DNS

来自Ubuntu中文
跳到导航跳到搜索

DNS解析

root@ubuntu:~# cat /etc/resolv.conf
nameserver 202.101.172.35
nameserver 202.101.172.47
domain domain
search domain

hosts

root@ubuntu:~# cat /etc/hosts
127.0.0.1       localhost
127.0.1.1       ubuntu.ubuntu-domain    ubuntu

192.168.0.251 web1.example.com web1

192.168.0.252 web2.example.com web2

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

用于本地解析域名,比前面那个优先级更高。

dhclient锁定DNS

通过DHCP获取IP

sudo dhclient 网卡名

同时会根据DHCP服务器的设定修改resolv.conf中的nameserver字段。

锁定resolv.conf中的域名解析服务器地址

root@ubuntu:/home/qii# nano /etc/dhcp3/dhclient.conf 

增加这两行

prepend domain-name-servers 8.8.8.8;

prepend domain-name-servers 8.8.4.4;
8.8.8.8
8.8.4.4

这是 Google 公共 DNS。

之后用dhcp配置网络信息时,该字段便会放到最前

root@ubuntu:/home/qii# cat /etc/resolv.conf 
nameserver 8.8.4.4
nameserver 8.8.8.8
nameserver 202.101.172.35
nameserver 202.101.172.47
domain domain
search domain