CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Networking / nslookup

nslookup

Look up DNS names quickly

Beginnerdnsnetworktroubleshooting

nslookup resolves a name to its addresses (or an IP to its name) and shows which DNS server answered. It's simpler than dig, exists on Linux, macOS and Windows, and is often the only DNS tool inside a minimal container image.

Syntaxnslookup [-type=TYPE] NAME [SERVER]

Watch it run

You want the IPs of a host and, from an IP in a log, the host name, with the least typing.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
nslookup example.com

The first block says which DNS server answered (the local systemd-resolved stub). Below are the IPv4 and IPv6 addresses. 'Non-authoritative' just means it came from a cache.

Anatomy of a command

$
commandnslookup

Name server lookup. Without a name it starts an interactive prompt (>).

How it works

The Linux nslookup comes from BIND (the same package as dig) and, like dig, builds DNS queries itself rather than going through getaddrinfo, so /etc/hosts is not consulted. It reads /etc/resolv.conf for the default server and the search list, and applies the search domains to short names: with options ndots:5, as in Kubernetes pods, a name with fewer than five dots is first tried with each search suffix appended (orders becomes orders.shop.svc.cluster.local). For a plain lookup it sends an A and an AAAA query over UDP port 53 and prints the server it used, then the answers. 'Non-authoritative answer' simply means the reply came from a resolver's cache rather than from the zone's own name server. An IP address as argument becomes a PTR query for the in-addr.arpa name. Busybox images ship a smaller nslookup with slightly different output.

Options you'll actually use

-type=TRecord type: a, aaaa, mx, ns, txt, soa, cname, ptr, srv, any
NAME SERVERSecond argument: ask that DNS server instead of the default
-debugPrint every question, answer, TTL and section
-timeout=NSeconds to wait for a reply
-retry=NNumber of retries before giving up
-port=NQuery a DNS server on a non-standard port
(interactive) server XSwitch the server used for the following queries
(interactive) set type=XChange the record type for the following queries

Common mistakes

Using nslookup to check an entry you added to /etc/hosts

nslookup queries DNS servers directly and ignores /etc/hosts, so it disagrees with what applications see.

getent hosts myhost
Reading 'Non-authoritative answer' as an error

It only means the answer came from a resolver's cache instead of the zone's own server. That's the normal case.

Look for NXDOMAIN, SERVFAIL or timeouts instead.
Calling a service in another namespace by its short name from a pod

The search list starts with the pod's own namespace, so 'payments' becomes payments.shop.svc.cluster.local and fails.

Use payments.billing (or the full payments.billing.svc.cluster.local).

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Run nslookup on example.com in this offline sandbox and read the error. Is it NXDOMAIN or something else?

  2. 2

    Show the DNS servers and search domains this machine is configured with.

  3. 3

    Write the nslookup command that asks 10.0.0.2 for the NS records of devops-lab.io.

Related commands

digQuery DNS and read the full answerpingCheck if a host answers and how fastkubectl execRun a command or shell inside a running containercurlMake HTTP requests and debug APIs
PreviousdigNextcurl
Linux / Networking / nslookup

nslookup

Look up DNS names quickly

Beginnerdnsnetworktroubleshooting

nslookup resolves a name to its addresses (or an IP to its name) and shows which DNS server answered. It's simpler than dig, exists on Linux, macOS and Windows, and is often the only DNS tool inside a minimal container image.

Syntaxnslookup [-type=TYPE] NAME [SERVER]

Watch it run

You want the IPs of a host and, from an IP in a log, the host name, with the least typing.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
nslookup example.com

The first block says which DNS server answered (the local systemd-resolved stub). Below are the IPv4 and IPv6 addresses. 'Non-authoritative' just means it came from a cache.

Anatomy of a command

$
commandnslookup

Name server lookup. Without a name it starts an interactive prompt (>).

How it works

The Linux nslookup comes from BIND (the same package as dig) and, like dig, builds DNS queries itself rather than going through getaddrinfo, so /etc/hosts is not consulted. It reads /etc/resolv.conf for the default server and the search list, and applies the search domains to short names: with options ndots:5, as in Kubernetes pods, a name with fewer than five dots is first tried with each search suffix appended (orders becomes orders.shop.svc.cluster.local). For a plain lookup it sends an A and an AAAA query over UDP port 53 and prints the server it used, then the answers. 'Non-authoritative answer' simply means the reply came from a resolver's cache rather than from the zone's own name server. An IP address as argument becomes a PTR query for the in-addr.arpa name. Busybox images ship a smaller nslookup with slightly different output.

Options you'll actually use

-type=TRecord type: a, aaaa, mx, ns, txt, soa, cname, ptr, srv, any
NAME SERVERSecond argument: ask that DNS server instead of the default
-debugPrint every question, answer, TTL and section
-timeout=NSeconds to wait for a reply
-retry=NNumber of retries before giving up
-port=NQuery a DNS server on a non-standard port
(interactive) server XSwitch the server used for the following queries
(interactive) set type=XChange the record type for the following queries

Common mistakes

Using nslookup to check an entry you added to /etc/hosts

nslookup queries DNS servers directly and ignores /etc/hosts, so it disagrees with what applications see.

getent hosts myhost
Reading 'Non-authoritative answer' as an error

It only means the answer came from a resolver's cache instead of the zone's own server. That's the normal case.

Look for NXDOMAIN, SERVFAIL or timeouts instead.
Calling a service in another namespace by its short name from a pod

The search list starts with the pod's own namespace, so 'payments' becomes payments.shop.svc.cluster.local and fails.

Use payments.billing (or the full payments.billing.svc.cluster.local).

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Run nslookup on example.com in this offline sandbox and read the error. Is it NXDOMAIN or something else?

  2. 2

    Show the DNS servers and search domains this machine is configured with.

  3. 3

    Write the nslookup command that asks 10.0.0.2 for the NS records of devops-lab.io.

Related commands

digQuery DNS and read the full answerpingCheck if a host answers and how fastkubectl execRun a command or shell inside a running containercurlMake HTTP requests and debug APIs
PreviousdigNextcurl