How to set the IP address and host name of CentOS8

Overview </ h3>

It is essential to know how to configure the network connection after installing CentOS. There are two ways to configure the network, command line and GUI. You can modify the network specifications to configure static IPs and configure dynamic network interfaces. This explanation explains how to configure the network with the following contents using the command line and Network Manager TUI.   ① Configure static IP address (using command line) ② Configure dynamic (DHCP) IP address (using command line) ③ Configure static IP address (Network Manager TUI) ④ Configure dynamic IP address (Network Manager TUI) ⑤ Change the host name

① Configure static IP address (command line) ### 1. Search for network interface Execute the following command to check the list of PC interfaces.
# nmcli d

The list is displayed as shown below. I will explain how to change the network interface of one line.

[root@localhost centos]# nmcli d
DEVICE          TYPE      STATE     CONNECTION 
enp0s3 ethernet connected enp0s3
virbr0 bridge Connected virbr0
lo loopback no management--         
virbr0-nic tun no management--  

2. Check the Conf file of the network interface

Execute the following command and check the "network-scripts" directory.

# ls /etc/sysconfig/network-scripts/

You can confirm that the corresponding Conf file exists as shown below.

ifcfg-enp0s3 

3. Open the corresponding Conf file

Replace the corresponding device name with network_device_name and execute the following command.

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

4. Modify Conf file

Add and correct the following information and save it by overwriting. ・ Additional items </ font> </ b> IPADDR = Add static IP address NETMAK = Subnet mask GATEWAY = default gateway DNS1 = Preferred DNS server DNS2 = Alternate DNS server ・ Correction items </ font> </ b> BOOTPROTO = static * → static specification </ font> * ONBOOT = yes * → Specify to automatically turn on the network when the OS starts * </ font>

  • If "ONBOOT = no" is set, the network interface will be turned off when the OS is restarted.

5. Modify Conf file

TYPE=enp0s3
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static → fix
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=port1
UUID=b09ce0d7-6071-461d-b6fc-4ae261729d25
ONBOOT=yes → correction
IPADDR=Static IP address
NETMAK=sub-net mask(Settings for use) 
GETWAY=default gateway(Settings for use)
DNS1=Preferred DNS server(Settings for use)
DNS2=Alternate DNS server(Settings for use)

6. Network service restart

# systemctl restart network

To TOP </ font>

② Configure dynamic (DHCP) IP address (command line)

1. Search for network interface

Execute the following command to check the list of PC interfaces.

# nmcli d

The list is displayed as shown below. I will explain how to change the network interface of one line.

[root@localhost centos]# nmcli d
DEVICE          TYPE      STATE     CONNECTION 
enp0s3 ethernet connected enp0s3
virbr0 bridge Connected virbr0
lo loopback No management--         
virbr0-nic tun no management--  

2. Check the Conf file of the network interface

Execute the following command and check the "network-scripts" directory.

# ls /etc/sysconfig/network-scripts/

You can confirm that the corresponding Conf file exists as shown below.

ifcfg-enp0s3 

3. Open the corresponding Conf file

Replace the corresponding device name with network_device_name and execute the following command.

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

4. Modify Conf file

Add and correct the following information and save it by overwriting. ・ Additional items </ font> </ b> IPADDR = Add dynamic IP address NETMAK = Subnet mask GATEWAY = default gateway DNS1 = Preferred DNS server DNS2 = Alternate DNS server ・ Correction items </ font> </ b> BOOTPROTO = dhcp * → static specification </ font> * ONBOOT = yes * → Specify to automatically turn on the network when the OS starts * </ font>

  • If "ONBOOT = no" is set, the network interface will be turned off when the OS is started or restarted.

5. Modify Conf file

TYPE=enp0s3
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp → correction
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=port1
UUID=b09ce0d7-6071-461d-b6fc-4ae261729d25
ONBOOT=yes → correction
IPADDR=Dynamic IP address
NETMAK=sub-net mask(Settings for use) 
GETWAY=default gateway(Settings for use)
DNS1=Preferred DNS server(Settings for use)
DNS2=Alternate DNS server(Settings for use)

6. Restart the Network service

# systemctl restart network

To TOP </ font>

In ① and ②, I explained how to change the network interface settings using the command line, but in ③ and ④ below, open the network manager and change the settings via GUI. I will explain. </ font>

③ Configure static IP address (Network Manager TUI)

1. Open NetworkManager

Open NetworkManager by running the following command on the command line

# nmtui

The NetworkManager TUI will be displayed as shown below.

01.png

2. Select Edit Connection

3. Select the network to change

02.png

4. Change IP4 setting to "manual"

03.png

5. Press Display

04.png

6. Change the setting of the red frame

05.png

7. Press OK and return to exit with the main menu

To TOP </ font>

④ Configure dynamic IP address (Network Manager TUI)

1. Open NetworkManager

Open NetworkManager by running the following command on the command line

# nmtui

The NetworkManager TUI will be displayed as shown below.

01.png

2. Select Edit Connection

3. Select the network to change

02.png

4. Change IP4 setting to "automatic"

06.png

5. Press Display and check the following

07.png

6. Press OK and return to exit with the main menu

To TOP </ font>

⑤ Change the host name

1. Open NetworkManager

Open NetworkManager by running the following command on the command line

# nmtui

The NetworkManager TUI will be displayed as shown below.

08.png

2. Select Set system host name and change the host name

09.png

3. Press OK and return to exit with the main menu

that's all.

To TOP </ font>

Recommended Posts