Configuring a Static IP Address on Linux
Dedicated servers typically have a static IP configured by default. This guide covers how to set or change it manually.
Ubuntu 20.04+ (Netplan)
ls /etc/netplan/
nano /etc/netplan/00-installer-config.yaml
network:
version: 2
ethernets:
eth0:
addresses:
- 203.0.113.10/24
gateway4: 203.0.113.1
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8
netplan apply
Debian (interfaces file)
nano /etc/network/interfaces
auto eth0
iface eth0 inet static
address 203.0.113.10
netmask 255.255.255.0
gateway 203.0.113.1
dns-nameservers 1.1.1.1 8.8.8.8
systemctl restart networking
CentOS/AlmaLinux (nmcli)
nmcli con mod eth0 ipv4.addresses 203.0.113.10/24
nmcli con mod eth0 ipv4.gateway 203.0.113.1
nmcli con mod eth0 ipv4.dns "1.1.1.1 8.8.8.8"
nmcli con mod eth0 ipv4.method manual
nmcli con up eth0
Verify the Configuration
ip addr show eth0
ping -c 3 8.8.8.8
Add a Secondary IP Address
# Temporary (lost on reboot):
ip addr add 203.0.113.11/24 dev eth0
# Permanent (add to Netplan under addresses):
addresses:
- 203.0.113.10/24
- 203.0.113.11/24