Track 4 · Lesson 2 of 5
DNS and addresses
How your phone turns a name like example.com into a reachable address, and how to inspect each step with dig.
Every time you open a site, your phone has to turn a name into an address. That translation is DNS. In this lesson you will find the resolver your phone uses. You will ask it for several kinds of record, and read the replies yourself. By the end you will know what happens between typing a name and reaching a server.
What you'll be able to do
- Find the DNS resolver your phone is using.
- Ask for A, AAAA, MX and TXT records with dig and nslookup.
- Read the answer section of a dig reply.
- Tell the difference between a name and an address.
- Follow a CNAME and run a reverse lookup.
Step 1: Find your resolver
A resolver is the server your phone asks to turn a name into an address. On Android it is stored as a system property. The getprop command reads those properties, and it is available in Termux.
Read the first resolver address:
getprop net.dns1
192.168.1.1
That address is your router, which forwards the question on. Some phones leave this property empty and fill in the second one instead. To see every DNS property at once, filter the full list:
getprop | grep -i dns
[net.dns1]: [192.168.1.1]
[net.dns2]: [8.8.8.8]
The first entry is your local resolver, and the second is a fallback.
The address you see here decides who answers your questions. Changing it later is a real change to how your phone works.
Step 2: Ask for an address
dig is the standard tool for asking DNS questions. It ships in the dnsutils package, which you may need to install first.
pkg install dnsutils
Reading package lists... Done
Setting up dnsutils (9.18.28) ...
Now ask for the address of example.com. The A record type holds an IPv4 address:
dig example.com A
; <<>> DiG 9.18.28 <<>> example.com A
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41022
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 3600 IN A 93.184.216.34
;; SERVER: 192.168.1.1#53(192.168.1.1)
The QUESTION SECTION repeats what you asked. The ANSWER SECTION holds the reply: the name, the number 3600, the record type, and the address. The 3600 is the time to live in seconds. It is the length of time a resolver may keep this answer before asking again.
For the IPv6 address, ask for the AAAA record:
dig +short example.com AAAA
2606:2800:220:1:248:1893:25c8:1946
The +short option prints only the answer. That is useful when you want the value, not the full report.
Step 3: Names, addresses and CNAMEs
A name and an address are two different things. example.com is a name, and 93.184.216.34 is the address that name points to right now. The name stays the same even when the address changes. That is the whole point of DNS.
A CNAME record makes one name an alias of another. Many zones point the www name at the plain name so both reach the same place. Ask for the alias directly:
dig +short www.example.com
example.com.
93.184.216.34
The first line is the CNAME, and the second is the address the alias resolves to. nslookup shows the same thing in a shorter form, naming the canonical name in a single line.
When a service moves, the operator changes the address and leaves the name alone. You keep sharing the name, and you never hard-code an address.
Quick reference
| Command | What it does |
|---|---|
getprop net.dns1 | Prints the DNS resolver your phone uses |
dig NAME A | Asks for the IPv4 address of a name |
dig NAME AAAA | Asks for the IPv6 address |
dig NAME MX | Asks for the mail servers of a domain |
dig NAME TXT | Asks for the text records |
dig -x ADDRESS | Asks for the name behind an address |
Next steps
- HTTP and APIs from the shell shows what you send once a name resolves.
- Moving files between machines covers copying data to a host by name.
- Network Recon puts these lookups to work.
Test yourself on this
4 questions and 1 task where you run a real command, with the reasoning explained either way.