linux修改dns方法:
方法一:
修改/etc(推荐)
[root@bin ~]# vi /etc nameserver 8.8.8.8 nameserver 8.8.4.4
修改后会立即生效,不需做任何额外处理!故,比较推荐此方法。
方法二:
修改 /etc/sysconfig/network-scripts/ifcfg-eth0文件
[root@bin ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp DNS2=8.8.4.4 TYPE=Ethernet DNS1=8.8.8.8 IPV6INIT=no USERCTL=no PEERDNS=yes
这种办法还要重启网卡才生效,重启网卡可以用以下命令:
service network restart
查看本机DNS的办法
1、查看/etc文件
[oboth@localhost ~]$ cat /etc nameserver 114.114.114.114 nameserver 8.8.8.8
2、使用nslookup命令查看DNS信息
[oboth@localhost ~]$ nslookup qq.com Server: 114.114.114.114 Address: 114.114.114.114#53 Name: qq.com Address: 123.151.137.18 Name: qq.com Address: 61.129.7.47 Name: qq.com Address: 183.3.226.35
3、使用dig命令来查看DNS信息
[oboth@localhost ~]$ dig ; <<>> DiG 9.11.25-RedHa <<>> ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27276 ;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;. IN NS ;; ANSWER SECTION: . 3359 IN NS l.roo. . 3359 IN NS j.roo. . 3359 IN NS g.roo. . 3359 IN NS a.roo. . 3359 IN NS i.roo. . 3359 IN NS f.roo. . 3359 IN NS k.roo. . 3359 IN NS h.roo. . 3359 IN NS e.roo. . 3359 IN NS b.roo. . 3359 IN NS d.roo. . 3359 IN NS m.roo. . 3359 IN NS c.roo. ;; Query time: 59 msec ;; SERVER: 114.114.114.114#53) ;; WHEN: 一 2月 01 18:02:15 CST 2021 ;; MSG SIZE rcvd: 239