20

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.

belacqua
  • 22,880
  • 23
  • 88
  • 108
wilhil
  • 1,785
  • 5
  • 20
  • 30
  • @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
  • 1
    @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
  • 1
    Oh... I see.. so you are just looking for an easy way to toggle it... – TheXed Apr 23 '12 at 20:42
  • 1
    "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 Answers1

39

Change from static to dynamic

ifconfig eth0 0.0.0.0 0.0.0.0 && dhclient  

Change back

killall dhclient && ifconfig eth0 10.0.1.22 netmask 255.255.255.0
RobotHumans
  • 29,190
  • 4
  • 76
  • 114