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
  • 23,540
wilhil
  • 1,795

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
  • 30,112