设置linux固定IP地址

因为虚拟机操作系统是 linux ubuntu server 14.04 amd64 位命令行界面的,操作不方便,经常是启动系统后,通过远程ssh链接上去操作,这样可以方便的使用鼠标和浏览网页等。

但是vmware虚拟机里面的ip是使用dhcp自动获取IP的,所以每次启动都会变更IP地址,比较麻烦。

现在,我们来将虚拟机的IP地址设置为固定的。

我使用的是vmware play,所以没有nat的高级设置。所以使用“桥接(bridged)”上网,这样,就可以使用的我路由器的IP地址段了。

注意:每个路由器的IP地址段有可能不一样,有的是192.168.0.1。有的是192.168.1.1,目前发现大部分路由器的ip地址是 1.1的。呵呵。大家自己看吧,不知道就看本地连接里面的“详细信息” 就可以了。

因为我的是192.168.0.1的ip段

在虚拟机里面执行:

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
# hjb@2014-11-17
iface eth0 inet dhcp

这里的 iface eth0 inet dhcp 表示使用dhcp动态获取IP地址。

我们修改成以下:

# 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
# hjb@2014-11-17
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.0.110
gateway 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255

就可以使用静态ip地址登录了,以后,启动虚拟机也会固定的使用这个IP地址,有多个虚拟机的化,address 后面的ip地址要稍微变一下,以免启动多个虚拟机时冲突。

另外,还需要重启下网络才可以,重启网络使用一下命令:

service networking restart

注:本来使用这个命令应该是没有错的,但是我使用了,发现不行。所以重启了下虚拟机。

重启后,可以用:

ifconfig

查看下是不是ip地址是不是正确。

好了,今天就说这个,有点啰嗦,呵呵,只是希望新手也可以看得明白。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

你需要开启你的javascript才可以哦!