How to Configure CentOS and Rocky Linux Network Settings

⌘K
  1. Home
  2. Docs
  3. Security
  4. Operating System
  5. How to Configure CentOS and Rocky Linux Network Settings

Configuring network settings in CentOS and Rocky Linux is a crucial step in setting up a server or workstation. These steps ensure that the system can communicate over the network properly, whether for accessing the internet, other devices, or hosting services.

This guide outlines how to configure network settings manually or using graphical tools.

Prerequisites
  • A system running CentOS or Rocky Linux.
  • Root or sudo privileges to make system changes.
1. Identify Your Network Interfaces

To identify available network interfaces on your system, use the following command:

ip link show

This will list all network interfaces along with their status. Common interface names are eth0, ens33, or eno1.

2. Configure Network Settings Using nmtui
Steps:
  1. Run the nmtui command to launch the Text User Interface: sudo nmtui
  2. Select Edit a connection and press Enter.
  3. Choose the network interface you want to configure and press Enter.
  4. Update the settings:
    • Set the connection name.
    • Enable or disable Automatically connect.
    • For static IP:
      • Enter the IPv4 Configuration method as “Manual”.
      • Add the IP address, gateway, and DNS servers.
    • For dynamic IP:
      • Set IPv4 Configuration to “Automatic (DHCP)”.
  5. Save your changes and exit.
  6. Restart the connection: sudo systemctl restart NetworkManager
3. Configure Network Settings Using nmcli

The nmcli command-line utility provides a way to manage network configurations programmatically.

Example 1: Configure a Static IP Address
  1. Add a new connection or modify an existing one: sudo nmcli con add type ethernet con-name static-connection ifname eth0 ip4 192.168.1.100/24 gw4 192.168.1.1
  2. Specify DNS servers: sudo nmcli con mod static-connection ipv4.dns "8.8.8.8,8.8.4.4"
  3. Activate the connection: sudo nmcli con up static-connection
Example 2: Configure DHCP
  1. Set the connection to use DHCP: sudo nmcli con mod "System eth0" ipv4.method auto
  2. Bring the connection up: sudo nmcli con up "System eth0"
4. Configure Network Settings Using Configuration Files

Network configurations are stored in /etc/sysconfig/network-scripts/.

Example: Configure a Static IP
  1. Open the configuration file for the desired interface: sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
  2. Update the file with the following: DEVICE=eth0 BOOTPROTO=none ONBOOT=yes IPADDR=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=8.8.8.8 DNS2=8.8.4.4
  3. Restart the network service: sudo systemctl restart NetworkManager
Example: Configure DHCP
  1. Edit the configuration file: sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
  2. Ensure the file contains: DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes
  3. Restart the network service: sudo systemctl restart NetworkManager
5. Verify Network Configuration

After configuring the network, verify the settings using the following commands:

  • Check IP addresses: ip addr show
  • Test connectivity: ping -c 4 8.8.8.8
  • Check DNS resolution: ping -c 4 google.com
6. Troubleshooting Tips
  • Ensure the NetworkManager service is active: sudo systemctl status NetworkManager
  • Restart the NetworkManager service after changes: sudo systemctl restart NetworkManager
  • Check logs for errors: journalctl -u NetworkManager

By following these steps, you can effectively configure and manage network settings in CentOS and Rocky Linux.