Ubuntu – Problem with static ip in ubuntu 12.04 lts server

12.04networkingstatic-ip

I change my server's ip from dynamic to static. After I change the file in /etc/network/interfaces with the following code, my server lost connection to 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

So after, i restart the networking service my ip in ifconfig change to 192.168.254.120 but when i try to ping any site or my other pc, it doesnt work. I will put here my original ifconfig info just in case someone will ask.

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

I hope someone can help me change my server to static ip. Thanks.

Best Answer

I suggest the following /etc/network/interfaces file:

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

Now get the sytem to read and use the changes:

sudo ifdown eth0 && sudo ifup eth0

Check that you can reach the internet:

ping -c3 www.google.com
Related Question