Celeb Glow
updates | March 30, 2026

Is it possible to use Ifconfig to switch an interface to DHCP and if not, what is the best way?

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.

5

1 Answer

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
8

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy