online posts 16
linux and the command line 101

task 8.1 · chapter 8 of 8: the network from the command line · 20 min

Where does it go?

objective

Log in to ws1 and work out how it reaches srv1: its addresses and management interface, its gateway, the DNS server it asks and what it answers, the route for one address with ip route get, and the hops with traceroute.

you edit, in the labanswers/8.1.yml

open a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter

given
LessonThe network from the command line
Log inssh ws1 (from task 6.2). After a make reset, ssh-copy-id ws1 again
Your answersanswers/8.1.yml, in the codespace (exit to get back)
new to this? step by stepbeginner
  1. ssh ws1, then ip -br addr and ip route: the management interface and the gateway.
  2. cat /etc/resolv.conf and dig srv1.lab (and dig +short srv1.lab).
  3. Challenge: ip route get 192.168.20.10 and traceroute -n srv1.
  4. exit, fill in answers/8.1.yml, then make check T=8.1.

more in meet the lab

1 explain

From the Networking 101 lab, one level down

What you already know

The Networking 101 lab had you read ip addr, ip route, ping, traceroute and dig on its hosts. Here the same commands come with the options engineers type day to day, on a machine with two networks, which is the usual case for servers.

CommandAnswers
ip -br addrevery interface and its address, one line each (-br is brief)
ip routethe routing table: where each network goes, and the default
ip route get ADDRESSwhich route this one address would use: the gateway, the interface, and the source address
dig NAMEthe full DNS answer: the question, the answer, the TTL, which server replied
dig +short NAMEjust the address
traceroute -n HOSTeach router on the way, as numbers (-n: don’t look up names, it’s faster)

Two networks, one default

ws1 has two interfaces. eth0 is on the lab’s management network, the one your codespace uses to reach it; it has a route for that one network only. eth1 goes to r1, and the default route, for everything else, points at r1. ip route get shows that choice being made for one address, which is the quickest way to answer why is this traffic going that way?

in one sentence ip route get answers “which way does this one address go?”; dig answers “what does DNS say?”.

2 show

ws1’s view

netops@ws1:~$ ip -br addr
lo               UNKNOWN        127.0.0.1/8
tunl0@NONE       DOWN
...
eth0@if23        UP             172.80.102.11/24
eth1@if28        UP             192.168.10.10/24
netops@ws1:~$ ip route
default via 192.168.10.1 dev eth1
172.80.102.0/24 dev eth0 proto kernel scope link src 172.80.102.11
192.168.10.0/24 dev eth1 proto kernel scope link src 192.168.10.10

The tunl0, gre0 and other DOWN entries are spare tunnel interfaces that come from the computer the lab runs inside. They have no address and nothing uses them. The numbers after @if will differ in yours.

3 follow along

Addresses, routes, names

  1. Log in, and list the interfaces and the routes:

    run in the terminal
    ssh ws1
    ip -br addr
    ip route
    

    The interface on 172.80.102.0/24 goes in mgmt_interface, and the address after default via in gateway.

  2. Which DNS server does ws1 ask?

    run in the terminal
    cat /etc/resolv.conf
    

    The nameserver line is dns_server. search lab means a short name like srv1 is tried as srv1.lab.

  3. Ask it, the long way and the short way:

    run in the terminal
    dig srv1.lab
    dig +short srv1.lab
    

    In the full answer, find the ANSWER SECTION, and at the bottom the SERVER line: who replied. The address goes in srv1_address.

  4. exit, and fill in the four follow-along lines in answers/8.1.yml.

in one sentence resolv.conf names the DNS server; dig shows its whole answer, and +short just the address.

4 challenge

The path to srv1

From ws1:

  1. Which interface does ws1 send srv1’s packets out of, 192.168.20.10? Ask for that one address, not the whole table. Write it in route_dev.
  2. How many hops does traceroute -n count from ws1 to srv1? Write it in hops_to_srv1.

Then exit and make check T=8.1.

hint

ip route get 192.168.20.10. The word after dev is the interface.

hint

Each numbered line of traceroute’s output is one hop, and the last is srv1 itself. If you see * * *, wait a few seconds and run it again: Linux limits how fast it sends the ICMP replies traceroute depends on.

show the solution
netops@ws1:~$ ip route get 192.168.20.10
192.168.20.10 via 192.168.10.1 dev eth1 src 192.168.10.10 uid 1000
    cache
netops@ws1:~$ traceroute -n srv1
traceroute to srv1 (192.168.20.10), 30 hops max, 60 byte packets
 1  192.168.10.1  0.055 ms  9.405 ms  0.034 ms
 2  192.168.20.10  0.126 ms  3.454 ms  0.149 ms
hops_to_srv1: 2
route_dev: eth1

No route says 192.168.20.0/24, so ws1 uses its default: via r1 (192.168.10.1), out of eth1, from its own 192.168.10.10. Two hops: r1, then srv1.

5 check: run it, then prove it

$ make check T=8.1

when it's right, you'll see

╭─ task 8.1 · where does it go?
│  ✓ ws1's default gateway (follow along): 192.168.10.1
│  ✓ the interface on the management network (follow along): eth0
│  ✓ srv1's address, from dig (follow along): 192.168.20.10
│  ✓ ws1's DNS server (follow along): 192.168.20.10
│  ✓ how many hops traceroute counts to srv1 (challenge): ...
│  ✓ the interface ws1 sends srv1's packets out of (challenge): ...
╰─ 6/6 checks passed  verified