To configure network interfaces in RHEL 8.6, you must create or modify ifcfg files within the /etc/sysconfig/network-scripts/ directory and then restart the NetworkManager service. This process ensures that static IP addresses, DNS settings, and interface states are applied correctly to the system.
Understanding the ifcfg File Structure
The ifcfg files are plain text configuration files used by the NetworkManager daemon in Red Hat Enterprise Linux (RHEL) 8.6. Each network interface typically has its own file, named according to the interface name, such as
ifcfg-eth0 or
ifcfg-enp0s3. These files reside in the
/etc/sysconfig/network-scripts/ directory. Understanding the key parameters is crucial for successful configuration. The most important fields include
NAME, which identifies the connection;
DEVICE, which specifies the physical interface;
TYPE, which defines the connection type (usually Ethernet);
ONBOOT, which determines if the interface comes up at boot; and
BOOTPROTO, which sets whether the IP is obtained via DHCP or is static.
Creating a New ifcfg File
When setting up a new network interface or adding a secondary IP configuration, you may need to create a new ifcfg file. It is best practice to copy an existing template to ensure all necessary defaults are present. For example, if you have an active interface like
enp0s3, you can use it as a base.
- Navigate to the network scripts directory:
cd /etc/sysconfig/network-scripts/.
- Copy an existing configuration file to a new one with your desired interface name:
cp ifcfg-enp0s3 ifcfg-enp0s8.
- Edit the new file using a text editor such as
vi or nano: vi ifcfg-enp0s8.
Inside the new file, update the following parameters to match your specific requirements:
- NAME: Set this to the device name, e.g.,
NAME=enp0s8.
- DEVICE: Ensure this matches the actual hardware interface, e.g.,
DEVICE=enp0s8.
- ONBOOT: Set to
yes if you want the interface to activate on boot.
- BOOTPROTO: Change to
none for a static IP configuration.
- IPADDR: Specify the desired static IP address.
- NETMASK or PREFIX: Define the subnet mask, e.g.,
PREFIX=24.
- GATEWAY: If required, specify the default gateway.
- DNS1: Add primary DNS server information.
After making these changes, save and close the file. This creates a valid configuration profile for NetworkManager to recognize.
Overwriting Existing Configuration
Sometimes, you need to overwrite an existing ifcfg file to change the network behavior of an active interface. Directly editing the file while NetworkManager is running can lead to inconsistencies. Therefore, it is safer to deactivate the connection before modifying the file, although NetworkManager will reload configurations upon service restart.
To overwrite an existing file, open the target file in your preferred editor. For instance, to modify the primary interface:
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
Update the relevant fields. If switching from DHCP to Static, ensure
BOOTPROTO is set to
none and add the
IPADDR and
PREFIX lines. If you are removing a static IP and reverting to DHCP, remove the
IPADDR,
PREFIX, and
GATEWAY lines, and set
BOOTPROTO=dhcp. Be careful not to delete essential lines like
DEVICE or
NAME, as this may cause NetworkManager to fail to identify the interface properly.
For more complex scenarios involving multiple IPs on virtual machines, refer to our guide on
Configuring Virtual Machine Network with Multiple IPs on Linux Server. This resource details how to handle additional addressing schemes that might require extra ifcfg files or alias configurations.
Applying Changes and Verification
Once the ifcfg file is created or overwritten, the changes do not take effect immediately. You must restart the NetworkManager service to apply the new configuration. Use the following command:
sudo systemctl restart NetworkManager
Alternatively, you can bring the specific interface down and up again using
nmtui or
nmcli commands, but restarting the service ensures all profiles are reloaded cleanly.
To verify that the configuration was applied correctly, check the status of the interface. Use
ip addr show enp0s3 to see the assigned IP address. Additionally, check the NetworkManager logs for any errors during the restart:
journalctl -u NetworkManager --since "5 minutes ago"
If the interface fails to come up, ensure that the
ONBOOT=yes parameter is set and that there are no syntax errors in the ifcfg file. Common issues include missing equals signs or incorrect spacing around values.
Troubleshooting Common Issues
If the network configuration does not apply after restarting NetworkManager, consider the following steps:
- Check File Permissions: Ensure the ifcfg file is readable by root. Typically, permissions should be
644.
- Validate Syntax: Use
nmcli c show to list all connections and verify that your new or modified connection appears without errors.
- Conflict Resolution: Ensure no other service, such as systemd-networkd, is managing the same interface, which could conflict with NetworkManager.
For servers where network connectivity is critical, always test changes in a maintenance window. Unexpected network drops can occur if the wrong gateway or DNS settings are applied. In cases where you need to manage service shutdown orders to prevent network loss during reboots, see
Preserve Order of Closing Services While Shutting Down Linux.
Frequently Asked Questions
Where are ifcfg files stored in RHEL 8.6?
They are located in the
/etc/sysconfig/network-scripts/ directory. This path is standard for RHEL-based distributions using NetworkManager with legacy ifcfg files.
How do I switch from DHCP to a static IP?
Edit the ifcfg file to set
BOOTPROTO=none, add
IPADDR,
PREFIX, and optionally
GATEWAY and
DNS1, then restart NetworkManager.
What happens if I make a typo in an ifcfg file?
NetworkManager will likely fail to activate the connection, leaving the interface down. Check the journal logs for specific error messages indicating syntax issues.
Can I use nmcli instead of editing ifcfg files directly?
Yes,
nmcli is the recommended modern tool for managing connections. Editing ifcfg files manually is still supported but requires careful handling to avoid corruption.
How do I verify my new IP address is active?
Use the
ip addr show command followed by the interface name to display current IP assignments and confirm they match your configuration.