单网卡设置双IP(ubuntu,debian)

# This file describes the network interfaces availableon your system
# and how to activate them. For more information, see interfaces(5).
#/etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.116
netmask 255.255.255.0
gateway 192.168.1.2

auto eth0:1
iface eth0:1 inet static
address 192.168.1.135
netmask 255.255.255.0
gateway 192.168.1.2

安装好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程序动态创建的,不要直接手动编辑,修改将被覆盖。

果不其然,修改后重启就失效了,搜索了Ubuntu下设置DNS的相关资料,总结出两个办法:

方法一 通过/etc/network/interfaces,在它的最后增加一句:

dns-nameservers 8.8.8.8

8.8.8.8是Google提供的DNS服务,这里只是举一个例子,你也可以改成电信运营商的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 8.8.8.8

方法二 通过修改:

/etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)

在里面插入:
nameserver 8.8.8.8
nameserver 8.8.4.4

如果有多个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 8.8.8.8
nameserver 8.8.4.4

可以看到我们的设置已经加上了,然后再ping一个域名,当时就可以解析了,无需重启。

附:CentOS下修改DNS则容易的多了,直接修改/etc/resolv.conf,内容是:
nameserver 8.8.8.8
nameserver 8.8.4.4

保存就生效了,重启也没问题。

原文链接http://blog.csdn.net/todd911/article/details/9251087

 

posted on 2017-10-20 14:41  三炮儿  阅读(684)  评论(0)    收藏  举报

导航