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.
ipshows 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
$ 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
- NetworkManager or systemd-networkd manage the network on most systems:
change settings with
nmclior their files, or they undo youripcommands. - Names like
enp3s0come from the card's position in the machine; older guides sayeth0. - With two default routes (Wi-Fi and cable, or a VPN), the lowest metric wins.
- Docker, VPNs and VMs add their own interfaces and routes (
docker0,tun0,virbr0): that's normal.
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.