Methods of payment Abuse

Network Settings in CentOS: From Basic Commands to Troubleshooting Connectivity

  • Main
  • Knowledge base
  • Network Settings in CentOS: From Basic Commands to Troubleshooting Connectivity
Yesterday, 17:15

Network settings in CentOS are an important aspect of working with the operating system, especially for those setting up servers or configuring the system for internet use. Although the process is theoretically simple, practical difficulties often arise, especially for users not working in IT on a daily basis.

CentOS is focused on stability, security, and high performance, and is often used for servers and hosting, where long-term stability without frequent updates is required.

In 2020, the end of support for CentOS 8 was announced for 2021, with CentOS Stream replacing it as an intermediate version between RHEL and community updates. However, CentOS 7 continues to receive long-term support and is actively used in server solutions.

Checking Current Network Settings 

To begin, you can check the current network settings. Open a terminal and enter the following command:

ip a

This will display all active network interfaces and their statuses, including IP addresses. For additional information, use ip route to check routes and ip link for interface status. Pay attention to the lo (local) interface and eth0 or ens33 (for external connection).

Configuring Network Interface 

When changing the IP address or gateway, you need to update the network settings in CentOS. This is important when moving a server to a new network or between data centers. After changes, the IP address should be within the new range to connect to other devices in the network. Also, check the gateway, which directs traffic to the external network.

Changing Settings via CentOS Navigate to the directory with interface configurations:

cd /etc/sysconfig/network-scripts/

Find the configuration file for your network interface, such as ifcfg-eth0 or ifcfg-ens33:

ls ifcfg-*

Open the file for editing:

nano ifcfg-eth0

Make the necessary changes to the settings:

  • BOOTPROTO="static" — for a static IP address (use dhcp for dynamic). 

  • IPADDR — the new IP address of the device. 

  • NETMASK — subnet mask, typically 255.255.255.0. 

  • GATEWAY — the gateway address. 

  • DNS1 — primary DNS server, for example, 8.8.8.8.

Don’t forget to save the changes and restart the network:

systemctl restart network

Checking the Connection To check that the changes have been applied and the connection is working, use the command:

ping google.com

If you receive responses, the connection is established.

Troubleshooting Connection Issues 

  • No connection: Check the IP address and gateway to ensure they are correct. 

  • No internet despite correct settings: Try changing the DNS servers (e.g., to 8.8.8.8 or 1.1.1.1).

  • Gateway connection issues: Use the command ping 192.168.1.1 to check the connection to the gateway. If the ping fails, check the IP settings and network connection. 

  • Firewall issues: If the issue isn’t resolved by checking the IP, check the firewall using the command:

firewall-cmd --list-all

To open ports, use:

firewall-cmd --add-port=<port>/tcp

Using DHCP for Automatic Configuration If the router automatically assigns IP addresses, the configuration can be simplified. Change the BOOTPROTO parameter to dhcp and restart the interface.

Working with network parameters in CentOS may seem complex, but with attention to detail and care, this task is quite manageable.