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 addrandip 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
iperrors
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.
sudo ip netns add essaisudo ip netns exec essai bashThe 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:
ip link add dummy0 type dummyip addr add 192.0.2.10/24 dev dummy0ip -Vip utility, iproute2-6.15.0, libbpf 1.5.0The 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]
ipaddradd192.0.2.11/24dev dummy0 -
ipthe programIt reads and changes the network configuration. -
addrthe objectaddr,link,routeorneigh. -
addthe actionshowby default,add,del,set. -
192.0.2.11/24the address and its mask/24tells which addresses are local. -
dev dummy0the 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.
ip -br addrlo DOWNdummy0 DOWN 192.0.2.10/24Look 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.
ip addr show dummy02: 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 foreverThe 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.
Confusing link and addr
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.
ip -br linklo 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.
ip routeip link set dummy0 upip -br addrlo DOWNdummy0 UNKNOWN 192.0.2.10/24 fe80::84d5:b9ff:fe4a:35b7/64The 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:
ip link set nope0 upCannot find device "nope0"Read the routing table
The routing table says where each destination goes. ip route prints it, one route per line.
ip route192.0.2.0/24 dev dummy0 proto kernel scope link src 192.0.2.10You 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.
ip route get 192.0.2.77ip route get 198.51.100.1192.0.2.77 dev dummy0 src 192.0.2.10 uid 0 cacheRTNETLINK answers: Network is unreachableThe 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:
ip route add default via 203.0.113.1Error: 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:
ip route add default via 192.0.2.1ip routeip route get 198.51.100.1default via 192.0.2.1 dev dummy0192.0.2.0/24 dev dummy0 proto kernel scope link src 192.0.2.10198.51.100.1 via 192.0.2.1 dev dummy0 src 192.0.2.10 uid 0 cache198.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).
ip route add 198.51.100.0/24 via 192.0.2.254ip route get 198.51.100.77ip route get 203.0.113.9ip route del 198.51.100.0/24ip route get 198.51.100.77198.51.100.77 via 192.0.2.254 dev dummy0 src 192.0.2.10 uid 0 cache203.0.113.9 via 192.0.2.1 dev dummy0 src 192.0.2.10 uid 0 cache198.51.100.77 via 192.0.2.1 dev dummy0 src 192.0.2.10 uid 0 cache198.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.
ip route add default via 192.0.2.254ip route replace default via 192.0.2.254ip routeRTNETLINK answers: File existsdefault via 192.0.2.254 dev dummy0192.0.2.0/24 dev dummy0 proto kernel scope link src 192.0.2.10The 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
Try Requested destinations
Look for a route
Routing table
$ ip route get 192.0.2.77; ip route get 198.51.100.1
- The interface is down: the routing table is empty, and 192.0.2.77 is refused.
- The interface is down: the routing table is empty, and 198.51.100.1 is refused.
- No destination is reachable: bring the interface up.
What the animation shows
- An address is not enough: the interface must be brought up with
up. - The local route comes by itself, from the address and its
/24mask. - The default route handles the rest: everything that is not local.
- 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.1Write the mask with the address
Without /24, no local route is created:
ip addr add 192.0.2.10/24 dev dummy0Essential vocabulary
Read the state · without changing anything
ip -br addr- The addresses, in brief
ip -br addr show dummy0→ one line per interface ip route- The routing table
ip link set dummy0 up; ip route→ a local route ip route get- The path to a destination
ip link set dummy0 up; ip route get 192.0.2.77→ direct ip addr show- A missing interface
ip addr show dev nope0; echo $?→ code 1
Change the state · until the next reboot
addr add- Add an address
ip addr add 192.0.2.11/24 dev dummy0; ip -br addr show dummy0→ 192.0.2.11 added addr add- The same address twice
ip addr add 192.0.2.10/24 dev dummy0; echo $?→ code 2 addr add- No mask: /32, no route
ip addr add 192.0.2.11 dev dummy0; ip -br addr show dummy0→ 192.0.2.11/32 link set down- Take the interface down
ip 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.
ip addr add 192.0.2.10/24 dev dummy0Error: 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:
ip addr add 192.0.2.11/24 dev dummy0The 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:
ip addr add 192.0.2.13/24 dev dummy0ip addr del 192.0.2.13/32 dev dummy0Error: ipv4: Address not found.The del fails with code 2: no 192.0.2.13/32 address exists. Remove it with its real mask:
ip addr del 192.0.2.13/24 dev dummy0An almost ready interface
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.
- ip addr add
- ip link add
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
ip link add dummy1 type dummy; ip link set dummy1 up; ip addr add 198.51.100.20 dev dummy1ip -br addr show dummy1ip route get 198.51.100.21ip addr del 198.51.100.20/32 dev dummy1ip addr add 198.51.100.20/24 dev dummy1ip route show dev dummy1ip route get 198.51.100.21ip link del dummy1dummy1 UNKNOWN 198.51.100.20/32 fe80::5c36:f8ff:fedf:901f/64198.51.100.21 via 192.0.2.254 dev dummy0 src 192.0.2.10 uid 0 cache198.51.100.0/24 proto kernel scope link src 198.51.100.20198.51.100.21 dev dummy1 src 198.51.100.20 uid 0 cacheThe 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.
ip link set dummy0 downip routeip addr show dummy02: 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 foreverip 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
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.
- ip route get
- ip link set
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
ip link add dummy2 type dummy; ip link set dummy2 upip addr add 203.0.113.10/24 dev dummy2ip route add default via 203.0.113.1ip routeip route get 198.51.100.77ip link set dummy2 down; ip link set dummy2 upip routeip route get 198.51.100.77; echo $?ip route add default via 203.0.113.1ip route get 198.51.100.77ip link del dummy2default via 203.0.113.1 dev dummy2203.0.113.0/24 dev dummy2 proto kernel scope link src 203.0.113.10198.51.100.77 via 203.0.113.1 dev dummy2 src 203.0.113.10 uid 0 cache203.0.113.0/24 dev dummy2 proto kernel scope link src 203.0.113.10RTNETLINK answers: Network is unreachable2198.51.100.77 via 203.0.113.1 dev dummy2 src 203.0.113.10 uid 0 cacheBefore 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.
ip neighNo 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):
10.10.96.1 dev enp5s0 lladdr 10:66:6a:8f:ba:b8 REACHABLEIt 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.
ip link set dummy0 mtu 1400ip addr show dummy02: dummy0: <BROADCAST,NOARP> mtu 1400 qdisc noqueue state DOWN group default qlen 1000The 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.
ip -s link show dummy02: 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 0Your 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:
ip -j addr | jq -r '.[].ifname'lodummy0Which command should you choose?
For an action that ip does not cover, another command takes over. The old net-tools commands have an equivalent:
| Need | Command |
|---|---|
| Listening ports, connections | ss (see network diagnosis) |
| Connectivity test, DNS, latency | ping, dig, mtr (same page) |
| Read addresses and interfaces | ip addr, ip link instead of ifconfig |
| Bring an interface up | ip link set eth0 up instead of ifconfig eth0 up |
| Read the routes | ip route show instead of route -n |
| Set a gateway | ip route add default via instead of route add default gw |
| Read the ARP cache | ip neigh show instead of arp -a |
| Interface counters | ip -s link instead of netstat -i |
| Write shorter | ip a for ip addr, ip r for ip route |
| IPv4 only | ip -4 -br addr |
| Follow changes live | ip monitor |
| Remove all the addresses of an interface | ip 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.
| Message | Cause | Fix |
|---|---|---|
RTNETLINK answers: Operation not permitted | You are not root, or the container lacks the NET_ADMIN capability | Add 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 created | sudo ip netns add essai, then replay the commands |
Error: ipv4: Address already assigned. | Address already set on the interface | ip -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 adding | Read 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 1 | ip -br link gives the real names |
RTNETLINK answers: Network is unreachable | No route contains the destination | Set a default route or bring the interface up |
Error: Nexthop has invalid gateway. | Gateway outside every local network (often a forgotten mask), or interface down | Check the mask, ip link set … up, then the route |
RTNETLINK answers: File exists | A route to the same destination, with the same priority, already exists | ip route replace |
RTNETLINK answers: No such process | ip route del of a route that does not exist | Read 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.
exitsudo ip netns del essaiip netns listip netns list must no longer print essai: the list is empty.
Key points
ip object action:addrfor addresses,linkfor interfaces,routefor routes,neighfor neighbours. Without an action,ipdisplays.ip -br addrandip routeread the state.ip route getsays where a packet would go, without sending anything.- An address is set with its mask: without it,
ipcreates a/32without 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 unreachablemeans that no route contains the destination.ip route replacereplaces a route without theFile existserror.- Everything
ipdoes 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
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
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Configure the network with Netplan
A new full quiz with random questions
Work again only on the questions you missed