Ubuntu下配置IP地址及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一下百度,立即就可以解析了,无需重启。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值