MacOS – Renew DHCP from the command line on a Mac

macosNetwork

Can I run command sudo ipconfig set en0 DHCP as a standard user which shouldn't prompt for administrative username and password?

Best Answer

sudo ipconfig set $if DHCP && echo OK

Where $if is your network interface. For example en0.

To find which interface you want to reset, you can see the output of ifconfig.

Or if you are lazy, you can just copy/paste this line, which will set $if to the interface which is used to access the Internet:

if=$(route -n get 0.0.0.0 2>/dev/null | awk '/interface: / {print $2}') && echo $if

So in the right order:

if=$(route -n get 0.0.0.0 2>/dev/null | awk '/interface: / {print $2}') && echo $if
sudo ipconfig set $if DHCP && echo OK