ZetCode

Linux ip Command

last modified October 23, 2026

The ip command in Linux shows and configures network interfaces, addresses, routes, and neighbour tables. It is part of the iproute2 package and replaces the older ifconfig, route, and arp commands from net-tools, which are no longer installed by default on many distributions.

The syntax is ip [options] object command, where the object is, for example, link (network devices), addr (IP addresses), route (routing table), or neigh (ARP and NDP cache). Objects and commands can be abbreviated, so ip a means ip addr show. Viewing works for any user; changes require root privileges and are lost after a reboot. The examples run in a container whose eth0 interface is connected to a Docker bridge network.

Showing addresses

The ip addr command lists all interfaces with their addresses.

ip addr

Each interface has an index, a name, flags, and the MTU. The link/ether line shows the MAC address, inet lines show IPv4 addresses, and inet6 lines show IPv6 addresses, all in CIDR notation. The flag UP means the interface is enabled, and LOWER_UP means a physical link is detected. The lo interface is the loopback device.

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0@if57: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 52:32:43:a6:5b:4e brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever

Brief output and filters

The -br option prints one line per interface, and -4 or -6 limit the output to one address family.

ip -br addr
ip -br link
ip -4 addr show dev eth0

The brief format shows the name, the state, and the addresses or MAC address, which is often all we need. The dev keyword selects a single interface. The -c option adds colours to the output.

$ ip -br addr
lo               UNKNOWN        127.0.0.1/8 ::1/128 
eth0@if57        UP             172.17.0.2/16 
$ ip -br link
lo               UNKNOWN        00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP> 
eth0@if57        UP             52:32:43:a6:5b:4e <BROADCAST,MULTICAST,UP,LOWER_UP> 
$ ip -4 addr show dev eth0
2: eth0@if57: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default  link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever

Managing network devices

The ip link object manages network devices. We create a virtual dummy interface for experiments and bring it up.

sudo ip link add dummy0 type dummy
ip link show dummy0
sudo ip link set dummy0 up

A new interface starts in the DOWN state. The ip link set ... up and down commands enable and disable an interface, like ifconfig eth0 up did. The same command sets other properties, for example ip link set dummy0 mtu 9000.

$ sudo ip link add dummy0 type dummy
$ ip link show dummy0
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 26:cc:5d:c0:59:a3 brd ff:ff:ff:ff:ff:ff
$ sudo ip link set dummy0 up
$ ip -br link show dummy0
dummy0           UNKNOWN        26:cc:5d:c0:59:a3 <BROADCAST,NOARP,UP,LOWER_UP> 

Adding and removing addresses

The ip addr add and ip addr del commands manage IP addresses of an interface.

sudo ip addr add 192.168.50.10/24 dev dummy0
sudo ip addr add 192.168.50.11/24 dev dummy0
sudo ip addr del 192.168.50.11/24 dev dummy0

An interface can have several addresses. The prefix length matters: without /24, the address would be added as /32. The IPv6 link-local address starting with fe80:: was assigned automatically when the interface came up. The ip addr flush dev dummy0 command removes all addresses at once.

$ sudo ip addr add 192.168.50.10/24 dev dummy0
$ sudo ip addr add 192.168.50.11/24 dev dummy0
$ ip -br addr show dummy0
dummy0           UNKNOWN        192.168.50.10/24 192.168.50.11/24 fe80::24cc:5dff:fec0:59a3/64 
$ sudo ip addr del 192.168.50.11/24 dev dummy0
$ ip -br addr show dummy0
dummy0           UNKNOWN        192.168.50.10/24 fe80::24cc:5dff:fec0:59a3/64 

Routes

The ip route object shows and changes the routing table.

ip route
sudo ip route add 10.10.0.0/16 via 192.168.50.1
ip route get 10.10.5.5
ip route get 1.1.1.1
sudo ip route del 10.10.0.0/16

The default route sends traffic for unknown destinations to the gateway. Adding an address to dummy0 automatically created a route for its subnet. We add a static route through a gateway on that subnet. The ip route get command shows which route, interface, and source address the kernel would use for a destination, which is very helpful when troubleshooting. A default gateway is set with ip route add default via ADDRESS.

$ ip route
default via 172.17.0.1 dev eth0 
172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.2 
192.168.50.0/24 dev dummy0 proto kernel scope link src 192.168.50.10 
$ sudo ip route add 10.10.0.0/16 via 192.168.50.1
$ ip route
default via 172.17.0.1 dev eth0 
10.10.0.0/16 via 192.168.50.1 dev dummy0 
172.17.0.0/16 dev eth0 proto kernel scope link src 172.17.0.2 
192.168.50.0/24 dev dummy0 proto kernel scope link src 192.168.50.10 
$ ip route get 10.10.5.5
10.10.5.5 via 192.168.50.1 dev dummy0 src 192.168.50.10 uid 1000 
    cache 
$ ip route get 1.1.1.1
1.1.1.1 via 172.17.0.1 dev eth0 src 172.17.0.2 uid 1000 
    cache 
$ sudo ip route del 10.10.0.0/16

Neighbour table

The ip neigh object shows the ARP cache for IPv4 and the neighbour cache for IPv6, which map IP addresses to MAC addresses.

ping -c 1 -q 172.17.0.1 > /dev/null
ip neigh

After we contact the gateway, its MAC address appears in the table with the state REACHABLE. This replaces the arp -n command.

$ ping -c 1 -q 172.17.0.1 > /dev/null
$ ip neigh
172.17.0.1 dev eth0 lladdr 76:98:d2:37:73:6c REACHABLE 

Interface statistics

The -s option adds traffic statistics to the output.

ip -s link show lo

The counters show received (RX) and transmitted (TX) bytes and packets, along with errors and dropped packets. After a few pings to 127.0.0.1, the loopback device shows the traffic in both directions. Growing error counters often indicate a cabling or driver problem.

$ ip -s link show lo
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
    RX:  bytes packets errors dropped  missed   mcast           
           504       6      0       0       0       0 
    TX:  bytes packets errors dropped carrier collsns           
           504       6      0       0       0       0 

JSON output

The -j option produces JSON, which is easier to process in scripts than parsing text.

ip -j addr show dev dummy0 | jq '.[0] | {ifname, operstate, mtu}'
ip -j addr show dev dummy0 | jq -r '.[0].addr_info[] | "\(.family) \(.local)/\(.prefixlen)"'

We use jq to select a few fields of the interface and to print its addresses. The -p option pretty-prints the JSON without an external tool.

$ ip -j addr show dev dummy0 | jq '.[0] | {ifname, operstate, mtu}'
{
  "ifname": "dummy0",
  "operstate": "UNKNOWN",
  "mtu": 1500
}
$ ip -j addr show dev dummy0 | jq -r '.[0].addr_info[] | "\(.family) \(.local)/\(.prefixlen)"'
inet 192.168.50.10/24
inet6 fe80::24cc:5dff:fec0:59a3/64

Removing a device

The ip link delete command removes virtual devices.

sudo ip link set dummy0 down
sudo ip link delete dummy0

The dummy interface is gone, together with its addresses and routes.

$ sudo ip link set dummy0 down
$ sudo ip link delete dummy0
$ ip -br link
lo               UNKNOWN        00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP> 
eth0@if57        UP             52:32:43:a6:5b:4e <BROADCAST,MULTICAST,UP,LOWER_UP> 

ip versus net-tools

The following table maps common net-tools commands to their ip equivalents.

net-toolsiproute2
ifconfigip addr, ip -br addr
ifconfig eth0 upip link set eth0 up
ifconfig eth0 192.168.1.5/24ip addr add 192.168.1.5/24 dev eth0
route -nip route
route add default gw 192.168.1.1ip route add default via 192.168.1.1
arp -nip neigh
netstat -iip -s link
netstat -tlnss -tln

Socket statistics are handled by a separate iproute2 tool, the ss command. Permanent network configuration belongs to the distribution's network manager, such as NetworkManager, systemd-networkd, or netplan, not to ip.

Best practices for ip

Source

ip(8) manual page

In this article, we have used the ip command to inspect interfaces and addresses, manage devices, addresses, and routes, view the neighbour table and statistics, and produce JSON output.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all Linux tutorials.