Ubuntu下配置DNS

方法一: 通过/etc/network/interfaces,在它的最后增加一句(多个dns之间用空格分隔):

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
    address 192.168.201.100
    netmask 255.255.255.0
    gateway 192.168.201.254
    dns-nameservers 202.97.224.68 202.97.224.69

202.97.224.68是联通的DNS服务。

重启后DNS就生效了,这时候/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 202.97.224.68
nameserver 202.97.224.69

方法二 :通过修改 /etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)

sudo vi /etc/resolvconf/resolv.conf.d/base

在里面插入:

nameserver 202.97.224.68
nameserver 202.97.224.69

如果有多个DNS就一行一个
修改好保存,然后执行:

resolvconf -u

再看/etc/resolv.conf,最下面就多了2行:

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 202.97.224.68
nameserver 202.97.224.69

可以看到设置的多个DNS已经加上了。然后再ping一下百度,立即就可以解析了,无需重启。

当然也可以使用下面的命令行重启网络。

/etc/init.d/networking restart

以上本人在ubuntu 14.04 和 16.04 上均验证成功。

你可能感兴趣的:(ubuntu,ubuntu,linux,DNS)