How to configure DNS resolution for linux server?

This article is based on three ways to configure DNS server for Linux machine when DNS server has been built.

An IP address is a digital address that identifies a site on the network. In order to facilitate memory, a domain name is used to replace the IP address to identify the site address. DNS (domain name resolution) is the process of converting domain names to IP addresses.

There are three ways to configure the location of the DNS resolution server in Linux. After the configuration is completed, it can be resolved automatically.

Local hosts

Modify the local hosts file and use hosts to automatically resolve the domain name to ip. This method is also applicable to windows, but the location of windows isC:\WINDOWS\system32\drivers\etc\hosts

$ vim /etc/hosts
123.123.123.123 www.baidu.com
124.123.123.123 www.qq.com

System default DNS configuration

Modify the configuration file to /etc/resolv.conf
add multiple rules such as:

$ vim /etc/resolv.conf
nameserver 114.114.114.114
nameserver 123.123.123.123

Network card configuration file

Assuming our network card is named eth0, then we can modify /etc/sysconfig/network-scripts/ifcfg-eth0the content of the configuration file and add dns rules

$ vim /etc/sysconfig/network-scripts/ifcfg-eth0
添加规则 例如:
DSN1=114.114.114.114
DNS2=xxx.xxx.xxx.xxx
DNS3=xxx.xxx.xxx.xxx

Restart the network service:

$ service network restart

As long as /etc/sysconfig/network-scripts/ifcfg-eth0DNS is configured

After restarting the service, the /etc/resolv.confsame DNS will be automatically generated

Priority of system analysis

Local HOST> Network Card Configuration> System Default DNS Configuration


Guess you like

Origin blog.51cto.com/15076235/2608333