Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

ip: manage the Linux network from the command line

By updated

Improve this page

A server stops answering, an address is missing or a route points to the wrong place: the ip command (package iproute2) shows the network state of the kernel and changes it. It replaces ifconfig, route and arp, which come from the net-tools package, absent by default on recent installations.

This page teaches ip on its own: reading addresses and routes, adding them, bringing an interface down, understanding the error messages. The full diagnosis method (ping, ports, DNS) is in Diagnose a network problem on Linux, and the configuration that survives a reboot in Netplan and NetworkManager.

What you will learn

  • Read addresses and interface state with ip -br addr and ip addr show
  • Read the routing table and ask the kernel for the route to a destination with ip route get
  • Bring an interface up or down with ip link set
  • Add and remove an address, and not forget its mask
  • Set a default route or a route to a specific network, and understand why it disappears
  • Recognize the common ip errors

Prerequisites

You know how to open a Linux terminal and use sudo. An IPv4 address with its mask (192.0.2.10/24) should look familiar: if not, read IP addressing and subnets (in French) first. An overview of Linux networking helps, without being required. The JSON section uses jq: install the jq package before you start, because the test network has no access to the Internet.

Create the test network

Changing the address or routes of your real machine can cut it off from the network. All the examples on this page therefore run in a network namespace: an empty network, isolated from the real one, that the kernel creates on demand. It has none of your interfaces or routes, and you delete it at the end.

Terminal window
sudo ip netns add essai
sudo ip netns exec essai bash

The second command opens a shell inside that namespace. You are root there: the following commands are therefore written without sudo, and do not touch your real network. Only the network is isolated: this root shell acts on your real files. exit brings you back to the normal shell. Now create a dummy interface dummy0 and give it an address:

Terminal window
ip link add dummy0 type dummy
ip addr add 192.0.2.10/24 dev dummy0
ip -V
Output of ip -V
ip utility, iproute2-6.15.0, libbpf 1.5.0

The first two commands succeed without printing anything. The outputs on this page come from Debian 13 with iproute2 6.15.0. They are identical on Ubuntu 26.04 (iproute2 6.19.0) and on AlmaLinux 10 (iproute2 7.0.0), apart from MAC addresses and fe80:: addresses. ip -V gives your version. The blocks chain together: each one starts from the state left by the previous one.

On a remote server

Outside the test namespace, ip link set eth0 down or a wrong default route cuts your SSH session, and only the machine's console gives it back. ip route get followed by the address of your workstation tells you which interface carries your session. The addresses 192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24 are reserved for documentation: no real network uses them.

The ip command in detail

An ip command is written ip object action parameters: the object says what you work on (addr, link, route, neigh), the action says what you do with it. Without an action, ip displays (show). The address always carries its mask. Read the line from left to right: each number points to the explanation of that piece.

Anatomy of the command

Syntaxip object action [parameters]

  1. ip the programIt reads and changes the network configuration.
  2. addr the objectaddr, link, route or neigh.
  3. add the actionshow by default, add, del, set.
  4. 192.0.2.11/24 the address and its mask/24 tells which addresses are local.
  5. dev dummy0 the interfaceThe one that holds the address.

Outputnothing: the command succeeds silently

Read the addresses

ip -br addr (-br for "brief") prints one line per interface: its name, its state and its addresses.

Terminal window
ip -br addr
Output
lo DOWN
dummy0 DOWN 192.0.2.10/24

Look at the second and third columns: dummy0 carries 192.0.2.10/24, but its state is DOWN. An address on an interface that is down is useless: you bring it up below. lo is the loopback interface, also down in a new namespace.

For the detail of one interface, ip addr show followed by its name also prints the MAC address, the MTU and the validity period of each address.

Terminal window
ip addr show dummy0
Output
2: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 86:d5:b9:4a:35:b7 brd ff:ff:ff:ff:ff:ff
inet 192.0.2.10/24 scope global dummy0
valid_lft forever preferred_lft forever

The MAC address is different on every machine: yours will differ. The inet lines carry IPv4 addresses, inet6 lines IPv6 addresses. qdisc noop (no queue attached) becomes noqueue once the interface is up.

Interpret the output

Three words in these outputs matter for diagnosis. state says whether the interface works: UP for a plugged-in network card, DOWN for an interface that is down or up without a cable (the detail then prints NO-CARRIER), UNKNOWN for a virtual interface like dummy0 that has no cable to watch. scope global marks an address usable beyond the local network, while scope link only holds on the physical segment of the interface: that is the case of the IPv6 addresses starting with fe80::, which the kernel creates on its own. valid_lft forever means the address does not expire, which is the case for an address set by hand.

ip link is about the interface itself: state, MAC address (third column of the output), MTU, flags. It prints no IP address: if you are looking for one, use ip addr.

Terminal window
ip -br link
Output
lo DOWN 00:00:00:00:00:00 <LOOPBACK>
dummy0 DOWN 86:d5:b9:4a:35:b7 <BROADCAST,NOARP>

Bring an interface up or down

ip link set followed by the interface name and up or down changes its state. Without up, nothing goes through dummy0, as the route below shows.

Terminal window
ip route
ip link set dummy0 up
ip -br addr
Output of ip -br addr
lo DOWN
dummy0 UNKNOWN 192.0.2.10/24 fe80::84d5:b9ff:fe4a:35b7/64

The first ip route prints nothing: the table is empty as long as the interface is down. After up, the state becomes UNKNOWN (virtual interface) and an fe80:: address appears, created by the kernel for IPv6.

If a command targets an interface that does not exist, ip says so without ambiguity:

Terminal window
ip link set nope0 up
Output
Cannot find device "nope0"

Read the routing table

The routing table says where each destination goes. ip route prints it, one route per line.

Terminal window
ip route
Output
192.0.2.0/24 dev dummy0 proto kernel scope link src 192.0.2.10

You did not write this line: the kernel created it when dummy0 went up, from the address 192.0.2.10/24. It means "the whole 192.0.2.0/24 network is reachable directly through dummy0, announcing itself as 192.0.2.10". proto kernel shows that it comes from the kernel. There is no default line yet: only the local network is reachable.

See the route to a destination

ip route get asks the kernel which route it would pick for an address, without sending anything. It is mostly useful when a server has several interfaces or several routes.

Terminal window
ip route get 192.0.2.77
ip route get 198.51.100.1
Outputs
192.0.2.77 dev dummy0 src 192.0.2.10 uid 0
cache
RTNETLINK answers: Network is unreachable

The first destination is in 192.0.2.0/24: it goes out directly through dummy0, with the source address 192.0.2.10. The second is in no known network and there is no default route: the kernel answers Network is unreachable.

Add and delete routes

A default route (default) receives everything that no other route contains. It points to a router, the gateway, which must be in one of the networks of the interface: 192.0.2.1 is in 192.0.2.0/24.

A gateway outside every local network is refused:

Terminal window
ip route add default via 203.0.113.1
Output
Error: Nexthop has invalid gateway.

The message is the same if the interface is down. With a router from the network of dummy0, the command succeeds:

Terminal window
ip route add default via 192.0.2.1
ip route
ip route get 198.51.100.1
Outputs of ip route and ip route get
default via 192.0.2.1 dev dummy0
192.0.2.0/24 dev dummy0 proto kernel scope link src 192.0.2.10
198.51.100.1 via 192.0.2.1 dev dummy0 src 192.0.2.10 uid 0
cache

198.51.100.1 now goes via 192.0.2.1: the kernel sends it to the router.

Add a static route

A route can target a specific network. Among several routes that contain the destination, the kernel takes the most specific one (the largest number after the slash).

Terminal window
ip route add 198.51.100.0/24 via 192.0.2.254
ip route get 198.51.100.77
ip route get 203.0.113.9
ip route del 198.51.100.0/24
ip route get 198.51.100.77
Outputs of the three ip route get
198.51.100.77 via 192.0.2.254 dev dummy0 src 192.0.2.10 uid 0
cache
203.0.113.9 via 192.0.2.1 dev dummy0 src 192.0.2.10 uid 0
cache
198.51.100.77 via 192.0.2.1 dev dummy0 src 192.0.2.10 uid 0
cache

198.51.100.77 first follows the static route, 203.0.113.9 the default route. Once the static route is removed with del, 198.51.100.77 follows the default route too.

Default route already present

Only one default route can exist with the same priority. ip route replace replaces the existing route, and creates it if it does not exist.

Terminal window
ip route add default via 192.0.2.254
ip route replace default via 192.0.2.254
ip route
Outputs
RTNETLINK answers: File exists
default via 192.0.2.254 dev dummy0
192.0.2.0/24 dev dummy0 proto kernel scope link src 192.0.2.10

The first add fails with File exists (code 2), because a default route of the same priority already exists, even with another router. replace succeeds without printing anything, and ip route shows the new gateway, 192.0.2.254.

How ip chooses a route, step by step

For each packet, the kernel looks for a route that contains its destination, then sends it or refuses it. The map follows two destinations, 192.0.2.77 and 198.51.100.1, with dummy0 and its address 192.0.2.10/24.

Before playing with the options, predict where the two destinations go in four cases: neither up nor default; up alone; default alone; both. For default, the command is ip route add default via 192.0.2.1. Then check on the map: look at the routing table and at the answer of ip route get.

Mental model

How the kernel chooses a route

read the destinationlook for a route that contains itsend, or refuse for each packet sent

$ ip route get 192.0.2.77; ip route get 198.51.100.1

  1. The interface is down: the routing table is empty, and 192.0.2.77 is refused.
  2. The interface is down: the routing table is empty, and 198.51.100.1 is refused.
  3. No destination is reachable: bring the interface up.

What the animation shows

  1. An address is not enough: the interface must be brought up with up.
  2. The local route comes by itself, from the address and its /24 mask.
  3. The default route handles the rest: everything that is not local.
  4. Taking the interface down deletes its routes, including the default route.

Golden rules

Ask the kernel, do not guess

ip route get tells which way a packet would leave:

ip route get 198.51.100.1

Write the mask with the address

Without /24, no local route is created:

ip addr add 192.0.2.10/24 dev dummy0

Essential vocabulary

Read the state · without changing anything

ip -br addr
The addresses, in briefip -br addr show dummy0 → one line per interface
ip route
The routing tableip link set dummy0 up; ip route → a local route
ip route get
The path to a destinationip link set dummy0 up; ip route get 192.0.2.77 → direct
ip addr show
A missing interfaceip addr show dev nope0; echo $? → code 1

Change the state · until the next reboot

addr add
Add an addressip addr add 192.0.2.11/24 dev dummy0; ip -br addr show dummy0 → 192.0.2.11 added
addr add
The same address twiceip addr add 192.0.2.10/24 dev dummy0; echo $? → code 2
addr add
No mask: /32, no routeip addr add 192.0.2.11 dev dummy0; ip -br addr show dummy0 → 192.0.2.11/32
link set down
Take the interface downip link set dummy0 up; ip link set dummy0 down; ip route → no route left

Add and remove an address

ip addr add sets an address on an interface, ip addr del removes it.

Terminal window
ip addr add 192.0.2.10/24 dev dummy0
Output
Error: ipv4: Address already assigned.

This error, and the code 2, show that dummy0 already carries this address. A second address in the same network is added without trouble:

Terminal window
ip addr add 192.0.2.11/24 dev dummy0

The command succeeds without printing anything. 192.0.2.11 becomes a secondary address of dummy0: the first one stays 192.0.2.10.

Wrong mask on deletion

ip addr del finds the address by its mask: it must be the one used when adding. Add 192.0.2.13 as a /24, then try to remove it with another mask:

Terminal window
ip addr add 192.0.2.13/24 dev dummy0
ip addr del 192.0.2.13/32 dev dummy0
Output of the del
Error: ipv4: Address not found.

The del fails with code 2: no 192.0.2.13/32 address exists. Remove it with its real mask:

Terminal window
ip addr del 192.0.2.13/24 dev dummy0
An almost ready interface Exercise 1 of 2 · ~8 min · terminal

In the test namespace, a colleague prepares an interface dummy1 for the 198.51.100.0/24 network with: ip link add dummy1 type dummy; ip link set dummy1 up; ip addr add 198.51.100.20 dev dummy1. They say the interface is ready. Check, then fix.

Run the colleague's command

Run the three commands of the statement, print the addresses of dummy1, then ask for the route to 198.51.100.21, a machine of that network.

Look for the network route

List the routes that go through dummy1, and compare them with those of dummy0.

Fix and check

Fix the address, count the routes of dummy1 again and ask for the route again. Then delete dummy1.

A hint 1 / 1

Compare the address of dummy1 with the one of dummy0, character by character. To filter the routes of a single interface, ip route show accepts dev followed by the name.

I have tried: show the solution
Terminal window
ip link add dummy1 type dummy; ip link set dummy1 up; ip addr add 198.51.100.20 dev dummy1
ip -br addr show dummy1
ip route get 198.51.100.21
ip addr del 198.51.100.20/32 dev dummy1
ip addr add 198.51.100.20/24 dev dummy1
ip route show dev dummy1
ip route get 198.51.100.21
ip link del dummy1
Outputs
dummy1 UNKNOWN 198.51.100.20/32 fe80::5c36:f8ff:fedf:901f/64
198.51.100.21 via 192.0.2.254 dev dummy0 src 192.0.2.10 uid 0
cache
198.51.100.0/24 proto kernel scope link src 198.51.100.20
198.51.100.21 dev dummy1 src 198.51.100.20 uid 0
cache

The address was set without a mask: ip created it as a /32, without warning. It only covers itself and the kernel created no route. The packet therefore follows the default route and leaves through dummy0, with no error at all. With /24, the route of dummy1 is more specific than the default route: it wins.

Forgetting the CIDR mask

An address set without a mask becomes a /32, and ip reports nothing: the interface carries an address but does not know its network. After each ip addr add, read the number that follows the slash and check the route with ip route get. Without a mask, ip addr del removes the address while warning that this behavior will disappear: always write the mask, when adding as when deleting.

Bring an interface down and up again

ip link set dummy0 down brings the interface down, and the kernel then removes all the routes that went through it, the default route included.

Terminal window
ip link set dummy0 down
ip route
ip addr show dummy0
Output of ip addr show dummy0
2: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 86:d5:b9:4a:35:b7 brd ff:ff:ff:ff:ff:ff
inet 192.0.2.10/24 scope global dummy0
valid_lft forever preferred_lft forever
inet 192.0.2.11/24 scope global secondary dummy0
valid_lft forever preferred_lft forever

ip route prints nothing anymore. The addresses 192.0.2.10/24 and 192.0.2.11/24 (marked secondary) are still there, but the interface is DOWN: the routes left with it. The exercise below shows what link set up gives back. dummy0 stays down for the rest of the page.

A destination that became unreachable Exercise 2 of 2 · ~10 min · terminal

In the test namespace, dummy0 is down. Create dummy2 with the address 203.0.113.10/24 and a default route via 203.0.113.1. Check that 198.51.100.77 goes through the gateway. A colleague brings dummy2 down then up again (ip link set dummy2 down then up) and says that "nothing changed". See for yourself.

Bring up dummy2 and its default route

Create the interface, bring it up, set the address and the default route. Count the lines of ip route, then ask for the route to 198.51.100.77.

Bring down then up again

Run the down and up of the interface. Count the lines of ip route again.

Ask the kernel and fix

Ask again for the route to 198.51.100.77, print the exit code with echo $?, then restore the situation and delete dummy2.

A hint 1 / 1

Bringing the interface up again gives back what the kernel creates on its own from the address. What you wrote by hand is not part of it.

I have tried: show the solution
Terminal window
ip link add dummy2 type dummy; ip link set dummy2 up
ip addr add 203.0.113.10/24 dev dummy2
ip route add default via 203.0.113.1
ip route
ip route get 198.51.100.77
ip link set dummy2 down; ip link set dummy2 up
ip route
ip route get 198.51.100.77; echo $?
ip route add default via 203.0.113.1
ip route get 198.51.100.77
ip link del dummy2
Outputs, in order
default via 203.0.113.1 dev dummy2
203.0.113.0/24 dev dummy2 proto kernel scope link src 203.0.113.10
198.51.100.77 via 203.0.113.1 dev dummy2 src 203.0.113.10 uid 0
cache
203.0.113.0/24 dev dummy2 proto kernel scope link src 203.0.113.10
RTNETLINK answers: Network is unreachable
2
198.51.100.77 via 203.0.113.1 dev dummy2 src 203.0.113.10 uid 0
cache

Before the interface goes down, the table has two lines: the default route and the local route. After it comes back up, only one is left, the local route 203.0.113.0/24, which the kernel recreates from the address. ip route get 198.51.100.77 answers Network is unreachable and returns code 2: the default route disappeared with the shutdown, and up does not give it back. Pushing the default route again restores the path.

Show the ARP cache

ip neigh ("neighbours") prints the resolution cache: for each IP address of the local network, the MAC address learned. In the test namespace, no machine has answered: the table is empty.

Terminal window
ip neigh

No line is printed. On a real server, each line carries a state. REACHABLE marks an entry confirmed recently. STALE marks an entry that has not been confirmed for a while: it may be obsolete, and the kernel rechecks it on next use. FAILED marks a resolution that stayed unanswered.

Here, as an example, is a line taken from a machine connected to a real network (not in the test namespace):

Example output of ip neigh
10.10.96.1 dev enp5s0 lladdr 10:66:6a:8f:ba:b8 REACHABLE

It says that the address 10.10.96.1, reachable through enp5s0, has the MAC address 10:66:6a:8f:ba:b8, and that this association was confirmed recently.

Change the MTU

The MTU is the maximum size of a packet on the interface, 1500 bytes by default on Ethernet. ip link set followed by mtu changes it, for example for a tunnel that adds headers.

Terminal window
ip link set dummy0 mtu 1400
ip addr show dummy0
First line of ip addr show dummy0
2: dummy0: <BROADCAST,NOARP> mtu 1400 qdisc noqueue state DOWN group default qlen 1000

The first line of ip addr show prints the current MTU: it goes from mtu 1500 to mtu 1400.

Interface statistics

ip -s link show adds the counters of received (RX) and sent (TX) packets for each interface.

Terminal window
ip -s link show dummy0
Output
2: dummy0: <BROADCAST,NOARP> mtu 1400 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
link/ether 86:d5:b9:4a:35:b7 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped missed mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
70 1 0 0 0 0

Your TX counters may differ: the kernel sends a few packets on its own. On a real card, run the command again a few seconds later. If errors goes up, packets arrive or leave damaged: look at the cable, the card or the driver.

JSON output for scripts

The global option -j writes the output as JSON, on a single line. A jq filter extracts a field from it, without parsing text by hand:

Terminal window
ip -j addr | jq -r '.[].ifname'
Output
lo
dummy0

Which command should you choose?

For an action that ip does not cover, another command takes over. The old net-tools commands have an equivalent:

NeedCommand
Listening ports, connectionsss (see network diagnosis)
Connectivity test, DNS, latencyping, dig, mtr (same page)
Read addresses and interfacesip addr, ip link instead of ifconfig
Bring an interface upip link set eth0 up instead of ifconfig eth0 up
Read the routesip route show instead of route -n
Set a gatewayip route add default via instead of route add default gw
Read the ARP cacheip neigh show instead of arp -a
Interface countersip -s link instead of netstat -i
Write shorterip a for ip addr, ip r for ip route
IPv4 onlyip -4 -br addr
Follow changes liveip monitor
Remove all the addresses of an interfaceip addr flush dev eth0; never on the one of your SSH session

Using ifconfig instead of ip

ifconfig (package net-tools) only prints one IPv4 address per interface: a second address added with ip addr add does not show up in it, on Debian 13, Ubuntu 26.04 and AlmaLinux 10. ip -br addr shows both.

Common errors

When an ip command fails, the message gives the cause: look it up in this table.

MessageCauseFix
RTNETLINK answers: Operation not permittedYou are not root, or the container lacks the NET_ADMIN capabilityAdd sudo; in a container, give it the capability
Cannot open network namespace "essai": No such file or directory (code 255)The namespace no longer exists: deleted with ip netns del, or never createdsudo ip netns add essai, then replay the commands
Error: ipv4: Address already assigned.Address already set on the interfaceip -br addr to see it, or pick another address
Error: ipv4: Address not found.ip addr del with a mask different from the one used when addingRead the mask again in ip -br addr, repeat it identically
Cannot find device "nope0"Wrong interface name; ip addr show dev nope0 prints Device "nope0" does not exist. instead and returns code 1ip -br link gives the real names
RTNETLINK answers: Network is unreachableNo route contains the destinationSet a default route or bring the interface up
Error: Nexthop has invalid gateway.Gateway outside every local network (often a forgotten mask), or interface downCheck the mask, ip link set … up, then the route
RTNETLINK answers: File existsA route to the same destination, with the same priority, already existsip route replace
RTNETLINK answers: No such processip route del of a route that does not existRead ip route again

Changes are not persistent

The ip commands on this page write to the kernel memory: at reboot, addresses and routes set by hand are lost, and so is the essai namespace. For a configuration to survive, write it in the tool of the distribution: Netplan on Ubuntu, NetworkManager on RHEL, Rocky and AlmaLinux. The page Linux networking fundamentals lists the tool of each distribution, Debian with ifupdown included.

Clean up the test network

Leave the shell of the test namespace, then delete it. Its interfaces, addresses and routes disappear with it, and your real network was never modified.

Terminal window
exit
sudo ip netns del essai
ip netns list

ip netns list must no longer print essai: the list is empty.

Key points

  • ip object action: addr for addresses, link for interfaces, route for routes, neigh for neighbours. Without an action, ip displays.
  • ip -br addr and ip route read the state. ip route get says where a packet would go, without sending anything.
  • An address is set with its mask: without it, ip creates a /32 without warning, and no local route appears.
  • An interface must be brought up (link set up) for its routes to exist. Bringing it down erases its routes, the default route included.
  • Network is unreachable means that no route contains the destination. ip route replace replaces a route without the File exists error.
  • Everything ip does is lost at reboot: write the configuration in Netplan or NetworkManager.

Knowledge check

Check that the essentials of this guide stuck. The questions cover only what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer