There are two quick ways to configure an IP address on the network interface of CentOS 8 operating system. The one is using the command nmtui and another is by direct editing of network files.
If you are not comfortable editing configuration files, choose option 1 to configure networks interactively.
Method 1 – Using nmtui tool
Run the following command to access an interactive form of network interface configuration.
sudo nmtui
Now, edit the default existing connection. In case there is no connection available, use Activate a connection.
You will see the list of Ethernet interfaces, select the interface you want to configure, then select Edit option on the right side of the interface.
Keep the profile name and device name unchanged. Set the IP address, gateway and DNS servers to the IPv4 configuration option. You can add multiple addresses using the selection option just below the IP address box.
Save the configuration and restart the NetworkManager service using the following command.
sudo systemctl restart NetworkManager.service
Method 2 – Using configuration files
The default network interfaces configuration file exists in the directory /etc/sysconfig/network-scripts/. The file name may vary depending on the type of installation, such as Physical Machine or Virtual Machine. The configuration file shoul be like ifcfg-XXXX (for example: ifcfg-eth0, ifcfg-eth1, ifcfg-enp0s3 etc.)
sudo vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
Use the following configuration to configure a static IP address for the CentOS 8 network interface.
Static IP configuration:
TYPE=Ethernet BOOTPROTO=static NAME=enp0s3 DEVICE=enp0s3 ONBOOT=yes IPADDR=192.168.1.237 PREFIX=24 GATEWAY=192.168.1.2 DNS1=8.8.8.8 DNS2=192.168.1.2 USRCTL=no
Alternatively, if you want to assign the IP address through the DHCP server, use the following settings.
DHCP Configuration
TYPE = Ethernet DEVICE = enp0s3 BOOTPROTO = dhcp ONBOOT = yes
Configuration parameter details:
- DEVICE: Ethernet device name
- BOOTPROTO: dhcp or static
- ONBOOT: yes/no, indicates whether the interface will be turned on automatically or not at boot.
- Guy: Interface type.
- USRCTL: Yes/no, indicates that a non-root user can upload or download this device.
Save the configuration and restart the NetworkManager service using the following command.
sudo systemctl restart NetworkManager.service
That's it.