Configure Static IP Addresses Using NetworkManager on RHEL/CentOS

Learn to configure persistent static IP addresses on RHEL/CentOS using the powerful `nmcli` utility. This step-by-step guide covers identifying network interfaces, creating and modifying connection profiles, setting static IPs, gateways, and DNS servers, and activating the new configuration. Master essential `nmcli` commands for verification, troubleshooting, and best practices, equipping system administrators with the skills for reliable enterprise Linux networking.

38 views

Configure Static IP Addresses Using NetworkManager on RHEL/CentOS

Networking is a fundamental aspect of any server administration task. On Enterprise Linux distributions like Red Hat Enterprise Linux (RHEL) and CentOS, NetworkManager serves as a dynamic and comprehensive network configuration and management service. While DHCP (Dynamic Host Configuration Protocol) is convenient for dynamic IP assignments, many server environments require static IP addresses for predictability, reliability, and services like DNS, web servers, and databases that depend on consistent addressing.

This article will guide you step-by-step through the process of configuring persistent static IP addresses on RHEL and CentOS systems using the nmcli (NetworkManager Command Line Interface) utility. Mastering nmcli is an essential skill for any Linux system administrator, providing powerful and flexible control over your system's network settings without needing to directly edit configuration files.

Understanding NetworkManager and nmcli

Before diving into the configuration steps, let's clarify the core components we'll be using:

What is NetworkManager?

NetworkManager is a daemon that handles network settings, making it easier to manage network connections. It can manage various connection types, including Ethernet, Wi-Fi, mobile broadband, and VPNs. It automatically detects and configures network devices and attempts to maintain an active network connection, switching between available connections as needed. For servers, it ensures that your network interfaces are configured correctly and persist across reboots.

What is nmcli?

nmcli is the command-line client for NetworkManager. It allows you to control NetworkManager and configure network connections from the terminal. It's particularly useful in headless server environments where a graphical interface isn't available. nmcli commands are intuitive and provide a robust way to interact with NetworkManager's full range of features, from displaying network device status to creating and modifying complex connection profiles.

Prerequisites

To follow this guide, ensure you have:

  • Root Privileges: You'll need sudo access or to be logged in as the root user to make network configuration changes.
  • System Information: The static IP address, subnet mask (or CIDR notation), default gateway, and DNS server IP addresses you intend to use.
  • Identified Network Interface: Knowledge of the network interface name (e.g., enp0s3, eth0) you wish to configure. We'll cover how to find this.

Step-by-Step Configuration of a Static IP Address

Here’s how to configure a static IP address using nmcli.

Step 1: Identify Your Network Interface

First, you need to know the name of the network interface you want to configure. You can list all active network devices and their statuses using nmcli device or nmcli device status:

nmcli device status

Example Output:

DEVICE     TYPE      STATE                   CONNECTION
enp0s3     ethernet  connected               System enp0s3
lo         loopback  unmanaged               --

In this example, enp0s3 is our Ethernet interface. Make a note of your interface name.

Step 2: Create a New Network Connection Profile

It's generally a good practice to create a new connection profile for your static IP configuration, rather than modifying an existing DHCP-managed one directly, especially if you might want to revert easily. A connection profile stores all the settings for a specific network connection.

To create a new Ethernet connection profile, use the nmcli connection add command. You'll specify the connection type, a descriptive connection name (con-name), and the interface name (ifname).

sudo nmcli connection add type ethernet con-name my-static-eth ifname enp0s3
  • type ethernet: Specifies an Ethernet connection.
  • con-name my-static-eth: Assigns a name to this new connection profile. Choose something descriptive.
  • ifname enp0s3: Links this connection profile to the physical network interface enp0s3.

Alternative: Modifying an Existing Profile

If you prefer to modify an existing connection (e.g., System enp0s3 from the nmcli device status output), you would use nmcli connection modify with its existing con-name.

sudo nmcli connection modify "System enp0s3" # replace with your connection name

Note: For simplicity and clarity, this guide will assume you've created a new connection profile named my-static-eth.

Step 3: Configure IPv4 Settings (IP, Gateway, DNS)

Now, let's configure the static IP address, gateway, and DNS servers for our my-static-eth connection profile. It's crucial to set the IPv4 method to manual to disable DHCP.

Setting the IP Address and Gateway

Use the ipv4.addresses and ipv4.gateway properties. The IP address should be in CIDR notation (e.g., 192.168.1.100/24).

sudo nmcli connection modify my-static-eth ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1
  • ipv4.addresses 192.168.1.100/24: Sets the static IP address to 192.168.1.100 with a 24-bit subnet mask (255.255.255.0).
  • ipv4.gateway 192.168.1.1: Sets the default gateway for the network.

Setting DNS Servers

Specify one or more DNS server IP addresses. Separate multiple addresses with commas.

```bash
sudo nmcli connection modify my-static-eth ipv4.dns