Switching a server to static IP from DHCP
I am running an Ubuntu 10.04 server installation and I recently had to switch it from DHCP to static ip. I edited /etc/network/interfaces
file and switched
iface eth0 inet dhcp
to
iface eth0 inet static
address 192.168.1.167
netmask 255.255.255.240
network 192.168.1.160
broadcast 192.168.1.175
gateway 192.168.1.161
You'll notice the IPs are a little strange. This is because the sever is now on a special subnet dedicated to isolating specific servers. I also edited the resolv.conf file to include the proper DNS servers (including one of Google's just in case all hell broke lose).
The problem is that, seemingly randomly, the machine will lose the ability to talk to the outside world. I know the machine is still up, but it acts like it has no networking at all. I think part of the issue is that there is no DHCP running to this subnet (nor will there be) and the dhclient seems to still be running on occasion which causes some sort of conflict (no idea what) which causes networking to die. I cannot, however, remove the dhcp3-client package as it also causes the ubuntu-minimal package to be removed and that would be bad.
So, any ideas? What might be calling the dhclient and what can I do to stop it from running?
If you haven't rebooted the machine since, that behavior is normal. Changing from dhcp to static ip should be:
sudo ifdown eth0
- change the configuration
sudo ifup eth0
The reason is that if you do the ifdown after changing the configuration, it behaves as if it's taking down a static interface and doesn't kill the dhclient process that will keep just screwing up your configuration. In that case, just kill the dhclient process with
sudo killall dhclient
and it should all work out.
As mentioned by jneves, it is probably the DHCP client messing things up for you.
As an alternative to sudo ifdown eth0
-edit-sudo ifup eth0
, you can just run /etc/init.d/networking restart
after you edited the file. It also has the advantage, that you can do it remotely...
(Not having enough points on askubuntu, I am not allowed to just comment on jneves' answer, so please do consider this a comment...)
Edit: Completely forgot; as the above command doesn't disconnect you at any time, your SSH-session should actually survive the re-loading of the configuration. It is quite nice to be able to change the network settings while being connected to said machine...