Technology Encyclopedia Home >How to configure network settings on CentOS?

How to configure network settings on CentOS?

Configuring network settings on CentOS involves editing network configuration files and restarting the network service. Here’s a step-by-step guide:

Step 1: Identify Network Interfaces

First, identify the network interfaces available on your system. You can do this by running:

ip link show

or

ifconfig -a

Step 2: Edit Network Configuration Files

Network settings are typically configured in the /etc/sysconfig/network-scripts/ directory. Each interface has a configuration file named ifcfg-<interface_name>. For example, for the interface eth0, the file would be /etc/sysconfig/network-scripts/ifcfg-eth0.

Open the file with a text editor:

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

Step 3: Configure Basic Settings

In the configuration file, you can set various parameters such as:

  • BOOTPROTO: Specifies how the IP address is obtained (e.g., static, dhcp).
  • IPADDR: The IP address of the interface.
  • NETMASK: The subnet mask.
  • GATEWAY: The default gateway.
  • DNS1 and DNS2: DNS server addresses.

Example configuration for a static IP:

DEVICE=eth0
BOOTPROTO=static
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

Step 4: Restart Network Service

After saving the configuration file, restart the network service to apply the changes:

sudo systemctl restart network

Step 5: Verify Configuration

Verify that the network settings have been applied correctly:

ip addr show eth0

or

ifconfig eth0

Example

Suppose you want to configure eth0 with a static IP address of 192.168.1.100, a subnet mask of 255.255.255.0, a gateway of 192.168.1.1, and DNS servers 8.8.8.8 and 8.8.4.4. You would edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file as shown in the example above and then restart the network service.

Cloud-Related Recommendation

If you are managing CentOS instances in a cloud environment, consider using Tencent Cloud’s Virtual Private Cloud (VPC) service. VPC allows you to create isolated virtual networks, configure subnets, and set up security groups to control inbound and outbound traffic to your instances. This provides a secure and flexible networking environment for your CentOS servers.