Log inSign up

Reading and changing network settings with ip

The ip tool from the iproute2 package is the current way to inspect and change Linux networking. Run ip -br addr for a one line summary of every interface, ip route for the routing table and ip route get 198.51.100.1 to see which path a packet would take. Changes made with ip are live but temporary; lasting settings belong in netplan, ifupdown or NetworkManager.

Topic: Networking and diagnostics · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

Why use ip instead of ifconfig and route?

Because ip is installed on every current distribution and shows everything the kernel knows, while the old net-tools commands are deprecated and often absent. ifconfig cannot display more than one address per interface cleanly, ignores many IPv6 details and knows nothing about policy routing or network namespaces. The iproute2 package comes preinstalled on Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9 and AlmaLinux 9, so there is nothing to install. Check the version with:

ip -V

Commands follow a simple pattern: ip [options] OBJECT COMMAND. The objects you will use most are addr (addresses), link (interfaces), route (routing table) and neigh (ARP and neighbor cache). Every object and command can be shortened, so ip a, ip r and ip n all work.

How do you list addresses?

Run ip addr for the full view or add -br (brief) for one tidy line per interface. Adding -c colors the state and addresses, which helps when reading quickly:

ip -br -c addr
ip addr show dev eth0
ip -4 addr
ip -6 addr show scope global

In the brief view each line holds the interface name, its state and then every address on it. The loopback lo carries 127.0.0.1/8 and ::1/128; the main interface shows your public IPv4 (for example 198.51.100.24), the global IPv6 address and a fe80:: link local address. The number after each slash is the prefix length, which defines the local subnet, so read it from your own output rather than assuming a value. Interface names vary between images: eth0, ens3 and enp1s0 are all common. Use the name your own output shows in every later command. The -4 and -6 switches filter by family, and scope global hides link local addresses. For an IPv6 walkthrough, see IPv6 on your server.

How do you check interface state and counters?

Use ip link to see whether an interface is up, its MAC address and MTU, and add -s for packet and error counters:

ip -br link
ip -s link show dev eth0

The state field reads UP, DOWN or UNKNOWN (the loopback always says unknown, which is normal). In the statistics, steadily rising errors or dropped values deserve attention, while a handful accumulated over weeks usually does not. The mtu value matters for tunnels: WireGuard and other VPN interfaces use a smaller MTU than the main interface, and a mismatch shows up as connections that open but stall on larger transfers. Running ip -s -s link doubles the detail level and splits errors by type.

How do you read the routing table?

Run ip route for IPv4 and ip -6 route for IPv6. The most important line starts with default via, which names the gateway that carries all traffic not covered by a more specific route:

ip route
ip -6 route
ip route get 1.1.1.1
ip route get 198.51.100.77

ip route get is the most useful troubleshooting form: it asks the kernel which interface, gateway and source address it would use for a destination right now, taking policy rules and VPN routes into account. When a VPN is active and traffic leaks out the wrong way, or a service replies from an unexpected address, this command gives the honest answer. Policy routing rules, used by tools like WireGuard when they route everything through the tunnel, appear with ip rule.

How do you view neighbors and the ARP cache?

ip neigh lists the MAC addresses the server has learned for hosts on its local segment, mostly the gateway:

ip neigh
ip -6 neigh

A gateway entry marked REACHABLE or STALE is healthy (stale only means it has not been confirmed recently). FAILED or INCOMPLETE for the gateway means the server cannot reach its next hop at layer 2, which explains a total loss of connectivity. In that case collect the output and include it in a support ticket, since the problem may sit outside your server.

How do you make temporary changes?

You can add addresses, routes and change link state on the fly. These changes take effect at once and vanish on reboot, which makes them a safe way to experiment:

sudo ip addr add 10.20.0.1/24 dev wg0
sudo ip route add 10.30.0.0/24 via 10.20.0.2 dev wg0
sudo ip link set dev eth1 mtu 1400
sudo ip route del 10.30.0.0/24

Be careful with the main interface. Running ip link set eth0 down or deleting the default route cuts your SSH session immediately, and with no browser console offered you would need to restart the server from the instance page to recover (a reboot discards the temporary change). Practice on a tunnel or a dummy interface instead:

sudo ip link add dummy0 type dummy
sudo ip addr add 192.0.2.1/32 dev dummy0
sudo ip link set dummy0 up
sudo ip link del dummy0

Where do permanent network settings live?

Each distribution family keeps its network configuration in a different place, and the ip command does not write to any of them. Make lasting changes in the right file instead:

  • Ubuntu: netplan YAML files in /etc/netplan/. Apply with sudo netplan try, which reverts automatically if you do not confirm within two minutes.
  • Debian: usually /etc/network/interfaces (ifupdown), sometimes netplan on newer cloud builds. Check which one exists before editing.
  • Rocky Linux and AlmaLinux: NetworkManager. List profiles with nmcli connection show and change them with nmcli connection modify.

Your server receives its public addresses through the image defaults, so most people never need to touch these files. Edit them only for extra items such as a static route to a tunnel, and keep a second SSH session open while applying changes.

Which options make the output easier to script?

Use -j for JSON output, which pairs well with jq, or -o for one record per line suitable for grep and awk:

ip -j addr show dev eth0 | jq -r '.[0].addr_info[] | select(.scope=="global") | .local'
ip -o -4 addr show | awk '{print $2, $4}'

JSON output is stable across releases and avoids parsing columns that may shift. Install jq with sudo apt install jq or sudo dnf install jq. These forms are handy in deployment scripts that need the server address, for example when writing a configuration file for a web server or a WireGuard endpoint.

Questions about The ip command

Can I still install ifconfig?

Yes, the net-tools package provides it on Ubuntu, Debian, Rocky and Alma. It works for simple reading, but it misses details that ip shows, so new scripts should use ip.

Why does my change disappear after a reboot?

Because ip only edits the running kernel state. Put lasting settings into netplan, /etc/network/interfaces or a NetworkManager profile, depending on the distribution.

How do I find the public IP from inside the server?

Run ip -br addr; the global addresses on the main interface are the public IPv4 and IPv6. The console also lists them, as explained in the server IP addresses guide.

What does "scope link" mean on an address?

It marks an address that is only valid on the local network segment, such as the fe80:: IPv6 address. It cannot be reached from the internet.

Can ip show network namespaces used by containers?

Yes. ip netns list shows named namespaces, and ip -n NAME addr runs a command inside one. Docker namespaces are unnamed by default, so nsenter is the usual tool there.