A static IP address is essential for servers, network devices, and machines that require a consistent network identity. Unlike dynamic IP addresses assigned by DHCP (Dynamic Host Configuration Protocol), a static IP remains constant, ensuring uninterrupted access to services and remote connections.
In this article, we will explore how to configure a static IP address in Linux using different methods, covering multiple distributions such as Ubuntu, Debian, CentOS, and Arch Linux.
New Linux Kernel Version: What to Expect
Why Use a Static IP Address?
Before we dive into configuration, let’s discuss why setting a static IP is necessary:
✅ Server Configuration – Web, database, and mail servers require a fixed IP to be accessible.
✅ Remote Access – A static IP makes SSH, FTP, or RDP connections stable.
✅ Network Devices – Printers, NAS, and IoT devices function better with a static IP.
✅ Firewall and Port Forwarding – Many firewall rules and NAT settings depend on fixed IPs.
✅ Avoiding IP Conflicts – Prevents issues where a machine’s IP changes dynamically, disrupting connectivity.
Checking Current Network Configuration
Before setting a static IP, check the current network settings to gather information about:
- Active network interfaces
- Existing IP address
- Default gateway
- Subnet mask
1. Identifying Active Network Interface
Run the following command to list network interfaces:
ip a
or
ifconfig
Example output:
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic ens33
valid_lft 86399sec preferred_lft 86399sec
From this, we note:
- Interface name: ens33
- Current IP: 192.168.1.100
- Subnet: /24 (255.255.255.0)
- Broadcast: 192.168.1.255
2. Checking Default Gateway
ip route | grep default
or
route -n
Example output:
default via 192.168.1.1 dev ens33
This means the default gateway (router IP) is 192.168.1.1.
Setting a Static IP in Linux
1. Using Netplan (Ubuntu 18.04 & Later)
Ubuntu uses Netplan for network configuration.
Step 1: Edit the Netplan Configuration File
sudo nano /etc/netplan/01-netcfg.yaml
Example configuration:
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
addresses:
- 192.168.1.200/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Step 2: Apply Changes
sudo netplan apply
To verify:
ip a
2. Using /etc/network/interfaces
(Debian, Older Ubuntu Versions)
Debian and older Ubuntu versions use /etc/network/interfaces
for configuration.
Step 1: Open the Configuration File
sudo nano /etc/network/interfaces
Step 2: Add Static IP Configuration
Modify or add the following:
auto ens33
iface ens33 inet static
address 192.168.1.200
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
Step 3: Restart Network Service
sudo systemctl restart networking
To verify:
ip a
3. Using NetworkManager (CentOS, Fedora, RHEL, Ubuntu Desktop)
NetworkManager allows easy IP configuration using CLI or GUI.
Method 1: CLI (nmcli)
nmcli con show
Identify your connection name (e.g., “Wired connection 1”).
Set the static IP:
nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.200/24
nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1
nmcli con mod "Wired connection 1" ipv4.dns 8.8.8.8
nmcli con mod "Wired connection 1" ipv4.method manual
nmcli con up "Wired connection 1"
Method 2: Editing Network Scripts (RHEL, CentOS 7/6)
sudo nano /etc/sysconfig/network-scripts/ifcfg-ens33
Modify:
DEVICE=ens33
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.200
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
Save and restart the network:
sudo systemctl restart NetworkManager
4. Using systemd-networkd
(Arch Linux, Advanced Users)
Step 1: Enable systemd-networkd
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd
Step 2: Configure Static IP
Create a configuration file:
sudo nano /etc/systemd/network/20-static.network
Add the following:
[Match]
Name=ens33
[Network]
Address=192.168.1.200/24
Gateway=192.168.1.1
DNS=8.8.8.8
Step 3: Restart the Network
sudo systemctl restart systemd-networkd
Verify:
ip a
Troubleshooting Common Issues
🚨 Issue: No Internet After Setting Static IP
✅ Ensure the correct gateway is set.
✅ Restart the network service:
sudo systemctl restart NetworkManager
or
sudo systemctl restart networking
🚨 Issue: DNS Not Resolving
✅ Verify /etc/resolv.conf
contains:
nameserver 8.8.8.8
nameserver 8.8.4.4
🚨 Issue: Incorrect Network Interface Name
✅ Use ip a
to get the correct interface name.
✅ Update the configuration file accordingly.
Conclusion
Setting up a static IP address in Linux is crucial for stability, networking, and server management. Depending on your distribution, you can configure static IP via:
- Netplan (Ubuntu 18.04+)
/etc/network/interfaces
(Debian, Older Ubuntu)- NetworkManager (CentOS, Fedora, RHEL)
- Systemd-networkd (Arch Linux, advanced users)
By following this guide, you can ensure seamless connectivity and avoid network disruptions. 🚀