Cheat sheet
ip command cheat sheet
The Linux ip command on one page: addresses, cards, routes, neighbours and routing rules.
ip addr
Shows each network card with its addresses and prefix, and adds or removes addresses.
ip -br addr- Lists every card on one line each, with its state and addresses.
ip addr show eth0- Shows eth0 in full: flags, MTU, MAC address, addresses with prefix and broadcast.
ip -6 addr show scope global- Shows only the global IPv6 addresses, the ones SLAAC or DHCPv6 gave.
ip addr add 10.0.1.50/24 dev eth0- Gives eth0 a second address, 10.0.1.50 in the 10.0.1.0/24 network.
ip addr del 10.0.1.50/24 dev eth0- Removes that address again.
ip link
Shows each network card's state, MAC address, MTU and counters, and switches it up or down.
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 route
Shows the routing table, asks which route a destination takes, and adds or removes routes.
ip route- Prints the routing table: one line per destination network and where it goes.
ip route get 10.0.2.10- Shows which next hop, card and source address a packet to 10.0.2.10 would use.
ip route show default- Shows only the default route, the gateway for everything not listed.
ip route add default via 10.0.1.2- Sends every packet with no better route to the router at 10.0.1.2.
ip route add 10.0.3.0/24 via 10.0.12.2- Sends packets for 10.0.3.0/24 to the next router, 10.0.12.2.
ip neigh
Shows the neighbour table, the IP-to-MAC answers this device learned with ARP or neighbour discovery.
ip neigh- Lists every neighbour this device knows, with its MAC address and state.
ip neigh show 10.0.1.2- Shows which MAC address this device uses for 10.0.1.2.
ip neigh flush all- Empties the neighbour table, so every address is asked for again.
ip neigh replace 10.0.1.2 lladdr 02:42:0a:00:01:02 dev eth0 nud permanent- Pins 10.0.1.2 to one MAC address, so forged ARP replies cannot move it.
ip -6 neigh- Lists IPv6 neighbours, learned with neighbour discovery instead of ARP.
ip rule
Shows and changes the policy rules that pick which routing table a packet is looked up in.
ip rule show- Lists every rule in the order they are checked, ending with
mainanddefault. ip rule add iif officeA table 10 pref 100- Routes everything arriving on officeA with table 10.
ip route show table 10- Lists the routes in table 10.
ip route get 192.168.50.10 from 10.0.1.10 iif officeA- Shows the decision for a packet arriving on officeA, including the table used.