您的位置:首页 > 其它

VMWare虚拟机下为Ubuntu 12.04.1配置静态IP(NAT方式)

2013-04-02 16:15 471 查看
Ubuntu 12.04.1中设置静态IP

1. 启动虚拟机Ubuntu系统,打开终端,利用如下命令打开并编辑网络接口配置文件:

sudo vi /etc/network/interfaces

2. 编辑文件如下:

auto lo
iface lo inet loopback

# Assgin static IP by eric on 26-SEP-2012
iface eth0 inet static
address 192.168.91.200 #change to your static IP
netmask 255.255.255.0  #change to your netmask
gateway 192.168.91.2    #change to your getway
#We must specify dns-nameserver here
#in order to get internet access from host
dns-nameservers 192.168.91.2
auto eth0

说明

address是你要分配给你虚拟机的静态IP地址,可以从刚才我们找到的可用的子网IP范围中随便选择一个放在此处。

netmask是子网掩码

gateway是网关

注意:在相对较早的版本中,你需要设置/etc下的resolv.conf文件,并加入nameserver,这样才可以连接互联网。但在Ubuntu 12.04之后,已经不推荐这种方式了,因为无论你想该配置文件中设置什么值,重新启动之后都会被还原为初始状态。推荐的做法是直接在interfaces配置文件中加入dns-nameserver <网关IP>这一行。

3. 重启ubuntu的网卡

sudo /etc/init.d/networking restart

4. ping测试互联网连通性

ping www.linuxidc.com

如果ping有响应,那么恭喜你,你已经成功将虚拟机设置为静态IP,并且也已连入互联网。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: