ip: network interfaces, addresses and routes
ip is the Linux tool for network interfaces, addresses and routing. It replaced the older ifconfig, route and arp commands, which are no longer installed by default on many distributions.
Show the network setup
ip a # all interfaces and their addresses
ip -br a # brief: one line per interface
ip a show eth0 # one interface
ip -4 a # IPv4 only
ip link # interfaces, MAC addresses, state (UP/DOWN)
ip -s link show eth0 # with traffic and error counters
ip r # routing table
ip r get 8.8.8.8 # which route and source address would be used
ip neigh # neighbour (ARP/NDP) table
$ ip -br a
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0 UP 203.0.113.10/24 2001:db8::10/64 fe80::5054:ff:fe12:3456/64
wg0 UNKNOWN 10.8.0.1/24
Change settings (temporary)
sudo ip addr add 192.168.1.50/24 dev eth0 # add an address
sudo ip addr del 192.168.1.50/24 dev eth0 # remove it
sudo ip link set eth0 up # bring an interface up
sudo ip link set eth0 down
sudo ip route add 10.20.0.0/16 via 192.168.1.1 # route a network through a gateway
sudo ip route replace default via 192.168.1.1 # set the default gateway
sudo ip link set eth0 mtu 9000 # jumbo frames
…and changing the address or default route of the interface you are connected through will drop your SSH session. Make permanent changes in the distribution's network configuration instead.
Permanent configuration
| System | Where |
|---|---|
| RHEL, Fedora, SUSE 16, desktops | NetworkManager: nmcli or nmtui |
| Ubuntu | netplan: YAML files in /etc/netplan/, then sudo netplan try |
| Debian (servers) | /etc/network/interfaces (ifupdown), or systemd-networkd |
nmcli con show
sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.50/24 ipv4.gateway 192.168.1.1 ipv4.dns 1.1.1.1 ipv4.method manual
sudo nmcli con up "Wired connection 1"
netplan try applies a configuration and rolls it back automatically if you do not confirm within two minutes, which protects you from locking yourself out.
ifconfig equivalents
| Old | New |
|---|---|
ifconfig | ip a |
ifconfig eth0 up | ip link set eth0 up |
route -n | ip r |
arp -a | ip neigh |
netstat -tulpn | ss -tulpn (see ss) |
The BSDs, macOS, AIX and Solaris keep ifconfig and netstat (Solaris 11 also has ipadm and dladm). Basic troubleshooting order: ip a (do I have an address?), ip r (do I have a default route?), ping the gateway, then test DNS with dig.