码迷,mamicode.com
首页 > 系统相关 > 详细

Ubuntu修改DNS配置

时间:2018-06-25 18:52:19      阅读:411      评论:0      收藏:0      [点我收藏+]

标签:color   常用命令   常用   base   loop   and   eth0   author   rest   

  • 不要直接手动修改文件 /etc/resolv.conf

安装好Ubuntu之后设置了静态IP地址,再重启后就无法解析域名。想重新设置一下DNS,打开/etc/resolv.conf

cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

内容是一段警告:说这个文件是resolvconf程序动态创建的,不要直接手动编辑,修改将被覆盖。

root@Ubuntu14:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.138
nameserver 100.100.2.136
options timeout:2 attempts:3 rotate single-request-reopen
root@Ubuntu14:~#

ubuntu修改DNS有如下两种方法。

 

  • 方法一:修改文件/etc/resolvconf/resolv.conf.d/base
root@Ubuntu14:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.138
nameserver 100.100.2.136
options timeout:2 attempts:3 rotate single-request-reopen
root@Ubuntu14:~# vim /etc/resolvconf/resolv.conf.d/base
root@Ubuntu14:~# cat !$
cat /etc/resolvconf/resolv.conf.d/base
nameserver 223.5.5.5
nameserver 223.6.6.6
root@Ubuntu14:~# resolvconf -u
root@Ubuntu14:~# cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 100.100.2.138
nameserver 100.100.2.136
nameserver 223.5.5.5
options timeout:2 attempts:3 rotate single-request-reopen
root@Ubuntu14:~# nslookup www.baidu.com
Server:         100.100.2.138
Address:        100.100.2.138#53

Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 220.181.112.244
Name:   www.a.shifen.com
Address: 220.181.111.188

root@Ubuntu14:~#

 

  • 方法二:修改文件 /etc/network/interdaces
root@iZbp1b66g5htibj2m7yyv3Z:~# cat /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

dns-nameservers 223.5.5.5   # 在最后添加这一行

 

  • 常用命令

linux刷新dns的缓存方法是:  sudo /etc/init.d/nscd restart

最暴力的方法刷dns,重启网络:  sudo /etc/init.d/networking restart

 

查看当前DNS解析情况:

  nslookup www.baidu.com

  dig | grep SERVER

root@iZbp1b66g5htibj2m7yyv3Z:~# /etc/init.d/nscd restart
 * Restarting Name Service Cache Daemon nscd                                                                                                                                                                                          [ OK ]
root@iZbp1b66g5htibj2m7yyv3Z:~#  /etc/init.d/networking restart
stop: Job failed while stopping
start: Job is already running: networking
root@iZbp1b66g5htibj2m7yyv3Z:~# dig |grep SERVER
;; SERVER: 100.100.2.138#53(100.100.2.138)
root@iZbp1b66g5htibj2m7yyv3Z:~# nslookup www.baidu.com
Server:         100.100.2.138
Address:        100.100.2.138#53

Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 220.181.111.188
Name:   www.a.shifen.com
Address: 220.181.112.244

root@iZbp1b66g5htibj2m7yyv3Z:~#

 



  

Ubuntu修改DNS配置

标签:color   常用命令   常用   base   loop   and   eth0   author   rest   

原文地址:https://www.cnblogs.com/karl-python/p/9225484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!