Network interfaces in Linux: ip addr, ip link
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
- Modern interface names come from the hardware:
ens18,enp0s3,eno1;lois loopback (127.0.0.1). ip -br a— all interfaces, state and IPs at a glance (likeshow ip int briefon Cisco).ip link show— L2: state (UP/DOWN,LOWER_UP= cable), MAC, MTU.sudo ip link set ens18 down/up,sudo ip addr add 10.20.0.16/24 dev ens18— temporary changes, lost on reboot.ip -s linkshows packet and error counters,ethtool ens18speed and duplex.
Interface names
On older systems interfaces were called eth0, eth1, and could swap places after a reboot. Now names come from where the hardware sits, and they are stable:
| Name | Meaning |
|---|---|
lo | Loopback — the server itself (127.0.0.1) |
eno1 | A card built into the motherboard (onboard) |
ens18 | PCI Express slot 18 — common on virtual servers |
enp0s3 | PCI bus 0, slot 3 |
wlp2s0 | Wi-Fi |
docker0, br0, veth... | Virtual bridge and container interfaces |
en — Ethernet, wl — WLAN.
ip -br a: at a glance
The ip command replaces the old ifconfig (on Ubuntu ifconfig is not installed by default):
ali@srv-web01:~$ ip -br a lo UNKNOWN 127.0.0.1/8 ::1/128 ens18 UP 10.20.0.15/24 fe80::be24:11ff:fe4a:7c21/64
This is what show ip interface brief is on Cisco: name, state, addresses. Without -br (brief) you get the detailed output:
ali@srv-web01:~$ ip addr show ens18 2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether bc:24:11:4a:7c:21 brd ff:ff:ff:ff:ff:ff altname enp0s18 inet 10.20.0.15/24 brd 10.20.0.255 scope global ens18 valid_lft forever preferred_lft forever inet6 fe80::be24:11ff:fe4a:7c21/64 scope link valid_lft forever preferred_lft forever
| Part | Meaning |
|---|---|
UP | The interface is administratively enabled (no shutdown on Cisco) |
LOWER_UP | There is a physical link — the cable is in, the port is up |
mtu 1500 | Maximum frame size |
link/ether bc:24:11:... | MAC address |
inet 10.20.0.15/24 | IPv4 address and mask |
brd 10.20.0.255 | Broadcast address |
scope global | An address reachable from anywhere; scope link — local segment only |
inet6 fe80::... | IPv6 link-local address (created automatically) |
If there is UP but no LOWER_UP, and NO-CARRIER is shown, the interface is enabled but the cable or the port on the other side has a problem.
ip link: layer two
ali@srv-web01:~$ ip -br link lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP> ens18 UP bc:24:11:4a:7c:21 <BROADCAST,MULTICAST,UP,LOWER_UP>
Temporary changes
| Command | What it does |
|---|---|
sudo ip link set ens18 down | Disables the interface (Cisco shutdown) |
sudo ip link set ens18 up | Brings it up |
sudo ip addr add 10.20.0.16/24 dev ens18 | Adds a second IP |
sudo ip addr del 10.20.0.16/24 dev ens18 | Removes it |
sudo ip link set ens18 mtu 9000 | Changes the MTU (jumbo frames) |
Two warnings:
- Every change made with
ipis lost on reboot. Permanent settings are made with netplan or NetworkManager (lesson 7.4). - If you bring down the interface you are connected through over SSH, your connection drops and you will need the console to get back.
Counters and speed
ali@srv-web01:~$ ip -s link show ens18 2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether bc:24:11:4a:7c:21 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped missed mcast 48213906 301455 0 0 0 0 TX: bytes packets errors dropped carrier collsns 91302554 210038 0 0 0 0 ali@srv-web01:~$ sudo ethtool ens18 | grep -E "Speed|Duplex|Link detected" Speed: 1000Mb/s Duplex: Full Link detected: yes
If errors and dropped keep growing, a cable, a port or a duplex mismatch is likely (check the same counters on the switch). ethtool shows the physical parameters.
Neighbours: the ARP table
The equivalent of Cisco's show arp:
ali@srv-web01:~$ ip neigh 10.20.0.1 dev ens18 lladdr bc:24:11:00:00:01 REACHABLE 10.20.0.20 dev ens18 lladdr bc:24:11:5e:19:a3 STALE
REACHABLE — confirmed recently, STALE — aged, FAILED — no reply (that IP is not on the network or is blocked).
Look at the server's interfaces with ip -br a, ip link and ip neigh in the Linux simulator.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1Which Cisco command is ip -br a similar to?
2An interface shows UP but also NO-CARRIER. Where is the problem?
LOWER_UP means a physical-layer problem.3What happens after a reboot to an address added with sudo ip addr add 10.20.0.16/24 dev ens18?
ip command only changes the running system.4On which line of ip addr output is the MAC address?
5How do you look at the ARP table on Linux?
Comments
Sign in to comment.