devutils/ATFQ/book ATFQ git

Part II · Your system

19.3 Interfaces and routes

alsorouteroutesroutinggatewaydefault gatewayip routeip addrinterfacerouting table

TL;DR

  • An interface is a network connection point: enp3s0 (cable), wlp2s0 (Wi-Fi), lo (the machine itself).
  • The routing table says where each packet goes: straight to a local network, or to the default gateway (your router) for everything else.
  • ip shows and changes both; what you change with it is lost at reboot.
ip -br addr
ip route
ip route get 1.1.1.1     # which way a packet would take

On your machine

alice@laptopexample
$ atfq 19.3
  docker0   down · virtual · MAC 02:42:5c:11:aa:01
            172.17.0.1/16
  enp0s31f6 down · MAC 54:e1:ad:12:34:56
  lo        unknown · loopback
            127.0.0.1/8, ::1/128
  wlp0s20f3 up · wireless · MAC 8c:c6:81:2a:10:7f
            192.168.1.23/24, fe80::8ec6:81ff:fe2a:107f/64
  Route     default via 192.168.1.1 on wlp0s20f3

An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.

Pitfalls

Deep dive 2 questions

How is a route chosen?

The most specific route that matches wins: a route for 192.168.1.0/24 beats the default 0.0.0.0/0. Between equally specific routes, the lowest metric wins. ip route get ADDRESS shows the result for one destination, interface and source address included.

What's in an interface name?

The prefix says the kind: en for Ethernet, wl for Wi-Fi. The rest says where the card sits: p3s0 is PCI bus 3, slot 0; o1 is the first onboard port. udev builds these names so that adding a card doesn't rename the others, which happened with eth0 and eth1.

Commands
ip nmcli
Paths
/sys/class/net/ /proc/net/route
See also
19. Network
19.2 DNS resolution
19.4 nftables vs iptables vs ufw