OnCallReady

Lesson 1.13 · First Login · 14 min read

Network identity

In plain words

When you move into a new flat in a big building, you do not pick your own flat number. You ask the front desk, and they hand you a number for a while, tell you where the building's exit is, and who to ask for directions. The front desk is DHCP. Your VM asked UTM's front desk and got 10.64.0.2, with the Mac at 10.64.0.1 as the exit.

The network card's name, enp0s1, is like a label saying "Ethernet socket on wall 0, position 1": it names the socket's place, so it never changes if you add another one. And the building's own name, oncall-lab, is only written on the flat door. Nobody outside knows it unless someone publishes it.

One morning ssh [email protected] just hangs. Did the VM's address change? Is its network card down? Is it the Mac? You cannot fix what you cannot name. This lesson gives you the words - address, interface, gateway - and the three commands that show them.

What you need to know already: 1.1 Where you are (host, guest, SSH), 1.7 Driving the shell.

Addresses and networks

An IP address is a machine's number on a network, like a phone number. The common kind, IPv4, is four numbers from 0 to 255: 10.64.0.2. (There is also a longer kind, IPv6, written with colons: fe80::3ca1:.... You will see both; this lesson is about IPv4.)

A network (or subnet) is a group of addresses that can reach each other directly. It is written as an address plus a prefix length: 10.64.0.2/24. The /24 says "the first 24 bits - the first three numbers - name the network". So 10.64.0.0 to 10.64.0.255 are all on the same local network, and your VM is number 2 in it.

To reach anything outside its own network, a machine sends traffic to a gateway (a router: a machine that forwards traffic between networks). Which traffic goes where is the routing table; the catch-all entry is the default route.

Where 10.64.0.2 came from

You never typed it. DHCP (Dynamic Host Configuration Protocol) is how a machine asks the network for an address. UTM runs a small DHCP server on the private network it made for the VM. At boot the VM shouted "anyone got an address for me?", and UTM answered with:

Your Mac being 10.64.0.1 on that same network is why ssh [email protected] works from the Mac and from nowhere else.

Interfaces, and reading the name

A network interface is one network connection as the OS sees it - usually one NIC (network interface card, the hardware that plugs into a network). Yours is called enp0s1:

enp0s1
│ │ └┴─ s1 = slot 1 on that bus
│ └┴─── p0 = PCI bus 0
└┴───── en = Ethernet

Ethernet is the standard wired network type. PCI is the internal connector system that cards plug into: a numbered bus, with numbered slots on it. So the name means "the Ethernet card in slot 1 of bus 0".

This is predictable interface naming. The old scheme (eth0, eth1) numbered cards in the order the kernel found them, so adding a card could rename your existing one and break settings that referred to it. Now the name comes from the physical position, so it never moves. lspci (list PCI devices) shows that network device at 00:01.0 - bus 00, slot 01 - which is literally where the name comes from.

lo is the loopback interface, address 127.0.0.1: a pretend network that never leaves the machine, so programs on the box can talk to each other.

The commands

$ ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128
enp0s1           UP             10.64.0.2/24 fd9b:...:2b09/64 fe80::...:2b09/64

ip is the tool for everything network. a is short for address (show addresses), and -br means brief: one line per interface. The columns: the interface name, its state (UP = connected and working; lo always says UNKNOWN, which is normal), then its addresses - the IPv4 one with its /24, then IPv6 ones.

$ ip r
default via 10.64.0.1 dev enp0s1 proto dhcp src 10.64.0.2 metric 100
10.64.0.0/24 dev enp0s1 proto kernel scope link src 10.64.0.2 metric 100

ip r (route) prints the routing table. Line 1: "for everything not listed below (default), send it via the gateway 10.64.0.1, out of device enp0s1; this was learned from dhcp". Line 2: "the 10.64.0.0/24 network is right here on enp0s1 - no gateway needed".

ip a              full detail (hardware address, every setting)
hostname -I       just the addresses, nothing else - handy in scripts

ifconfig, which you may know from the Mac, is not installed on Ubuntu Server (it lives in the old net-tools package). ip replaced it; learn that one.

The "use DHCP on enp0s1" decision itself is a file the installer wrote: /etc/netplan/50-cloud-init.yaml. Only root may read it (mode 600), so sudo cat it. Chapter 8 (networking) edits it.

Why "ssh learner@oncall-lab" fails from the Mac

The VM knows its own name. Your Mac does not - nothing tells it. To use a name instead of an address, something has to translate the name: a DNS server, a line in the Mac's /etc/hosts file (a local list of name = address pairs), or mDNS (multicast DNS: machines on the same local network announce their own names - Apple calls it Bonjour, and it answers for names ending in .local). A stock Ubuntu Server does not run an mDNS announcer, so the name never leaves the VM. Either use the IP, install avahi-daemon (the Linux mDNS announcer) on the VM, or add the line to the Mac's /etc/hosts.

DHCP leases can change. If the address moves, find it again from the UTM window (the VM's own screen, which works without the network) with ip -br a. That is also why servers other machines must reach are not left on a changing address: they get a static (fixed, typed-in) address, or a DHCP reservation - the DHCP server always hands that one machine the same address.

In an interview ("how does a machine get its IP?"): DHCP - it asks, a server answers with address, network size, gateway, DNS and a lease; ip -br a and ip r show the result, and proto dhcp in the route says where it came from.

What you can now do

Why it helps

A large share of debugging ends up at the network. "Connection timed out", "Connection refused" and "Could not resolve host" are three different problems, and this lesson starts that split: address (DHCP), interface, route, and name. ip -br a and ip r are the first two commands on any machine that lost its connection.

Interface names show up in real settings files: network configs and firewall rules refer to enp0s1 by name, and a config copied from a machine with a different name leaves a box without network after reboot. And knowing that a name only works if something publishes it (DNS, mDNS, a hosts file) is the reasoning you will reuse every time "it works by IP but not by name".

Commands in this lesson

ip hostname

FAQ

Will the VM's IP address change?

It can. DHCP gives a lease, not ownership. UTM's DHCP server usually gives the same address back to the same VM, so in practice it is stable, but a new VM, a changed network mode or an expired lease can move it. If ssh suddenly times out, open the VM's window in UTM and run ip -br a. For something permanent you can set a fixed (static) address in the VM's network config.

Why is my interface enp0s1 and not eth0?

Predictable interface naming. The name is built from where the card sits: en for Ethernet, p0 PCI bus 0, s1 slot 1. The old eth0 names were handed out in the order the kernel found the cards, which could change when hardware was added, silently swapping names and breaking settings that referred to them. Other machines show other names, like ens5, depending on how their hardware reports its position.

What is the /24 after the address?

The prefix length: the first 24 bits of the address (the first three numbers) name the network, the last 8 bits (the last number) name the machine within it. 10.64.0.2/24 means every address from 10.64.0.0 to 10.64.0.255 is on the same local network and reachable directly, without a gateway. Anything else goes to the default gateway shown by ip r.

Is ifconfig still a thing?

It comes from the old net-tools package, which modern Ubuntu does not install and which has not kept up with newer network features in the kernel. ip replaces it: ip a for addresses, ip r for routes, ip link for the interfaces themselves. You will still see ifconfig in old guides and on the Mac, where it remains the normal tool.

Why can I ssh by IP but not by hostname from my Mac?

The name oncall-lab is only stored inside the VM. For your Mac to turn it into an address, something has to publish it: a DNS server, mDNS (which needs avahi-daemon running on the VM, answering to oncall-lab.local), or a line in the Mac's /etc/hosts file. Another option is a Host oncall-lab entry with HostName 10.64.0.2 in the Mac's ~/.ssh/config, which only ssh uses.

In an interview Junior

How does a Linux machine get its IP address, and how do you check it?

Usually by DHCP: at boot the machine asks the local network "anyone got an address for me?", and a DHCP server answers with an address and network size (10.64.0.2/24), a gateway (10.64.0.1), a DNS server, and a lease - how long the address is the machine's before it must ask again. On Ubuntu the "use DHCP on enp0s1" decision is a file in /etc/netplan/.

To check: ip -br a shows each interface, its state (UP) and its addresses; ip r shows the routing table, where default via 10.64.0.1 ... proto dhcp is the gateway and where it came from; hostname -I prints just the addresses. Gotcha: a lease can change, so a machine others must reach needs a fixed address or a reservation.

Also asked: What does the /24 in 10.64.0.2/24 mean? · What does an interface name like enp0s1 tell you? · Why can you reach the VM by its IP address but not by its hostname from the Mac?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.