Interfaces and addresses
ip addr
Shows each network card with its addresses and prefix, and adds or removes addresses.
The first thing to run on any device: which cards it has, whether they are up, and the address with its
prefix on each (10.0.1.10/24). The prefix decides which addresses count as "my own network": everything else
goes to a router. ip -br addr is the one-line-per-card view. It replaced ifconfig, which you still meet in
old guides.
ip addr command usage
ip [-br] [-4|-6] addr [show [dev CARD]] ip addr add|del ADDRESS/PREFIX dev CARD ip addr help
Options
-
-br - brief: one line per card, name, state, addresses
-
help - print every form the command takes, and stop
-
-4 / -6 - only IPv4 or only IPv6 addresses
-
show dev eth0 - only that card
-
add 10.0.1.50/24 dev eth0 - put one more address on the card, with its prefix
-
del 10.0.1.50/24 dev eth0 - take an address off the card, named with its prefix as the card lists it
-
scope global - skip link-local and loopback addresses
ip addr examples
-
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 -4 -br addr - Lists only the IPv4 addresses, one card per line.
-
ip -br -c addr - The same list in colour: states and address families stand out.
-
ip -br addr show up - Lists only the cards that are switched on.
-
ip addr show to 10.0.1.0/24 - Finds which card holds an address in 10.0.1.0/24.
-
ip -6 addr show dev eth0 scope link - Shows eth0's link-local IPv6 address, the fe80:: one every IPv6 card has.
-
ip addr add 2001:db8:1::10/64 dev eth0 - Gives eth0 a static IPv6 address.
-
ip addr flush dev eth0 - Removes every address from eth0 at once.
-
ip -o -4 addr show eth0 | awk '{print $4}' - Prints eth0's IPv4 address and prefix alone, for a script: -o puts each address on one line.
-
ifconfig eth0 - The old net-tools view of the same card, still found on older systems and in old guides.
Reading the output
$ ip addr show eth0
11: eth0@if6378: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether fe:26:a1:c3:bb:c3 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 10.0.1.10/24 brd 10.0.1.255 scope global eth0
valid_lft forever preferred_lft forever <…UP,LOWER_UP>:UPmeans switched on,LOWER_UPmeans a cable (or its virtual twin) is connected.UPwithoutLOWER_UPis a dead link.mtu 1500: the largest packet this card sends without fragmenting.link/ether fe:26:…: the card's MAC address.inet 10.0.1.10/24: the IPv4 address and prefix: this device treats10.0.1.0–10.0.1.255as its own network.brdis that network's broadcast address.@if6378: the card is one end of a virtual cable; the other end is interface 6378 on the host.
Pitfalls
- A wrong prefix is a classic fault:
/16where the network is/24makes the device ARP for addresses that are really behind a router. ip addr addwithout/PREFIXmeans/32: an address with no network, and no route for its neighbours.- Changes made with
iplast until the device restarts: they are not saved anywhere.