关于 Ubuntu 设置静态IP的问题


之前我安装也过Ubuntu server ,因为ubuntu server 没有图形界面,配置静态ip就必须使用vi编辑器来编辑/etc/network/interfaces文件实现,但是就是设置不成功,不知道是什么原因,网上的资料也查询了,都是一个设置方式。

通过不断的实验,终于配置成功,留下日志备查:

使用vi,输入命令(为了不输入sudo 我直接切换到root账户):

sudo su
vi /etc/network/interfaces
配置过后的文件内容为(红色标记为更改添加内容):
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
# iface eth0 inet dhcp
iface eth0 inet static
address 192.168.0.6
netmask 255.255.255.0
gateway 192.168.0.1

注意对比,配置完成之后,重启网络:

/etc/init.d/networking restart
如果不是root账户,记得加sudo哦

昨天设置了静态IP,今天再打开电脑的时候却发现服务器不能联网了,奇怪,后来想了想是不是我没有设置DNS的缘故,使用vi编辑器打开/etc/resolv.conf:

vi /etc/resolv.conf
添加DNS:

search mydomain.com
nameserver 61.139.39.73
nameserver 61.139.2.69

配置完成之后,重启网络:

/etc/init.d/networking restart
问题解决!

更多Ubuntu相关信息见Ubuntu 专题页面 http://www.bkjia.com/topicnews.aspx?tid=2

相关内容