In production environments, servers often require a fixed (static) IP address for reliable network access. Using Red Hat’s NetworkManager CLI (nmcli
), we can configure a static IPv4 address that persists across reboots. The following guide walks through identifying your network interface, setting a static IP, gateway, and DNS, and applying the changes with best practices in mind.
Step 1: Identify the Network Interface
First, determine the name of the network interface to configure. On RHEL, CentOS, or AlmaLinux, common interface names might be eth0
, ens33
, enp1s0
, etc. Use the commands below to list interfaces:
# List all network interfaces (active and inactive)
nmcli device status
# Alternatively, view all interfaces and addresses
ip addr
The nmcli device status
output will show device names and their state. Identify the interface you need to configure (e.g. ens33
or eth0
). You can also run nmcli connection show
to see existing connection profiles and confirm the interface’s connection name (often the same as the device name for Ethernet connections). For example:
NAME UUID TYPE DEVICE
ens33 12345678-90ab-cdef-1234-567890abcdef ethernet ens33
Best Practice: Make sure you have console access or are prepared for a brief network interruption when applying changes. If configuring remotely via SSH, a network restart can disconnect your session, so plan accordingly.
Step 2: Gather Network Configuration Details
Before making changes, collect the static network details for your server: the IPv4 address, subnet mask (or prefix length), default gateway, and DNS server(s). Ensure the chosen IP is not within a DHCP pool or used by another device to avoid conflicts. In a production environment, coordinate with your network administrator or consult documentation for the correct values. For example, you might decide on:
- IP Address: 192.168.1.100
- Subnet Mask (CIDR): 255.255.255.0 (which is
/24
in prefix notation) - Gateway: 192.168.1.1
- DNS Servers: 8.8.8.8 (and maybe a second one like 8.8.4.4)
Step 3: Set the Static IPv4 Address
Use nmcli
to assign the IP address and prefix to your interface’s connection. The syntax is:
nmcli con mod <connection_name> ipv4.addresses <IP_address>/<prefix>
For example, if your interface (and connection profile) is ens33
and you want to set IP 192.168.1.100 with a /24
subnet (255.255.255.0), run:
nmcli con mod ens33 ipv4.addresses 192.168.1.100/24
This command configures the static IP and network mask on the ens33
interface. (If your connection profile name is different (e.g. “System eth0” or “Wired Connection 1”), use that name or the interface’s UUID in place of ens33
.)
Step 4: Configure the Default Gateway
Next, set the default gateway (the router IP for your subnet) so the server knows where to send traffic destined for outside the local network. Use:
nmcli con mod ens33 ipv4.gateway 192.168.1.1
Replace 192.168.1.1
with your network’s gateway IP. The above command adds a persistent default route for the connection.
Step 5: Configure DNS Name Servers
Specify one or more DNS servers for name resolution. Using nmcli
, you can list multiple DNS IPs separated by commas or spaces. For example:
nmcli con mod ens33 ipv4.dns "8.8.8.8,8.8.4.4"
This sets Google’s DNS servers (8.8.8.8 and 8.8.4.4) as the resolvers for this connection. If you only have one DNS server, you can omit the comma and second address. This setting will update the system’s resolver configuration (e.g. /etc/resolv.conf
) when the connection is activated. (In our example we used quotes around the DNS list; quotes may be needed if using multiple entries or special characters.)
Step 6: Enable Static IP Mode (Disable DHCP)
By default, most servers initially use DHCP (ipv4.method auto
). We need to switch the IPv4 method to “manual” to enforce the static settings. Set the connection’s IPv4 method to manual with:
nmcli con mod ens33 ipv4.method manual
This tells NetworkManager to use the manual static configuration we provided (IP address, gateway, DNS) instead of trying to get an address via DHCP. At this point, the IP, gateway, DNS, and manual method are configured in the NetworkManager profile for ens33
, but the changes are not yet applied to the live network interface.
Step 7: Ensure the Configuration Persists (Autoconnect)
NetworkManager typically enables autoconnect by default for Ethernet profiles, which means the interface will come up on boot. However, it’s good practice to verify this is enabled for your connection. Run:
nmcli con mod ens33 connection.autoconnect yes
This ensures the interface will automatically activate at boot with the static configuration. Under the hood, connection.autoconnect yes
corresponds to having ONBOOT="yes"
in the ifcfg file, meaning the static network will start on boot without manual intervention. (If it was already “yes”, this command makes no harm; if it was “no”, it’s now enabled.)
Step 8: Apply the New Settings (Activate the Connection)
After modifying the connection profile, bring the connection up (or reactivate it) to apply the changes. Use the following command to restart the interface with the new static configuration:
nmcli con up ens33
If the interface was currently active (e.g. via DHCP), this will reactivate it with the new static settings. You should see a confirmation that the connection is successfully activated. For example:
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/...)
Bringing the connection up writes the changes to the system’s network config files. On RHEL-based systems, NetworkManager will save these settings to the appropriate ifcfg script (e.g. /etc/sysconfig/network-scripts/ifcfg-ens33
) for persistence. In our case, the file ifcfg-ens33
will now contain the static IPADDR
, PREFIX
(network mask), GATEWAY
, DNS
, and will have BOOTPROTO=none
(or static
) and ONBOOT=yes
to ensure it starts on reboot.
Note: Activating the new settings will temporarily disrupt network connectivity while the interface reconfigures. If you are applying this via SSH, your session may drop. It’s advisable to apply network changes during a maintenance window or via console access.
Step 9: Verify the Configuration
Finally, verify that the static network settings are correctly applied and working:
- Check IP and Interface Status: Run
ip addr show ens33
(replace ens33 with your interface) to confirm the new IP address and subnet are assigned. The IP should match what you set, and the interface state should be “UP”. For example, the output should showinet 192.168.1.100/24
on your interface. You can also usenmcli connection show ens33
to list the profile details and confirm the IPv4 config (IP, gateway, DNS) is as intended. - Check Routing: Use
ip route
orip route show
to ensure the default route (default via 192.168.1.1
in our example) is present. - Test Connectivity: Ping your gateway to verify local network connectivity:
ping -c 4 192.168.1.1
. Also try pinging an external IP (e.g.ping -c 4 8.8.8.8
) to confirm external reachability. - Test DNS Resolution: Try resolving a domain name (if DNS was set). For example:
ping -c 4 example.com
. If DNS is correctly configured, the name should resolve to an IP and ping succeed. - Persistence Check: Reboot the server (if possible) to ensure the network comes up with the static IP automatically. After reboot, run
ip addr
ornmcli dev status
to confirm the interface still has the static IP. Because the changes were saved to the ifcfg file, the static IP should persist across reboots.
If all checks out, your server is now configured with a persistent static IP. The configuration we applied via nmcli
is permanently stored (you can inspect /etc/sysconfig/network-scripts/ifcfg-<interface>
to see the settings), and NetworkManager will bring up the interface with this static IP on each boot. This approach follows best practices by using NetworkManager’s tooling to ensure consistency and manageability of network settings in production.
Leave a Comment
You must be logged in to post a comment.