Interfaces are names for a path
An interface is a kernel object that sends and receives packets. Physical network cards, Wi-Fi adapters, virtual Ethernet pairs for containers, and the loopback device all appear as interfaces. Each one has a name, such as eth0 or wlan0, and a state. A packet that leaves the machine goes out through one interface, chosen by the routing table, which the next unit covers.
The loopback interface is special. It carries traffic from the machine to itself, so a program that connects to 127.0.0.1 never touches a cable. Because it always exists on Linux, it is the safest place to practice. The lab machine for this course has only loopback, which is enough to learn most of the tools in this module.
Reading addresses with ip
The compact view of every interface is ip -br addr. The brief flag prints one line per interface with its name, its state, and its addresses. The state UNKNOWN for loopback is normal, because loopback has no link light to report.
ip -br addrIn the lab, the output has one line for lo, with the state UNKNOWN and the address 127.0.0.1/8. The number after the slash is the prefix length. A /8 means the first eight bits identify the network, so the whole 127.x.x.x range belongs to the loopback network.
Understanding prefix length
An address with a prefix length, such as 192.168.1.20/24, names two things at once: the host address and the network it lives in. A /24 means the first 24 bits are the network and the last 8 bits identify the host, so 256 addresses share that network. The shorter the prefix, the larger the network. Two machines on the same network can reach each other directly. Machines on different networks need a router.
| Prefix | Addresses in the block | Typical use |
|---|---|---|
| /8 | 16,777,216 | The whole loopback range 127.0.0.0/8 |
| /24 | 256 | A small home or office network |
| /32 | 1 | A single host route |
Showing one interface in detail
To see the full details of one interface, name it. The output includes the link layer address, the MTU, which is the largest packet the interface sends without splitting, and flags such as LOOPBACK and UP.
ip addr show loThe flags field lists what the interface is doing. The mtu value on loopback is large, because nothing is transmitted over a wire. Use the same command with a real interface name on a normal machine to read its MTU and its addresses in one place.
Interfaces are up or down
An interface can be administratively down, which means it will not send or receive, or up. The ip tool changes that state with ip link set, which requires root privileges on most systems. Unprivileged users can read the state, which is what this unit asks you to do. A down interface still has its addresses, which can confuse people who expect an address to mean the interface works.
The older ifconfig command is not installed in this lab image, and it is absent from many modern systems. The ip command does everything it did and more, so learn ip.
Hands-on: read the loopback
Run the two commands below. The first shows every interface in brief form, and the second shows the detail of loopback with its prefix. Compare the address in both outputs.
ip -br addr
ip -4 addr show loThe lines show 127.0.0.1/8 in both places. The lab asks you to save the brief output for lo to a file, which practices reading one field from the command.