ubuntu server修改IP和DNS

1.设置IP,
终端输入 sudo gedit /etc/network/interfaces
假设实用的是网卡0,如果是其它网卡就将eth0改为对应的值。
auto lo
iface lo inet loopback
#使用网卡0
auto eth0
#使用静态IP
iface eth0 inet static
#设置IP
address 172.32.1.11
#设置子网掩码,不要弄错了,可以自己算的,具体可能不一样的,由IP决定!
netmask 255.255.0.0
Dark补充:
network 202.104.123.16
网络起始地址
dns-nameservers 202.96.134.133 8.8.8.8 202.96.128.86
DNS server
dns-search sanshingit
参考【附录】
#设置网关
gateway 172.32.1.215


2.配置DNS
如果需要手动配置DNS
终端输入sudo  vi /etc/resolv.conf
在其中加入以下代码(202.96.134.133换为你的DNS)
nameserver 202.96.134.133     (深圳服务器是可以用百度到的,全深圳通用)


3.重启网络
sudo /etc/init.d/networking restart
提示ok之后可以试试能否ping到网关和局域网内的其它机器,然后再试试能否上


网!
配置后,遇到unknow host的解决办法(一般是写错DNS,最好查


看/etc/network/interfaces下和/etc/resolv.conf的DNS是否写错了)
http://www.2cto.com/os/201303/197708.html
 

【附录】

/etc/resolv.conf中关键字search和domain的作用

domain 声明主机的域名。很多程序用到它,如邮件系统;当为没有域名的主机进行DNS 查询时,也要用到。如果没有域名,主机名将被使用,删除所有在第一个点( . )前面的内容。
search 它的多个参数指明域名查询顺序。当要查询没有域名的主机,主机将在由search 声明的域中分别查找。domain 和search 不能共存;如果同时存在,后面出现的将会被使用。

下面的说明更清晰

在/etc/resolv.conf 配置文件:domain 和search作用是一样的

domain linpro.no
search linpro.no uio.no ifi.uio.no

domain function:

Had I typed telnet math.uio.no. with the trailing dot, the resolver would have known it was an FQDN and would have looked up math.uio.no at once, without trying to append the specified domain first. Not all applications are tolerant of the trailing dot, though, so it can't always be specified.

search function:

When ssh gram is executed, the resolver first looks for gram.linpro.no, which does not exist; then gram.uio.no, which does not exist, either; and finally gram.ifi.uio.no, which will succeed because it does exist

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值