Switching a server to static IP from DHCP
Solution 1
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.
Solution 2
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...
Enekk
Updated on September 17, 2022Comments
-
Enekk over 1 year
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 switchediface 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?
-
aatdark over 13 yearsplease run
sudo dhcpclient eth0
and comment if the network was broken afterwards. And the last lines of/var/log/syslog
if possible -
aatdark over 13 yearsUPDATE You may try
sudo ifdown eth0
according to art.ubuntuforums.org/showthread.php?t=1419803 -
Riccardo Murri over 13 years@aatdark If you run
ps auxf | less
, you should be able to see a list of processes, organized in a tree-like structure. You can then see what process spwaneddhclient
(just go up the branch); for instance, on my PCdhclient
is a son of theNetworkManager
process.
-
-
Jorge Castro over 13 yearsIt's perfectly fine (and encouraged) for you to add your own answer with more information that builds on another! (Nice job linking to the prior answer too)
-
HorusKol about 12 yearsI was using
/etc/init.d/networking restart
(in 10.04 server) after editing the configuration file - the dhclient was still running. I had to manually kill the dhclient process (and then I did a reboot just to make sure that it wouldn't come back on after a restart)