Releasing and Renewing a DHCP IP Address from the Command Line with ipconfig on Mac OS X

If you need to release and renew an IP address from the command line on a Mac, the ipconfig command can do it quickly. Bear in mind that for most OS X users, renewing an IP address from the Mac’s System Preferences is the best approach, as it is easy to use and just as effective; however, the Terminal approach has advantages for advanced users and can be run both over SSH and from single-user mode.

The basic syntax for renewing the DHCP lease from the command line with ipconfig is as follows:

sudo ipconfig set (DEVICEINTERFACE) DHCP

If you know the device interface (en0, en1, en2, etc.), simply run this command to release and then renew DHCP for that device. Let’s assume en0, the standard for modern Wi-Fi-only Macs.

sudo ipconfig set en0 DHCP

Once the command has run, you can check whether the IP has been set correctly by querying the DHCP packet with the same ipconfig command using “getpacket”, like this:

ipconfig getpacket en0

Assuming the previous “set” command was successful, getpacket will return the IP, DNS server, subnet mask, router/gateway assigned by the DHCP server and the lease time. If the DHCP information comes back empty, either the interface queried was wrong or DHCP was not renewed/assigned correctly.

Another, cruder option would be to run ipconfig for all the device interfaces available on the Mac by chaining the syntax together like this:

sudo ipconfig set en0 DHCP && sudo ipconfig set en1 DHCP

However, it is better to set DHCP for the specific interface.

If you don’t know the interface, the first step is to determine which hardware device interface on your computer is used for the specific network port you are using. For most modern Macs we are looking for Wi-Fi, which is typically en0, but many Mac users use Ethernet, an iPhone Personal Hotspot, a tethered Android phone or an external NIC, each of which may have a different device interface depending on the hardware. You can easily determine the device interface by running networksetup -listallhardwareports, like this:

networksetup -listallhardwareports

Scroll through the output to find the interface you want to set and renew DHCP for. Let’s say you are looking for “Wi-Fi”, which might look something like this:

Hardware Port: Wi-Fi
Device: en0
Ethernet Address: b1:3f:22:dd:ab:19

Next to “Device” you will find the interface, in this case “en0”, which is what you plug into the ipconfig command above.

Enjoy!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top