Hướng dẫn cấu hình Network trong Centos


How Network Interface Naming Works?

RHEL introduced its new naming convention for network interfaces in version RHEL 6. However, the feature was enabled by default only with version 7, which meant that eth0 and eth1 were no more.

The names are now defined by a group of factors (device type, adapter, port/ID, and so on).

Based on the device type, the network interface name can start with:

  • en – Ethernet interface
  • wl – Wlan interface
  • ww – Wwam interface
  • sl – Serial line IP (slip)

Configuring a Static IP

You can set up a static IP via command line by modifying the network script of the interface.

1. First, find the name of the network interface you want to change using the network manager command-line tool. Prompt the system to list all network devices, along with network details:

nmcli d

In our example, we will change the configuration for the first network.

2. To do so, open the network’s configuration file by typing the following:

vi /etc/sysconf ig/network-scripts/ifcfg-[network_device_name]

3. A text editor with the network configuration opens.

4. To set a static IP for your network, you need to change the BOOTPROTO line to have the value "static". Also, modify the ONBOOT option to "yes" to enable the network when starting the system.

5. Then, add the following information about your network under the already existing text:






The configuration file should be similar to the example below:

6. Save the file and exit the text editor, returning to the command line.

7. For these changes to take effect, you must restart the network with the command:

systemctl restart

Note: If you don’t have network details (such as the IP address, gateway, and so on), run the command nmcli dev show [network_device_name]. The output displays all the information it has on the network.

Configuring Network Interface for DHCP

You can configure a network for DHCP (Dynamic Host Configuration Protocol) via command line by changing the network configuration.

1. Instruct the system to list your network devices with the command:

nmcli d

Find the network you want to configure for DHCP and copy its name.

2. Then, open the appropriate configuration file. Use the following command and paste the device name at the end:

vi /etc/sysconf ig/network-scripts/ifcfg-[network_device_name]

3. A text editor with the network configuration opens.

4. The BOOTPROTO line should have the value "dhcp" and change the ONBOOT line to "yes" to enable the network. Also, add network details such as IPADDRNETMASKGATEWAY, and DNS.

5. Save the file and exit to return to the command line.

6. Finally, restart the network with:

systemctl restart

Validating Your Network Settings

Verify your network is now working with the new settings with the command:

ip a show [network_device_name]

The output will display interface information based on which you can verify if the changes are live.

How to Configure Network Settings on CentOS 7 Using GUI

To configure your CentOS network interface via GUI, you need to open the Network Manager and modify the configuration according to your needs.

1. Open the Network Manager by running the following command in the command line:


2. The command prompts the NetworkManager TUI window, which appears as in the image below. Select Edit a connection to view configuration settings.

Configure network settings on CentOS using Network Manager.

3. Next, choose the network you want to configure.

Choose network interface which you want to configure.

You can now edit the given connection.

Configuring a Static IP

If you want to set the connection to have a static IP address, you can modify the configuration with the Network Manager.

1. First, open the required connection settings. If you have followed the steps outlined in the section above, you should already have the Edit a connection window in front of you.

2. To set a static IP address for the IPv4 configuration, open the drop-down menu next to the name of the appropriate connection.

3. By default, it is set to Automatic. Change the settings to Manual.

Configure a static IP address using the Network Manager.

4. Then, select the Show option for the given network to add the necessary information.

Show network configuration for IPv4.

5. Now you can add information related to your connection. This includes the addressesgatewaysDNS servers, and search domains. You don’t have to fill out all the fields.

6. Finally, make sure to enable the option for requiring IPv4 addressing for this connection and automatic connection.

Set a static IP address using GUI.

7. Select OK and Back to return to the main menu.

Configuring Network for Using DHCP

1. To configure a network as DHCP (Dynamic Host Configuration Protocol), you need to set the IPv4 configuration settings to Automatic.

Configure network for using DHCP on CentOS via GUI.

2. Before you exit out of the Network Manager, make sure to enable automatic connection for the network interface.

Enable automatic connection for network interface.

3. Select OK to save the changes.

4. Then, exit out of the Network Manages by selecting Back and then Quit.

5. To enable the new configuration, you need to restart the service network by typing the following command in the terminal:

service network restart

Set a System Hostname

Post a Comment

Mới hơn Cũ hơn