Skip links

How to Check Network Configuration in CentOS

View Categories

How to Check Network Configuration in CentOS

1 min read

In CentOS, you can check and verify the network configuration by examining the settings in the /etc/sysconfig/network-scripts/ifcfg-<interface> files. Each network interface has its own configuration file in this directory, typically named ifcfg-<interface>, where <interface> represents the name of the network interface. At CloudPap, the most likely interface name is enp1s0 (e.g., ifcfg-enp1s0 for the first Ethernet interface). Here are the specific steps to do this:

  1. Login to the VM: Login to the VM via SSH using the command below
$ ssh centos@IP_ADDRESS

2.Identify the Network Interface: First, identify the network interface that you want to check and verify. You can use the ifconfig or ip addr command to list all the network interfaces on your system and their names. For example:

   ifconfig

This command will display a list of network interfaces, such as enp1s0, eth0, or others. Note the name of the interface you want to inspect.

3.View the Interface Configuration File: Now, open the configuration file for the chosen network interface using a text editor such as vim.

   sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0

You will need root privileges to edit this file, hence the sudo command.

5.Review the Configuration File: The configuration file (ifcfg-enp1s0) contains various parameters for the network interface. Typical contents include:

   DEVICE=enp1s0
   BOOTPROTO=none
   ONBOOT=yes
   TYPE=Ethernet
   IPADDR=192.168.1.10
   NETMASK=255.255.255.0
   GATEWAY=192.168.1.1
   DNS1=8.8.8.8
  • DEVICE: Specifies the name of the network interface.
  • BOOTPROTO: Indicates the method of obtaining an IP address (e.g., dhcp for DHCP or static for a manually configured IP).
  • ONBOOT: Set to “yes” if the interface should be started during boot.
  • TYPE: Specifies the interface type (usually “Ethernet”).
  • IPADDR, NETMASK, GATEWAY: Define the IP address, subnet mask, and default gateway, respectively.
  • DNS1, DNS2: Specify DNS server IP addresses.

6.Verify the Configuration: Carefully review the settings in the configuration file to ensure they match your network requirements. Check for potential issues such as incorrect IP addresses, gateway settings, or DNS configurations.

7.Save and Exit: If you make any changes to the configuration file, save your modifications. In the nano or vi editor, you can typically save by pressing Ctrl + O, confirming the file name, and pressing Enter. To exit, press Ctrl + x.

8.Check Network Configuration: After reviewing and potentially modifying the configuration file, you can check the network configuration for the interface by using the ifconfig or ip addr command:

   ifconfig

This will display the current network interface settings. Verify that the information you see in the output matches the settings you have defined in the configuration file.

By following these steps, you can check and verify the network configuration for a specific network interface in CentOS. If there are any discrepancies or issues, you may need to make adjustments to the configuration file and restart the network service to apply the changes.