terminal.cab

Linux Basics Lesson 33 of 38

guestLevel 1Badges and progress0/100 XP, XP to the next levelStreak0

Names and other machines

8 minutes

Learning goals

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:

  • +short only the answer, no sections
  • @SERVER ask this DNS server instead of the one in /etc/resolv.conf

Example:

dig +short api.example.com
203.0.113.10

in the glossary: dig

203.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:

  • 'COMMAND' runs only this command on the other machine and comes back
  • USER@HOST:PATH with scp, a path on the other machine, as the source or the target

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/

in the glossary: ssh

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.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

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.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

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.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

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

  1. Question 1 of 3dig +short web-02 prints nothing, but getent hosts web-02 prints 198.51.100.20. Why?

    Check works once you have chosen an answer.

  2. Question 2 of 3Which line copies report.pdf from this machine into /tmp on web-02?

    Check works once you have chosen an answer.

  3. Question 3 of 3In the answer line shop.example.net. 300 IN A 198.51.100.7, what is the 300?

    Check works once you have chosen an answer.

Cards

  1. Card 1 of 3

    Tap the card or press Space to turn it over.

  2. Card 2 of 3

    Tap the card or press Space to turn it over.

  3. 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

Next: lesson 34, Nothing gets through from outside (10 min)

What you can do now: dig +short api.example.com, ssh lerner@web-02

+0 XP in this lesson

  1. Lesson 1: open
  2. Lesson 2: open
  3. Lesson 3: open
  4. Lesson 4: open
  5. Lesson 5: open
  6. Lesson 6: open
  7. Lesson 7: open
  8. Lesson 8: open
  9. Lesson 9: open
  10. Lesson 10: open
  11. Lesson 11: open
  12. Lesson 12: open
  13. Lesson 13: open
  14. Lesson 14: open
  15. Lesson 15: open
  16. Lesson 16: open
  17. Lesson 17: open
  18. Lesson 18: open
  19. Lesson 19: open
  20. Lesson 20: open
  21. Lesson 21: open
  22. Lesson 22: open
  23. Lesson 23: open
  24. Lesson 24: open
  25. Lesson 25: open
  26. Lesson 26: open
  27. Lesson 27: open
  28. Lesson 28: open
  29. Lesson 29: open
  30. Lesson 30: open
  31. Lesson 31: open
  32. Lesson 32: open
  33. Lesson 33: done
  34. Lesson 34: open
  35. Lesson 35: open
  36. Lesson 36: open
  37. Lesson 37: open
  38. Lesson 38: open
1 of 38

Next: lesson 34, Nothing gets through from outside (10 min) That's enough for today

Path complete

You finished all 38 lessons of Linux Basics.

Back to the path

Cheat sheet

The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.