Tested on: Ubuntu 24.04 LTS, Debian 12
ip (package iproute2) replaces the old ifconfig and route commands. Changes made with ip are temporary — they are lost after a reboot. To make them permanent, see Make settings persistent below.
ip -br link # Interfaces and their state (UP/DOWN)
ip -br addr # Interfaces with IP addresses
ip addr show dev enp4s0 # Full details for one interface
ip route # Routing table
Always specify the prefix length. Without it the address is added as /32.
sudo ip addr add 192.168.88.5/24 dev enp4s0 # Add an address
sudo ip addr del 192.168.88.5/24 dev enp4s0 # Remove an address
sudo ip addr flush dev enp4s0 # Remove all addresses from the interface
sudo ip link set enp4s0 up
sudo ip link set enp4s0 down
Do not disable the interface you are connected through over SSH — the session will drop.
sudo ip route add default via 192.168.88.1 # Default gateway
sudo ip route replace default via 192.168.88.254 # Change the gateway
sudo ip route add 10.0.0.0/8 via 192.168.88.254 # Route to a specific network
sudo ip route del 10.0.0.0/8
Check which system manages the network on your server:
/etc/netplan/ contains files → netplan (Ubuntu)
/etc/network/interfaces contains your interfaces → ifupdown (Debian servers)
Desktops usually use NetworkManager (nmcli)
Ubuntu (netplan)
If the file is 50-cloud-init.yaml, cloud-init may overwrite it on reboot. Disable cloud-init network management first:
echo 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Edit the file in /etc/netplan/, e.g. /etc/netplan/50-cloud-init.yaml:
network:
version: 2
ethernets:
enp4s0:
dhcp4: false
addresses:
- 192.168.88.5/24
routes:
- to: default
via: 192.168.88.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]
sudo chmod 600 /etc/netplan/*.yaml # netplan warns if the files are readable by others
sudo netplan try # Applies and rolls back after 120 s unless you confirm
netplan try is the safe way to change the network on a remote server: if you lose access, the old settings return automatically. Use sudo netplan apply when you are sure.
Debian (ifupdown)
Edit /etc/network/interfaces:
auto enp4s0
iface enp4s0 inet static
address 192.168.88.5/24
gateway 192.168.88.1
sudo nohup sh -c 'ifdown enp4s0; ifup enp4s0' >/dev/null 2>&1 &
On a remote server a mistake here cuts off access — have console access (KVM, provider's web console) ready.
ip -br addr show dev enp4s0 # The new address is present
ip route | grep default # The default gateway is set
ping -c 3 192.168.88.1 # The gateway is reachable
resolvectl status # DNS servers in use (Ubuntu)