Commands / Interfaces and addresses

Interfaces and addresses

ip link

Also interface, mtu, counters

Shows each network card's state, MAC address, MTU and counters, and switches it up or down.

ip link is about the card itself, below any address: up or down, its MAC address, its MTU, its VLAN id. ip -s link adds counters: packets and bytes received and sent, and errors and drops, which tell a broken or overloaded link from a quiet one. ip -d link shows details such as a VLAN card's id.

ip link command usage

ip [-br|-s|-d] link [show [dev CARD]]
ip link set dev CARD up|down|mtu N
ip link add NAME type vxlan id VNI local ADDRESS dstport 4789

Options

-br
brief: name, state, MAC address
-s
statistics: packets, bytes, errors, drops
-d
details: the card's type, VLAN id and more
set dev eth0 down
switch the card off (up to switch it on)
set dev eth0 mtu 1400
change its MTU

ip link examples

ip -br link
Lists every card with its state and MAC address.
ip -s link show eth0
Shows eth0's counters: packets, bytes, errors and drops each way.
ip -d link show eth0.10
Shows the details of a VLAN card, including its VLAN id.
ip link set dev eth0 up
Switches eth0 on.
ip link set dev eth0 mtu 1400
Lowers eth0's MTU to 1400 bytes.
ip link add vxlan100 type vxlan id 100 local 10.0.1.2 dstport 4789
Makes a VXLAN tunnel endpoint for VNI 100, sending from 10.0.1.2 to UDP port 4789.

Reading the output

$ ip -s link show eth0
11: eth0@if6378: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether fe:26:a1:c3:bb:c3 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    RX:   bytes packets errors dropped  missed   mcast
       25983450  393625      0       0       0       0
    TX:   bytes packets errors dropped carrier collsns
    39265647646  895800      0       0       0       0
  • state UP: the card works. DOWN or LOWERLAYERDOWN means nothing passes, whatever the addresses say.
  • RX: received, TX: sent. Run it twice: counters that grow tell you traffic really flows through this card.
  • dropped or errors that grow point at the link or the card, not at routing.

Pitfalls

  • A card that is DOWN keeps its addresses, so ip addr still shows them: check the state, not just the address.
  • Both ends of a link must agree on the MTU: a smaller one on one side makes big packets vanish while pings still work.

Run it on real machines

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Start with a free account: Google or email, no card.

Start this lab, free