DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串。
一台主机的dns服务器的好坏会直接影响我们上网的速度以及网站的访问,今天我们一起来看一下如何为Linux系统配置好用的公共DNS.
1. 查看服务器的DNS方法一,查看配置文件,输入命令cat /etc/resolv.conf,从结构中可以看到DNS是221.4.8.1,备用DNS是0.0.0.0
EC20 openLinux system
1 root@mdm9607-perf:/# cat /etc/resolv.conf 2 nameserver 221.4.8.1 3 nameserver 0.0.0.0 4 nameserver 221.4.8.1 5 nameserver 0.0.0.0 6 root@mdm9607-perf:/#
ubuntu system:
1 open_linux@quectel-sz-server:/etc/systemd/system$ cat /etc/resolv.conf 2 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) 3 # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN 4 nameserver 127.0.1.1 5 open_linux@quectel-sz-server:/etc/systemd/system$
2. 方法二,查看使用nslookup命令,输入命令:nslookup www.yahoo.com
EC20 OpenLinux system:
1 root@mdm9607-perf:/# nslookup www.yahoo.com 2 Server: 221.4.8.1 3 Address 1: 221.4.8.1 4 5 Name: www.yahoo.com 6 Address 1: 124.108.103.104 media-router-fp2.prod1.media.vip.tp2.yahoo.com 7 Address 2: 124.108.103.103 media-router-fp1.prod1.media.vip.tp2.yahoo.com 8 Address 3: 2406:2000:ec:815::4 media-router-fp2.prod1.media.vip.tp2.yahoo.com 9 Address 4: 2406:2000:ec:815::3 media-router-fp1.prod1.media.vip.tp2.yahoo.com
ubuntu system:
1 open_linux@quectel-sz-server:/etc/systemd/system$ nslookup www.yahoo.com 2 Server: 127.0.1.1 3 Address: 127.0.1.1#53 4 5 Non-authoritative answer: 6 www.yahoo.com canonical name = atsv2-fp-shed.wg1.b.yahoo.com. 7 Name: atsv2-fp-shed.wg1.b.yahoo.com 8 Address: 124.108.103.104 9 Name: atsv2-fp-shed.wg1.b.yahoo.com 10 Address: 124.108.103.103
3. 方法三:dig命令查看dig |grep SERVER
EC20 OpenLinux system:
1 root@mdm9607-perf:/# dig | grep SERVER 2 -sh: dig: not found
Ubuntu system:
1 open_linux@quectel-sz-server:/etc/systemd/system$ dig | grep SERVER 2 ;; SERVER: 127.0.1.1#53(127.0.1.1)
4方法四:ip route show
1 /usrdata # ip route show 2 default via 10.228.16.250 dev rmnet_data2 3 default via 10.226.190.201 dev rmnet_data0 4 10.51.131.200/29 dev rmnet_data1 proto kernel scope link src 10.51.131.204 5 10.226.190.192/28 dev rmnet_data0 scope link 6 10.228.16.248/30 dev rmnet_data2 proto kernel scope link src 10.228.16.249 7 192.168.225.0/24 dev bridge0 proto kernel scope link src 192.168.225.1
5. 修改DNS服务器配置,vim编辑配置文件/etc/solve.conf
6. 将IP地址改为你想要的DNS服务器的IP,如下方我改的是首选是x.x.x.x,备选是x.x.x.x,修改后保存并退出
7. 使用nslookup 命令检验是否配置成功:
8. hosts主机表文件
跟Windows系统一样,Linux系统也有主机表文件。同样可以通过设置主机表地址进行特定主机的解析,优先DNS服务器地址。配置文件,在/etc/hosts
ubuntu system:
1 open_linux@quectel-sz-server:/etc$ cat hosts 2 127.0.0.1 localhost 3 127.0.1.1 quectel-sz-server 4 5 # The following lines are desirable for IPv6 capable hosts 6 ::1 ip6-localhost ip6-loopback 7 fe00::0 ip6-localnet 8 ff00::0 ip6-mcastprefix 9 ff02::1 ip6-allnodes 10 ff02::2 ip6-allrouters
EC20 OpenLinux system:
1 root@mdm9607-perf:/# cat /etc/hosts 2 127.0.0.1 localhost.localdomain localhost 3 192.168.225.1 mobileap.qualcomm.com
9,总结:
Linux下设置DNS的位置主要是,
1). 系统默认DNS服务器地址设置。2). hosts文件指定
生效顺序是:
1 hosts文件 ---- 2 /etc/resolv.conf
注意:
-
Linux修改dns是不是更加的简单,只需要修改一下配置文件/etc/resolv.conf即可
-
修改好后需要重启电脑系统吗?答案是不需要的,配置好保存即生效