Linux Basics Lesson 33 of 38
Names and other machines
8 minutes
Learning goals
- Ask the DNS with dig and dig +short, and ask a particular server with dig @.
- Tell apart what dig shows and what the system resolves with getent hosts and /etc/hosts.
- Read ssh and scp lines and say what they do, before they run in the terminal from LPIC-1 on.
dig: ask the DNS
dig asks a DNS server which records are stored for a name. +short leaves only the answer:
dig +short api.example.com
Purpose: Asks a DNS server directly which address is behind a name.
Syntax: dig [+short] [@SERVER] NAME
Options:
Example:
dig +short api.example.com
203.0.113.10203.0.113.10, the address of this server. Without +short you see the whole conversation:
dig shop.example.net
; <<>> DiG 9.20.30-1~deb13u1-Debian <<>> shop.example.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30487
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;shop.example.net. IN A
;; ANSWER SECTION:
shop.example.net. 300 IN A 198.51.100.7
;; Query time: 12 msec
;; SERVER: 203.0.113.53#53(203.0.113.53) (UDP)
;; WHEN: Sat Oct 17 09:42:00 UTC 2026
;; MSG SIZE rcvd: 61
Three lines are worth reading. The ANSWER SECTION has the record: name, then 300, the seconds for which the answer may be cached, then A for an IPv4 address, then the address. SERVER names the DNS server that answered, the one from /etc/resolv.conf. Query time says how long it took.
With @ you ask a particular server. If two servers give different answers, a change has not reached all of them yet, or one of them is wrong:
dig +short @203.0.113.53 shop.example.net
198.51.100.7
/etc/hosts: names without DNS
dig asks only the DNS. Your programs ask differently: first the file /etc/hosts, then the DNS. getent hosts looks a name up the same way they do:
getent hosts web-02
198.51.100.20 web-02
dig +short web-02
web-02 is only in /etc/hosts, so getent finds it and dig finds nothing. The same goes the other way: an old line in /etc/hosts beats the DNS, and then dig says one thing while curl connects somewhere else. cat /etc/hosts would show the whole file on a real server. cat, grep and kill are not loaded on this page, and getent shows what matters.
ssh and scp: the other machines
ssh opens a shell on another machine, and scp copies files over the same kind of connection:
ssh lerner@web-02
Purpose: Opens a shell on another machine. scp copies files through the same kind of connection.
Syntax: ssh USER@HOST ['COMMAND'] | scp FILE USER@HOST:PATH
Options:
Reading example, in the terminal from LPIC-1 on. This path has no second machine yet, so ssh and scp only give a hint here, and the card shows no output.
Example:
ssh lerner@web-02
scp report.pdf lerner@web-02:/tmp/The first line logs you in to web-02 as lerner, and exit brings you back. The second copies report.pdf from here into /tmp on web-02. Swap source and target, and scp fetches: scp lerner@web-02:/tmp/report.pdf .. With ssh lerner@web-02 'uptime' only that one command runs over there, and you are back straight away. On real servers you log in with a key instead of a password: ssh-keygen makes one, ssh-copy-id puts it on the other machine.
This course has no second machine yet. In the terminal, ssh and scp give a hint, and they arrive in the LPIC-1 path. That is why this card shows the lines without any output.
Practice
Terminal task 1/3
Which address is behind api.example.com? Ask the DNS, and only the address, please.
Task 1/3: Which address is behind api.example.com? Ask the DNS, and only the address, please.
Which address is behind api.example.com? Ask the DNS, and only the address, please.
Task complete
Solution
dig +short api.example.com Why: 203.0.113.10, this server itself, the address on eth0. So the name points where it should, and the chat was wrong this time.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
Terminal task 2/3
Ask the DNS server 203.0.113.53 directly which address shop.example.net has.
Task 2/3: Ask the DNS server 203.0.113.53 directly which address shop.example.net has.
Ask the DNS server 203.0.113.53 directly which address shop.example.net has.
Task complete
Solution
dig @203.0.113.53 shop.example.net Why: 198.51.100.7, in the ANSWER SECTION, and the first line of the output repeats whom you asked. With @ you decide whom you ask. If another server answered differently, you would know that the DNS itself is the problem.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
Terminal task 3/3
web-02 is not in the DNS. Find its address the way the system and your programs look it up.
Task 3/3: web-02 is not in the DNS. Find its address the way the system and your programs look it up.
web-02 is not in the DNS. Find its address the way the system and your programs look it up.
Task complete
Solution
getent hosts web-02 Why: 198.51.100.20 from /etc/hosts. dig +short web-02 stays empty, because the DNS has never heard of the name.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
Fill the gap
dig only asks the . getent hosts reads /etc/hosts first.
dig only asks the …. getent hosts reads /etc/hosts first.
Check works once you have typed an answer.
Find the error
This line is supposed to copy report.pdf into /tmp on web-02. Tap the part that is wrong.
Parts of the command
Check works once you have tapped a part.
Next up: a case. The app answers on the server, but not from outside.
Quiz
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
Cards
-
Card 1 of 3
Tap the card or press Space to turn it over.
-
Card 2 of 3
Tap the card or press Space to turn it over.
-
Card 3 of 3
Tap the card or press Space to turn it over.
End of the lesson
Still open: 5 exercises, 3 quiz questions
What you can do now: dig +short api.example.com, ssh lerner@web-02
+0 XP in this lesson
- Lesson 1: open
- Lesson 2: open
- Lesson 3: open
- Lesson 4: open
- Lesson 5: open
- Lesson 6: open
- Lesson 7: open
- Lesson 8: open
- Lesson 9: open
- Lesson 10: open
- Lesson 11: open
- Lesson 12: open
- Lesson 13: open
- Lesson 14: open
- Lesson 15: open
- Lesson 16: open
- Lesson 17: open
- Lesson 18: open
- Lesson 19: open
- Lesson 20: open
- Lesson 21: open
- Lesson 22: open
- Lesson 23: open
- Lesson 24: open
- Lesson 25: open
- Lesson 26: open
- Lesson 27: open
- Lesson 28: open
- Lesson 29: open
- Lesson 30: open
- Lesson 31: open
- Lesson 32: open
- Lesson 33: done
- Lesson 34: open
- Lesson 35: open
- Lesson 36: open
- Lesson 37: open
- Lesson 38: open
Cheat sheet
-
dig +short <name>only the address from the DNS -
dig @<server> <name>ask one particular DNS server -
getent hosts <name>resolve like your programs, /etc/hosts first -
ssh <user>@<host>shell on another machine (in the terminal from LPIC-1 on) -
scp <file> <user>@<host>:<path>copy a file to another machine (from LPIC-1 on)
The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.
- Download PDF (PDF, 19 KB)
- View as image (PNG, 66 KB)