+5 votes
829 views
How to configure IP, DNS and DHCP in CentOS 8

in Linux / Unix by (552k points)
reopened | 829 views

1 Answer

+3 votes
Best answer

1. How to identify the CentOS 8 network adapter
2. How to set IP address, DNS and static gateway in CentOS 8
3. How to configure the network from CentOS Network Manager 8

One of the main actions we carry out when we use a computer is to connect it to the network . In this way we can surf the internet and make for example downloads or access our email, which without this connection would not be possible. There are several network elements that are essential for connectivity to be as ideal and correct as possible and these are:

IP
It is the Internet Protocol address which makes the computer or server can connect to the network and be recognized by the other elements of the system.

DNS
Domain Name System which is a domain name system that allows you to translate IP addresses into web domain names

DHCP
Dynamic Host Configuration Protocol which is a protocol in charge of providing IP addresses to the network equipment

In addition to this, the IP addresses of the device can be fixed or dynamic (DHCP). When the device has a dynamic address it will change frequently, but there are certain devices in which the address cannot be modified, in this case the objective is to assign a fixed IP..

TechnoWikis will explain the process of configuring IP, DNS and DHCP in CentOS 8 to manage network parameters much more centrally.


1. How to identify the CentOS 8 network adapter

Step 1

To know the ID of the network adapter, we must access the directory etc / sysconfig / network-scripts / and there list the elements:
 cd etc / sysconfig / network-scripts / ls -lah 
image

In this case we can see that our adapter is identified as "ifcfg-enp0s3". If there are more network adapters, they will be identified with the ifcfg-ensxxx syntax..

This is the file to edit to process the network configuration and define it as necessary.

Step 2

To edit the necessary network settings, we will use some text editor and take the adapter ID, in this case it will be the following:
 nano / etc / sysconfig / network-scripts / ifcfg-enp0s3 
When accessing this file we find all the network details such as:
  • Kind
  • Adapter name
  • Boot type
  • Device Type and more
image
Step 3

There we must add the line at the beginning of the file referencing the MAC address of the device, to know it we must execute the following:
 ip to 
image
Step 4

As we see, in our adapter is the MAC address in the link / ether line, those 6 pairs of alphanumeric characters are entered in the previous file with the following syntax:
 HWADDR = ”00: 00: 00: 00: 00: 00 ″ 
image

This process allows us to use an IP address in DHCP mode, that is, dynamically.
We save the changes using the Ctrl + O keys and exit the editor using the Ctrl + X keys..

Step 5

For the changes to take effect we can turn off the system by running:
 shutdown -r now 
Or, if we don't want to restart the computer, just restart the network service with the following command:
 systemctl restart network.service 
Step 5

Now, after this, we can check the IP address, DNS and other parameters by executing "ifconfig": image

2. How to set IP address, DNS and static gateway in CentOS 8


As we have mentioned, in some cases it is required that the device has a static IP address due to process or task issues, so in TechnoWikis you will learn how to assign a static IP address to your CentOS 8 server.
Step 1

For this case we must access again the configuration file of the network adapter:
 nano / etc / sysconfig / network-scripts / ifcfg-enp0s3 
There we will add the following lines:
It is edited from dhcp to static
 BOOTPROTO = ”static” 

It is the desired IP address for the server
 IPADDR = 192.168.0.38 

Subnet mask
 NETMASK = 255.255.255.0 

Gateway
 GATEWAY = 192.168.0.1 

This value is set to Yes so that it is enabled when the device is started up.
 ONBOOT = ”yes” 

Primary DNS server
 DNS1 = 8.8.8.8 

Secondary DNS server
 DNS2 = 8.8.4.4 
image
Note
In this case we have used Google’s public DNS, but you can use whatever you want.

We save the changes with the Ctrl + O keys and exit the editor with the Ctrl + X keys.

Step 2

We proceed to restart the computer to apply the changes:
 systemctl restart network 
To verify that the changes have been implemented by running the following:
 ip as enp0s3 
image
Step 3

We check the routing:
 ip r 
image
Step 4

We can run a ping to validate connection to the external network: image

3. How to configure the network from CentOS Network Manager 8


This is a method that makes use of the nmtui command which is a TUI application to interact with NetworkManager and with which it will be possible to edit various aspects of the network.
Step 1

For its use we execute the following:
 nmtui edit enp0s3 
image
Step 2

Pressing Enter we will see the following: image

There by default we can see the ID of the network adapter which is configured by DHCP (Automatic), if we wanted to set the IP manually we must use the Tab key to select the line “IPv4 Configuration and there press Enter to select the option“ Manual":

image
Step 3

We enter and now select the Show field: image
Step 4

There we select each field and press Enter to enter the necessary IP values: image
Step 5

We use the Tab key to go to Accept and apply the changes to verify that the desired IP has been set: image

With any of these methods we will be able to assign the type of IP, as well as the DNS or Gateway in CentOS 8.


by (3.5m points)
edited

Related questions

+4 votes
1 answer
asked Aug 31, 2020 in Linux / Unix by backtothefuture (552k points) | 948 views
+3 votes
1 answer
+5 votes
1 answer
+5 votes
1 answer
+4 votes
1 answer
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users