In the realm of network administration, dynamic DNS (DHCP) is convenient for general connectivity, but static IP addresses are essential for server accessibility, remote administration, and service discovery. Whether you are setting up a web server, an internal file share, or a self-hosted application, assigning a fixed IP ensures that your services remain reachable at the same location within your network topology. This guide provides accurate, step-by-step instructions for configuring static IP addresses on the three most popular enterprise Linux distributions: Ubuntu/Debian (using Netplan) and RHEL/CentOS/Fedora (using NetworkManager or traditional network-scripts).
Before diving into configuration steps, it is crucial to understand the prerequisites. You must know your desired IP address, subnet mask, gateway, and DNS servers. These values are typically obtained from your router’s DHCP lease information or your upstream ISP. A common mistake administrators make is attempting to assign a static IP without checking if that address is already in use by another device, which can cause network conflicts. Additionally, always verify your current network status using ip addr or ifconfig before making changes to ensure you are targeting the correct interface, such as eth0 or ens33.
Understanding the Distinction Between Dynamic and Static Assignments
To configure a static IP effectively, one must first understand how the system currently obtains its address. On modern Linux systems, the default behavior is often to receive an address via DHCP (Dynamic Host Configuration Protocol). This works well for client devices like laptops and phones but introduces instability for servers. A dynamic IP can change every time the server reboots or loses network connectivity, breaking persistent connections from clients.
Conversely, a static IP assignment locks the interface to a specific address defined in the configuration file or database. This provides predictability. However, it does not mean the system cannot renew other settings like DNS or gateway information; those are simply hardcoded into the network stack. It is also important to note that if your organization uses DHCP reservations (where a MAC address is permanently bound to an IP), you do not need to configure a static IP manually on the OS itself, as the DHCP server will always hand out the same address. In such cases, manual configuration might actually break connectivity by overriding the reservation with a conflicting setting.
Configuring Static IPs on Ubuntu and Debian Using Netplan
Ubuntu 18.04 and later versions, as well as modern Debian systems, utilize Netplan as the default network management tool. Netplan stores configurations in YAML files located at /etc/netplan/. These files are human-readable but require strict syntax adherence, particularly regarding indentation. Spaces must be consistent, and tabs are not allowed.
To begin, identify your network interface name using ip addr show. Common names include eth0, ens33, or enp0s31f1. Next, create a new configuration file or edit the existing one (e.g., /etc/netplan/00-installer-config.yaml). The structure typically looks like this:
network:
version: 2
ethernets:
ens33:
dhcp4: no
addresses:
- 192.168.1.50/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
In this example, dhcp4: no disables automatic IP acquisition for the specified interface. The addresses line defines the static IP and the prefix length (subnet mask). The gateway4 sets the default router, and nameservers configures DNS resolution. After saving the file, apply the changes with sudo netplan apply. If an error occurs, Netplan will report the specific syntax issue, which is a frequent troubleshooting step for beginners. Always ensure you are not editing the wrong interface; applying settings to eth0 when your active card is ens33 will leave your server offline.
Managing Static IPs on RHEL, CentOS, and Fedora with NetworkManager
Red Hat Enterprise Linux (RHEL), CentOS Stream, and Fedora often rely on NetworkManager for network configuration, though legacy systems may still use the older /etc/sysconfig/network-scripts/ approach. For modern versions (RHEL 8/9, Fedora 34+), the recommended method involves using nmcli, the command-line interface for NetworkManager.
First, check the current connection status with nmcli device status. Identify the device name and the connection UUID or name associated with your primary network card. To set a static IP, you can use the following command sequence:
sudo nmcli con mod "System eth0" ipv4.method manual
sudo nmcli con mod "System eth0" ipv4.addresses "192.168.1.50/24"
sudo nmcli con mod "System eth0" ipv4.gateway "192.168.1.1"
sudo nmcli con mod "System eth0" ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli con up "System eth0"
Replace "System eth0" with the actual connection name found in your system. The ipv4.method manual command is critical; without it, NetworkManager will ignore the address settings and revert to DHCP upon reboot. A common pitfall here is forgetting to run the final up command, which activates the new profile immediately. If you are on an older RHEL version using network-scripts, you would instead edit /etc/sysconfig/network-scripts/ifcfg-ens33, ensuring that BOOTPROTO is set to static and ONBOOT is yes.
Verifying Configuration and Troubleshooting Common Errors
Once the configuration files are saved and commands executed, verification is a mandatory step. Use ip addr show to confirm that your server now holds the static IP address you defined. If the output still shows an IP from your router (e.g., 192.168.1.x), the changes have not applied correctly.
Common errors include syntax mistakes in YAML files (extra spaces or tabs) and typos in interface names. Another frequent issue is DNS resolution failing immediately after setting a static IP. If you can ping an IP address like 8.8.8.8 but cannot resolve google.com, the issue lies with your nameservers entry in the configuration file. Ensure that the DNS IPs are reachable and correctly formatted (no trailing spaces).
It is also wise to test connectivity from a different machine on the network to ensure port forwarding or firewall rules are not blocking access to your new static IP. Remember that changing your IP address may invalidate existing SSH sessions if you are logged in remotely; plan to perform these changes during a maintenance window when possible. Always keep a backup of your working DHCP configuration before switching to static, so you can revert quickly if the network becomes unreachable.
Real-World Example: Hardening a Web Server Environment
Consider a scenario where an organization hosts a public-facing website on Ubuntu 22.04. The administrator needs to ensure the server always responds at 192.168.1.50 regardless of reboots. The admin checks /etc/netplan/, edits the YAML file to disable DHCP and hardcode the IP, gateway, and DNS. After applying Netplan, they verify the connection via curl from a client machine.
In a RHEL environment hosting a database server, the DBA configures NetworkManager to use a static IP to ensure consistent replication paths with other nodes in the cluster. The admin documents the MAC address and assigned IP in their internal inventory spreadsheet to prevent future conflicts. This dual-distribution approach highlights that while the commands differ slightly between Ubuntu/Debian and RHEL/Fedora, the logical flow remains identical: identify, configure, apply, and verify.
Conclusion and Best Practices Checklist
Configuring a static IP address is a fundamental skill for any Linux system administrator. By following the specific paths for Netplan on Debian-based systems and NetworkManager on Red Hat-based systems, you can ensure stable network connectivity. Always remember to validate your syntax, backup existing configurations, and test connectivity thoroughly before closing your terminal session.
Quick Checklist:
1. Identify the active network interface name (ip addr).
2. Determine the desired IP, subnet, gateway, and DNS from your router or ISP.
3. Choose the correct configuration method (Netplan for Ubuntu/Debian, NetworkManager for RHEL).
4. Edit the config file or run nmcli commands carefully.
5. Apply changes (netplan apply or nmcli con up).
6. Verify the new IP with ip addr.
7. Test DNS resolution and external connectivity.
By adhering to these steps, you eliminate the unpredictability of dynamic addressing and establish a robust foundation for your server infrastructure.



