keepcalculator

06 Numbers and Powers

Configure Network Interface in RHEL CentOS

Card No. 06·85677 · Updated · Standard formula, shown below

To configure a network interface in RHEL or CentOS, you edit the interface configuration files in /etc/sysconfig/network-scripts/ or use the NetworkManager command-line tools (nmcli) and then restart the network service. This article covers both the classic static configuration method and the modern NetworkManager approach, including common pitfalls and verification steps.

Background: How RHEL/CentOS Handles Networking

Red Hat Enterprise Linux and its community rebuild CentOS use a layered networking stack. At the bottom are kernel drivers and the hardware device; above that, the ip tool and NetworkManager daemon manage the actual addresses and routes. Historically, RHEL 6 and earlier relied on the network service and plain text files. RHEL 7 and 8 introduced NetworkManager as the default, but kept the same configuration file format for compatibility. RHEL 9 continues with NetworkManager and adds the nmcli and nmtui utilities as the primary interfaces.

The key files are:

  • /etc/sysconfig/network-scripts/ifcfg-<interface> – per-interface settings
  • /etc/sysconfig/network – global hostname and gateway settings (legacy)
  • /etc/resolv.conf – DNS servers (usually managed by NetworkManager)

You can identify your interface names with ip link or nmcli device status. Typical names are eth0, ens33, or enp0s3 depending on the hardware and firmware.

How Network Configuration Works

When the system boots, the network service or NetworkManager reads the ifcfg files. Each file defines whether the interface uses DHCP or a static IP, the netmask, gateway, and DNS. The kernel then assigns the address and adds routes. If you change a file, you must restart the service or reload the connection for the change to take effect.

For a static configuration, the essential directives are:

  • DEVICE=eth0 – the interface name
  • BOOTPROTO=none – disables DHCP
  • ONBOOT=yes – brings the interface up at boot
  • IPADDR=192.168.1.100 – the IPv4 address
  • NETMASK=255.255.255.0 – the subnet mask
  • GATEWAY=192.168.1.1 – the default gateway
  • DNS1=8.8.8.8 – primary DNS server

For DHCP, you only need BOOTPROTO=dhcp and ONBOOT=yes. The system will obtain an address, netmask, gateway, and DNS automatically.

Step-by-Step: Static IP Configuration

  1. Open the interface file with a text editor: vi /etc/sysconfig/network-scripts/ifcfg-eth0
  2. Set the directives as shown above. Make sure BOOTPROTO=none (or static) and ONBOOT=yes.
  3. Save the file and exit.
  4. Restart the network service: systemctl restart network (RHEL 7/8) or nmcli connection reload then nmcli connection up eth0 (RHEL 8/9).
  5. Verify with ip addr show eth0 and ping -c 4 8.8.8.8.

If you use NetworkManager, the recommended way is nmcli:

nmcli connection modify eth0 ipv4.addresses 192.168.1.100/24
nmcli connection modify eth0 ipv4.gateway 192.168.1.1
nmcli connection modify eth0 ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection modify eth0 ipv4.method manual
nmcli connection up eth0

This updates the ifcfg file automatically and applies the changes immediately.

Choosing Between Static and DHCP

Use DHCP when the machine is a desktop or a VM that gets its address from a router or a server. It reduces configuration errors and is fine for most clients. Use a static IP for servers that need a predictable address: web servers, database servers, or any service that other machines connect to by IP. Static configuration also avoids the risk of the address changing after a lease expires.

For servers, you might also set NM_CONTROLLED=no in the ifcfg file to make the network service manage the interface directly, bypassing NetworkManager. This is common in older RHEL 6/7 environments, but RHEL 8/9 defaults to NetworkManager and you should keep it unless you have a specific reason.

Common Problems and Troubleshooting

The most frequent issue is that the interface doesn’t come up after a reboot. Check that ONBOOT=yes is set. Another common mistake is a typo in the netmask or gateway, which results in no connectivity. Always verify with ip route to see the default route.

If you edited the file but the change doesn’t take effect, the service may have cached the old configuration. Restart the service or use nmcli connection reload. For NetworkManager, also check nmcli device status to see if the device is managed; if it shows “unmanaged”, set NM_CONTROLLED=yes in the ifcfg file.

DNS issues are also common. If you can ping an IP but not a hostname, check /etc/resolv.conf. NetworkManager overwrites this file based on the DNS settings in the connection. If you set DNS manually in the ifcfg file, make sure the connection is reloaded.

Comparison: ifcfg Files vs. nmcli

The classic ifcfg method is straightforward and works on all RHEL/CentOS versions. It is scriptable and easy to copy between machines. The downside is that you must know the exact syntax and remember to restart the service. nmcli is more modern, provides immediate feedback, and integrates with NetworkManager’s connection profiles. It also supports advanced features like bonding, bridging, and VLANs more cleanly.

For a single server, either works. For automation (Ansible, kickstart), the ifcfg files are more common in older environments, but nmcli is the standard in RHEL 8/9. If you are new to RHEL, start with nmcli because it is the future direction.

Safety and Best Practices

Before making changes, back up the current configuration: cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak. If you are working on a remote server, make sure you have console access or a second network path, because a wrong network configuration can lock you out. Test with ping and ssh from another machine before closing your current session.

Use a static IP outside the DHCP range to avoid conflicts. For production servers, document the IP assignments in a central inventory. Also consider setting IPV6INIT=no if you don’t need IPv6, to reduce complexity.

Frequently Asked Questions

How do I find my network interface name?

Run ip link or nmcli device status. The output lists all interfaces with their names and states. The active one usually has an IP address assigned.

Why doesn’t my static IP work after reboot?

Most likely ONBOOT=yes is missing or the interface is not managed by NetworkManager. Check the ifcfg file and the NM_CONTROLLED setting. Also verify that the gateway is reachable.

Can I use both DHCP and a static IP?

Yes, you can set BOOTPROTO=dhcp and also specify IPADDR as a fallback, but this is rarely needed. Better to use DHCP only or static only.

What is the difference between RHEL 7 and RHEL 8 network configuration?

RHEL 7 still uses the network service by default, though NetworkManager is installed. RHEL 8 and 9 use NetworkManager exclusively, and the network service is deprecated. The ifcfg files are still read, but nmcli is the recommended tool.

How do I set a hostname?

Use hostnamectl set-hostname server.example.com. This updates /etc/hostname and takes effect immediately. The hostname is not part of the interface configuration.

Is it safe to edit /etc/resolv.conf manually?

NetworkManager overwrites it when the connection is reloaded. If you need persistent DNS, set it in the ifcfg file or via nmcli. Manual edits are temporary.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →