Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

Show Addresses: ip a

ip a
ip -br a
ip a show dev eth0

ip a is short for ip address show. Each interface block shows its state (UP or DOWN), the MAC address after link/ether, IPv4 addresses on inet lines, and IPv6 addresses on inet6 lines, each with its prefix length, such as /24. The lo interface is the loopback with 127.0.0.1, explained in what is localhost. -br prints one short line per interface.

Interface names differ between servers: eth0, ens3, and enp1s0 are all common. The examples use eth0; list yours with ip -br link and use that name instead. Objects can be shortened: ip a, ip addr, and ip address are the same command.

Interfaces: ip link

ip link
ip -br link
ip -s link show dev eth0

ip link shows each interface with its MTU, state, and MAC address, without IP addresses. -s adds counters for bytes, packets, errors, and dropped packets in both directions. Rising error or drop counters point to a link or driver problem rather than a configuration mistake.

Routes: ip r

ip r
ip route get 198.51.100.20

The line that starts with default via names the gateway and the interface that leads to it. Lines with proto kernel scope link are the local networks the kernel adds for each address. ip route get shows which route, interface, and source address the server would use to reach one destination, which helps on servers with several addresses or interfaces.

Before You Change Anything

A wrong address or route cuts your SSH session, and you may not get it back over the network.

  • Find the console first: know where the server console is in your provider's control panel. It works without the network.
  • Write down the current state: save the output of ip a and ip r, for example with ip a > ~/ip-a.txt.
  • Use real values: on a cloud server, the addresses, prefix, and gateway come from the provider. Use the values shown in the control panel, never invented ones.
  • Test, then make permanent: changes made with ip addr and ip route disappear at reboot, which makes them the safe way to test. A reboot from the console undoes a mistake.

Add a Temporary Address or Route

sudo ip addr add 192.0.2.50/24 dev eth0
ip a show dev eth0
sudo ip addr del 192.0.2.50/24 dev eth0

sudo ip route add 198.51.100.0/24 via 203.0.113.1 dev eth0
sudo ip route del 198.51.100.0/24

An extra public address only works after the provider has assigned it to your server. Never run ip route del default, ip addr flush, or ip link set eth0 down on the interface your SSH session uses: the session ends at once. To keep a setting after reboot, write it into the network configuration, as shown in how to configure a static IP with netplan and how to set a static IP with nmcli.

IPv6: ip -6

ip -6 a
ip -6 r

-6 limits the output to IPv6, and -4 to IPv4. Every interface with IPv6 has a fe80:: address with scope link; it is valid only on that network segment. A public IPv6 address shows scope global. Details are in how to configure IPv6 on a Linux server.

Neighbors: ip neigh

ip neigh
ip neigh show dev eth0

This is the ARP table for IPv4 and the neighbor table for IPv6: each line pairs an IP address on the local network with a MAC address (lladdr) and a state. REACHABLE and STALE are normal. If the gateway shows FAILED or INCOMPLETE, the server cannot reach it at all, which usually means a wrong address, prefix, or gateway.

ip vs ifconfig

TaskOld toolip
Addressesifconfigip a
Interface upifconfig eth0 upip link set eth0 up
Routesroute -nip r
ARP tablearp -nip neigh

ifconfig, route, and arp belong to the old net-tools package, which minimal server images often leave out. ifconfig may also leave out extra addresses on an interface. Use ip; for the other everyday network tools, see Linux network commands, and for prefix lengths, subnet masks and CIDR notation.

Was this answer helpful?
Loading...