Where to start First steps track · 15 stages
Linux Labs

ip — addresses, interfaces and routes

6 min Ubuntu 24.04 · iproute2

Manage interfaces, addresses and routes (iproute2) — the replacement for ifconfig/route.

Cheat sheet

7 commands Printable version
  • ip -br a addresses, brief
  • ip -br l interfaces, brief
  • ip r routing table
  • ip route get 8.8.8.8 path a specific packet would take
  • ip neigh ARP
  • sudo ip a add 192.168.1.10/24 dev eth0 add an address temporarily
  • permanent: /etc/netplan/*.yaml + sudo netplan apply

Overview

ip (the iproute2 package) is the modern tool for interfaces, addresses and routes. It replaces the legacy ifconfig, route, arp.

Subcommands can be abbreviated: ip a = ip address, ip r = ip route, ip l = ip link. Useful output modifiers: -br (brief) for compact output, -c for color, -s for statistics.

Options

8

Output modifiers (-br, -s, -c, -d, -h) go right after ip and only affect how the result is printed, not which object is selected: ip -br a and ip a -br are the same. -4/-6 narrow the output to one protocol version — useful when an interface has both IPv4 and IPv6 and the extra lines get in the way.

Option What it does Example
-br --brief Brief, compact output — one line per object. ip -br a
-s --stats Show statistics — packet, byte and error counters. ip -s link show eth0
-4 Restrict the output to IPv4. ip -4 a
-6 Restrict the output to IPv6. ip -6 a
-c --color Colorize the output. ip -c a
-o --oneline Print each record on a single line — convenient for parsing. ip -o a
-d --details More details about the object. ip -d link show eth0
-h --human-readable Human-readable size numbers (KB/MB/GB). ip -h -s link show eth0

Nothing found. Try a shorter query.

Recipes

4

ip objects

Object About Common
ip address (a) IP addresses on interfaces ip -br a
ip link (l) the interfaces themselves (up/down, MTU, MAC) ip -br l
ip route (r) the routing table ip r
ip neigh (n) ARP/neighbors (IP↔MAC) ip n
ip -s link packet/error counters per interface
ip route get which route will be chosen ip route get IP

Commands

bash
ip -br a                          # addresses, brief (name · state · address)
ip -c a                           # with color
ip a show eth0                    # a single interface
ip -br l                          # interface list and link state
ip -s link show eth0              # RX/TX counters, errors, drops
ip r                              # routing table
ip route get 8.8.8.8              # which route/interface a packet takes
ip neigh                          # the ARP table (neighbors)

# changes (TEMPORARY, until reboot):
sudo ip link set eth0 up          # bring the interface up
sudo ip link set eth0 mtu 1400    # change MTU
sudo ip a add 192.168.1.10/24 dev eth0    # add an address
sudo ip a del 192.168.1.10/24 dev eth0    # remove an address
sudo ip r add default via 192.168.1.1     # default gateway
sudo ip r add 10.10.0.0/16 via 192.168.1.254   # static route
sudo ip neigh flush all           # clear the ARP cache

Changes made with ip ... are temporary (until reboot). For permanent configuration on Ubuntu Server, use netplan (/etc/netplan/*.yaml, sudo netplan apply).

Address, prefix and subnet

192.0.2.10/24 is an address and a prefix: the first 24 bits (192.0.2) are the network number, the rest is the host number. Addresses with the same network number form the subnet 192.0.2.0/24: from 192.0.2.0 to 192.0.2.255, hosts get .1–.254. Neighbours in a subnet exchange packets directly; another subnet needs a route — without one ping prints Network is unreachable at once (see ping).

bash
ip -4 -br a                       # addresses with prefixes
ip r                              # subnets you have a path to
ip route get 192.0.2.1            # which way a packet will go

Network diagnostics

bash
ip -br a                          # is there an address at all
ip -br l                          # is the link up? (NO-CARRIER = cable/port)
ip route get 8.8.8.8              # is there a route out, and through what
ping -c3 192.168.1.1              # is the gateway reachable
getent hosts example.com          # does DNS work (see dns-resolv)
ss -tlnp                          # what ports listen locally

The natural ladder: address → link → route/gateway → external IP → DNS → port (see network-diagnostics).

Troubleshooting

5

No address (ip -br a empty/down)

The interface is down (sudo ip link set <if> up), or DHCP/netplan didn't run (sudo netplan apply, journalctl -u systemd-networkd).

NO-CARRIER in ip -br l

No physical link: cable/port/switch. Check the hardware with ethtool.

There's an address, but "Network is unreachable"

No default route: ip r has no default line → add a gateway (in netplan).

Two interfaces, traffic goes "the wrong way"

ip route get <IP> shows the actual choice. It's governed by route metrics and order; fix it in netplan (metric:) or with policy routing.

IP pings, names don't

That's DNS, not ip: resolvectl status, getent hosts name (see dns-resolv).

Terms

12
network interface
A kernel object for sending and receiving packets, representing a physical or virtual device. Also appears in: cgroups and namespaces, Docker
IP address
A network-layer address assigned to an interface for IPv4 or IPv6 packet exchange. Also appears in: The veth pair and network namespaces, Ansible: inventory, modules and one-off commands, DHCP server, nmap: which ports are visible from outside and 2 more
network prefix
The leading address portion identifying a network; /N specifies its length in bits.
loopback
A local interface for communication within a network environment; typical addresses are 127.0.0.1 and ::1. Also appears in: GPG, hostname, Postfix
route
A path-selection entry for a destination network or host, such as an interface and next gateway. Also appears in: Persistent networking with netplan, ping, tcpdump, Network diagnostics and 15 more
gateway
The next host to which a packet is handed along the selected route. Also appears in: nginx, HTTP, Persistent networking with netplan, Network diagnostics and 6 more
ARP
A protocol resolving a neighbor IPv4 address to its link-layer address on a local network. Also appears in: nmap: which ports are visible from outside, ping
default route
A zero-length-prefix route used when no more specific matching route applies. Also appears in: Persistent networking with netplan, ping
route metric
A numeric preference between otherwise comparable routes; a lower value is generally preferred.
return path
The response path from recipient back to the original sender. Also appears in: tcpdump
blackhole route
A route deliberately discarding packets for its destination.
subnet
Addresses sharing one network number, such as 192.0.2.0/24: neighbours in it exchange packets directly; another subnet needs a route. Also appears in: The veth pair and network namespaces, DHCP server, ping, Network diagnostics and 1 more

See also

  • ping — check whether packets get through.
  • veth — the veth pair and network namespaces.
  • ss — Who's listening on what ports and which connections are open — the modern netstat.
  • firewall — Traffic filtering — simple ufw and low-level nftables.
  • sshd — The SSH server — remote access by keys, config and hardening.
Loading…