25.3 ip link: Managing Network Interfaces
Alright, let’s get our hands dirty with ip link, the Swiss Army knife for your network interfaces. Forget ifconfig; it’s the old guard, retired and living on a farm upstate. The iproute2 suite, which ip link is part of, is the modern toolkit, and it’s how the kernel actually thinks about your network devices. We’re going to talk to the kernel directly, no old-timey translators.
First things first, let’s see what we’re working with. The most common command you’ll run is ip link show. It gives you the lay of the land.
$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether ab:cd:ef:12:34:56 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 12:34:56:ab:cd:ef brd ff:ff:ff:ff:ff:ff
Let’s decode this masterpiece of terseness. Each line starts with a number—that’s the interface index, the kernel’s favorite way to ID things. Then the name, like eth0 or wlan0. The stuff in the angle brackets <...> are the flags: UP means the interface is administratively enabled (we told it to be on), LOWER_UP means there’s actually a physical signal (a cable is plugged in and it’s happy). mtu is the Maximum Transmission Unit, which is just a fancy way of saying the biggest packet it’s willing to send without fragmenting it. The state is crucial: UP/DOWN tells you its administrative status, while UNKNOWN for lo is just it being weirdly philosophical about its own existence.
Bringing an Interface Up and Down
This is the most common operation after just looking. Notice in the output above that wlan0 is state DOWN. Maybe we just installed the drivers and need to activate it. To bring an interface up, you need root powers:
$ sudo ip link set wlan0 up
And just like that, it should show state UP. To take it down, say for troubleshooting or because you’re paranoid about network traffic:
$ sudo ip link set eth0 down
Massively Important Pitfall: If you do this on a remote machine over SSH, you will have a very bad, no-good day. You’re turning off the network interface you’re currently using. The next packet you try to send will be your session’s dying breath. Always have physical console access or another network path when messing with interfaces.
The Absolute Weirdness of Interface Naming
Let’s address the elephant in the room. You grew up with eth0, eth1. Simple, predictable, sane. Then systemd and udev happened and decided we needed clues in the names, so now you get enp0s3 or wlp2s0. en for Ethernet, wl for wireless, p0 for bus position 0, s3 for slot 3. It’s meant to be persistent, but it often feels like they solved a problem we didn’t really have and created a new one: everyone just misses the old names.
You can defeat this, of course. You can write udev rules to rename devices back to eth0. But honestly, after a while, you get used to the new scheme. It’s like a weird haircut; eventually, it just grows on you.
Changing the MAC Address (Spoofing)
Sometimes you need to change your MAC address. Maybe you’re on a network that filters by MAC and your new card is unknown, or maybe you’re doing something… questionable. Here’s how you do it. First, take the interface down. You can’t change the settings of a busy interface.
$ sudo ip link set dev wlan0 down
$ sudo ip link set dev wlan0 address 00:11:22:33:44:55
$ sudo ip link set dev wlan0 up
Why this works: The MAC address is a software property, not burned-in hardware (despite the name “hardware address”). The driver tells the kernel “here’s what I’d like my address to be,” and the kernel says “sure, whatever.” The original MAC is usually stored in the card’s firmware, and the driver reads it and uses it as the default, but we can almost always override it. Notable exception: some VMware virtual interfaces are notoriously stubborn about this.
Mastering the MTU
The MTU isn’t just a number you leave at 1500 forever. If you’re on a jumbo-frame network (like a proper SAN), you might need to crank it up. If you’re tunneling traffic over VPNs or other encapsulations, you might need to lower it to avoid fragmentation, which murders performance.
# Let's see what the current MTU is on eth0
$ ip link show dev eth0 | grep mtu
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
# Now let's change it to 9000 for some jumbo frame action
$ sudo ip link set dev eth0 mtu 9000
Best Practice: Don’t just guess the MTU. If you’re troubleshooting a connection, use ping -s 1472 -M do www.google.com (the -M do tells it to not fragment; it’ll fail if the packet is too big). Start low and work your way up to find the true MTU of your path.