Based on the Linux Master 2 exam syllabusReport an error
.) → top-level (TLD) → second-level → host.nslookup · dig · host, and the Linux DNS server program is BIND. What happens when you type www.example.com?
1 Check /etc/hosts first (if it is there, you are done here)
2 Ask the DNS server in /etc/resolv.conf
3 The DNS server tells you 93.184.216.34
4 Connect to that IP/etc/hosts is a relic of that old approach. . (root)
┌──────────┼──────────┐
com kr org ← Top-level domains (TLD)
│ │
example co.kr ← Second-level domains
│ │
www naver ← Hostswww.example.com., is called an FQDN (Fully Qualified Domain Name).com is above example.| Category | Examples |
|---|---|
| gTLD (generic top-level) | com, net, org, edu, gov, mil, int |
| ccTLD (country code) | kr, jp, cn, us |
| gTLD | Purpose | Corresponding kr second level |
|---|---|---|
| com | For-profit companies | co.kr |
| org | Non-profit organizations | or.kr |
| edu | Educational institutions | ac.kr (universities) |
| gov | Government agencies | go.kr |
| net | Network-related organizations | ne.kr |
| mil | Military organizations | — |
| int | International organizations | — |
kr, the labels are abbreviated to two letters. They are co (company), or (organization), go (government), and ac (academic). The trap is that the counterpart of edu is ac.kr, not ed.kr.kr, jp, or us, it is a country code.WWW.Example.COM and www.example.com are the same.| Type | What it does |
|---|---|
| Root DNS server | The top of the hierarchy. Tells you where the TLD servers are |
| Authoritative server | The server that actually holds the information for that domain |
| Caching (Resolver) server | A server that asks on the user's behalf and stores the result |
| Master / Slave | The server holding the original / the secondary server that receives a copy |
/etc/resolv.conf is usually the address of a caching server (for example, 8.8.8.8).This is what a caching server does when www.example.com is asked for the first time.
My computer ──①──► Caching server (8.8.8.8 as listed in /etc/resolv.conf)
│
├──②──► Root server "com is known by that TLD server over there"
├──③──► com TLD server "example.com is known by that name server over there"
└──④──► Authoritative server for example.com "It is 93.184.216.34"
│
My computer ◄──⑤── Caching server (passes on the answer and remembers it for a while)| Category | Who asks whom | Nature |
|---|---|---|
| Recursive query (①) | My computer → caching server | "Bring me the final answer" — ask once and wait |
| Iterative query (②~④) | Caching server → root·TLD·authoritative servers | Asks one after another, receiving "whom to ask next" each time |
com → example.com.| Category | Direction | Record |
|---|---|---|
| Forward lookup | Name → IP | A, AAAA |
| Reverse lookup | IP → name | PTR |
| Record | Meaning |
|---|---|
| A | Name → IPv4 address |
| AAAA | Name → IPv6 address |
| MX | The domain's mail server (Mail eXchanger) |
| CNAME | An alias (another name for a name) |
| NS | The name server that manages the domain |
| PTR | IP → name (reverse) |
| SOA | The zone's basic information (administrator, refresh interval) |
A is address, MX is mail, CNAME is alias, NS is name server, PTR is reverse — be sure to tell these five apart. Questions about MX (mail) in particular come up.
| What you want to do | Record to use |
|---|---|
Connect www.example.com to 93.184.216.34 | A |
Make ftp.example.com another name for www.example.com | CNAME |
Specify the server that receives mail sent to alice@example.com | MX |
Specify the name server that manages example.com | NS |
Look up in reverse what name 93.184.216.34 has | PTR |
nslookup naver.com # Simple lookup
host naver.com # One-line summary
dig naver.com # Detailed lookup
dig naver.com MX # Mail servers only
dig -x 8.8.8.8 # Reverse lookup| Command | Characteristics |
|---|---|
nslookup | A traditionally widely used tool |
dig | The most detailed. Easy to specify the record type |
host | Output is concise |
$ nslookup www.example.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: www.example.com
Address: 93.184.216.34| Line | How to read it |
|---|---|
Server / Address | Whom you asked. The nameserver from /etc/resolv.conf appears here. #53 is the port number |
Non-authoritative answer | Not an answer given directly by the authoritative server, but one a caching server relayed from what it remembered |
Name / Address | The name asked about and its IP — this is the result |
Address with the lower Address. The upper is the DNS server's address, and the lower is the answer you were looking for.$ dig www.example.com
;; QUESTION SECTION:
;www.example.com. IN A
;; ANSWER SECTION:
www.example.com. 3600 IN A 93.184.216.34
;; SERVER: 8.8.8.8#53(8.8.8.8)ANSWER SECTION is in the order name · TTL (seconds) · IN · record type · value. The example above means "this answer may be remembered for 3600 seconds (1 hour)."dig displays names with a trailing dot (www.example.com.). This is the FQDN notation we saw earlier.| What you want to do | nslookup | dig | host |
|---|---|---|---|
| View mail servers (MX) | nslookup -type=mx example.com | dig example.com MX | host -t mx example.com |
| Specify the server to ask | nslookup name 168.126.63.1 | dig @168.126.63.1 name | host name 168.126.63.1 |
| Reverse lookup | nslookup 8.8.8.8 | dig -x 8.8.8.8 | host 8.8.8.8 |
dig puts @ before the server and needs -x for reverse lookups. With nslookup and host, if you just give an IP they automatically do a reverse lookup.ping also shows a name converted to an IP, but it is not classified as a DNS lookup tool.| Item | Description |
|---|---|
/etc/resolv.conf | Where you write the DNS servers to ask (nameserver) |
/etc/hosts | Maps names directly to IPs |
/etc/nsswitch.conf | The order of which to consult first (hosts: files dns) |
| BIND | The leading DNS server program on Linux. The daemon is named named |
| Port | 53 (mainly UDP, and TCP when the response is large) |
hosts comes before dns, /etc/hosts is consulted first. That is why values written there take priority over DNS.named, and the configuration file is /etc/named.conf (Red Hat family). Like Apache and httpd, the product and process names differ.| File | Which machine's it is | What is written |
|---|---|---|
/etc/resolv.conf | The asking side (client) | The IP of the DNS server to ask |
/etc/hosts | The asking side (client) | Name ↔ IP pairs to use without asking DNS |
/etc/named.conf | The answering side (DNS server) | Configuration of BIND itself |
resolv.conf, write an IP, not a name. If you wrote the DNS server by name, DNS would be needed again to resolve that name./etc/resolv.conf is filled in by the system, not by a person. If something you edited by hand has reverted after a reboot, this is the case.| Symptom | Cause | Check |
|---|---|---|
| It works by IP but no name resolves | resolv.conf is empty or the DNS server is unreachable | cat /etc/resolv.conf, ping 8.8.8.8 |
| Only one name goes to the wrong server | An old address is written in /etc/hosts | grep name /etc/hosts |
The nslookup result differs from the address actually connected to | nslookup asks only DNS and does not look at /etc/hosts | /etc/hosts |
| You changed a record but the old address keeps appearing | The caching server remembers the old answer for the TTL | It clears up as time passes |
Tomorrow we cover remote access and file transfer — TELNET, SSH, and FTP.
Click a choice to reveal the answer and explanation.
Question 1
What is the role of DNS?
Question 2
Which DNS record specifies the server that receives mail for a given domain?
Question 3
Which DNS record connects a domain name to an IPv4 address?
Question 4
What is the default port number used by DNS?
Question 5
Which record is used for a reverse lookup that finds a domain name from an IP address?