How to solve the problem of loss after Centos modifies DNS restart or restart network service
This article mainly introduces "how to solve the loss after Centos modifies DNS restart or restart network service". In daily operation, I believe many people have doubts about how to solve the problem after Centos modified DNS restart or restart network service. Xiaobian consulted all kinds of information and sorted out simple and useful operation methods. I hope it will be helpful to answer "how to solve the loss after Centos modifies DNS restart or restart network service". Next, please follow the editor to study!
cause
When we search for centos configuration dns information, we often say that we configure "/ etc/resolv.conf" in this file. After we add nameserver to this file, we can ping the domain name, but after restarting centos or restarting the network service, we will not be able to ping, and the nameserver information configured in "/ etc/resolv.conf" will also be lost.
Deal with
We found the corresponding network card configuration file "/ etc/sysconfig/network-scripts/ifcfg-eth"
Here can be 0, 1, 2, and so on, representing the configuration files of different network cards.
For example, if the first network card on the system is eth0, its configuration file is / etc/sysconfig/network-scripts/ifcfg-eth0.
Vim / etc/sysconfig/network-scripts/ifcfg-eth0
After opening it, insert the following 3 items
Peerdns=no
Dns1=192.168.1.1
Dns2=192.168.1.2
Then: wq save
Then let's review "/ etc/resolv.conf"
Cat / etc/resolv.conf
It is found that the dns information we modified in ifcfg-eth0 can be seen in resolv.conf, which is why the column, because resolve.conf is just a link file.
And then let's take a look at the effect.
Ping www.baidu.com
Then we restart the network service
Service network restart
And then we're under ping.
Found that there was no problem.
And then we reboot the system.
Reboot
At this point, the study on "how to solve the loss after Centos modifies DNS restart or restart network service" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!