1

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.

Ff Vote
  • 143
  • 1
  • 4
  • 9

1 Answers1

6

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
chili555
  • 58,968
  • 8
  • 93
  • 129
  • it's still the same, cant get to ping google. i look at my router dhcp config, and found out that the ip pool range is from 192.168.254.100 - 192.168.254.254 – Ff Vote Jul 31 '13 at 00:41
  • Well, pretty clearly, the address you picked is inside the DHCP range, no? I suggest you change to 192.168.254.50 and try again, this time with: sudo ifdown eth0 && sudo ifup -v eth0. The -v is for verbose; it may give some diagnostic clues. Also post: ifconfig. – chili555 Jul 31 '13 at 00:53
  • i change to 192.168.254.50, then do the sudo ifdown eth0 && sudo ifup -v eth0. then the ip in ifconfig change to 192.168.254.50, bcast to 192.168.254.255 and mask to 255.255.255.0 but when i ping to google.com it said that "From 192.168.254.50 icmp_seq=1 Destination Host Unreachable". – Ff Vote Jul 31 '13 at 01:59
  • If you change all to DHCP: auto eth0; iface eth0 inet dhcp; does it get an IP address normally? If so, let us see: ifconfig and also route -n. May I assume Network Manager is not installed and running? – chili555 Jul 31 '13 at 11:51
  • when i change it back to normal dhcp, i got a normal ip, here is my ifconfig. address 192.168.254.110, bcast 192.168.254.255 and mask 255.255.255.0. my route -n, in the first line, destination 0.0.0.0 gateway 192.168.254.254 gemask 0.0.0.0 flags UG metric 100 ref 0 use 0 iface eth0, on the second line destination 192.168.254.0 gateway 0.0.0.0 genmask 255.255.255.0 flags U metric 0 ref 0 iface eth0 – Ff Vote Jul 31 '13 at 23:35
  • It appears from route -n that your gateway is not 192.168.254.1 but instead 192.168.254.254. Please make that change in /etc/network/interfaces and then try again: sudo ifdown eth0 && sudo ifup eth0 followed by: ping -c3 www.google.com – chili555 Aug 01 '13 at 01:16
  • thx, it was working now, i have just a few question, what is dns-nameservers 8.8.8.8 192.168.254.254 means and do i need to add broadcast or network to my interfaces? thx – Ff Vote Aug 01 '13 at 03:17
  • DNS nameservers are needed to convert names, www.google.com, for example to numbers; in this case 74.125.134.99. The internet works on numbers, not names. Using DHCP, the router supplies DNS nameserver numbers. If you use static IP addresses, you must specify them. 8.8.8.8 is Googles DNS namserver. The other is your router. Glad it's working. – chili555 Aug 01 '13 at 11:52