Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have just set up a new Ubuntu server and I am going to be doing a lot of networking tests.

During setup, I simply skipped the network step.

I now need to switch between DHCP and an address quite often.

I know I can easily give a port an address via ifconfig eth0 x.x.x.x netmask x.x.x.x, but, is there an alternative that can be used in order to set a port to use DHCP?

If this isn't possible, I am guessing I can default in /etc/network/interfaces to dhcp and then just use up/down or restart networking in order to apply... but, I would much rather use ifconfig.

share|improve this question
@TheX - I am just using Ubuntu Server, I am not actually "serving" anything! I need to switch between DHCP on one network and plugging on to another network where there is no DHCP server and there is a completely different range. –  wilhil Apr 23 '12 at 14:02
@TheX - Sorry... This is for downloading data/tests from one network that does have DHCP enabled... and then switching over to another network where there isn't DHCP. –  wilhil Apr 23 '12 at 14:10
@TheX - I'm sorry, I am not sure if there is something you haven't understood... I know exactly that this is the case! This is why I want to have a static IP and DHCP, and switch between them! In Windows, when testing networks, I just right click on the connection and put in an IP configuration and to get back to DHCP, I just tick the automatically assign box... I just want the Linux variation of that. –  wilhil Apr 23 '12 at 20:41
Oh... I see.. so you are just looking for an easy way to toggle it... –  TheX Apr 23 '12 at 20:42
"TheX - Precisely! Sorry if I didn't explain, but, I didn't think it was that complicated! I can do this easily in GUI Linux which is very similar to Windows - I just can't figure out how to do it from the command line. –  wilhil Apr 23 '12 at 21:24

1 Answer 1

Change from static to dynamic

ifconfig eth0 && dhclient  

Change back

killall dhclient && ifconfig eth0
share|improve this answer
you might need an ip route add as well –  hbdgaf Apr 23 '12 at 14:08
Exactly what I need, thank you. But why to provide ? dhclient alone worked for me. –  3bdalla Mar 8 at 9:34
It's a habit. So you're saying "unassign whatever address I currently have, then ask for an address" instead of just "ask for an address" –  hbdgaf Mar 8 at 11:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.