在ubuntu 12.04 lts服务器中使用静态IP的问题

我将服务器的ip从动态更改为静态。 用以下代码更改/ etc / network / interfaces中的文件后,我的服务器失去了与Internet的连接。

Here's my new network interfaces: auto eth0 iface eth0 inet static address 192.168.254.120 netmask 255.255.255.0 network 192.168.254.0 broadcast 192.168.254.255 gateway 192.168.254.1 

所以之后,我重启网络服务我的ip在ifconfig更改为192.168.254.120,但当我尝试ping任何网站或我的其他电脑,它不起作用。 我会把我原来的ifconfig信息放在这里,万一有人会问。

 ifconfig eth0 inet addr: 192.168.254.109 Bcast: 192.168.254.255 Mask: 255.255.255 

我希望有人可以帮助我将我的服务器更改为静态IP。 谢谢。

我建议使用以下/ etc / network / interfaces文件:

 auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.254.120 #assuming this address is outside the range used for DHCP in the router netmask 255.255.255.0 gateway 192.168.254.1 dns-nameservers 8.8.8.8 192.168.254.1 

现在让sytem读取并使用更改:

 sudo ifdown eth0 && sudo ifup eth0 

检查您是否可以上网:

 ping -c3 www.google.com