19

From the Terminal, how can I release and renew my DHCP lease?

Currently, I'm doing the following for the wireless interface, but I'm wondering if there's a better way:

sudo ifconfig en1 down
sudo ifconfig en1 up

For the wired interface, replace en1 with en0.

  • Are you waiting for someone to say, no - there is no better way or can we address your question / edit it so it's likely to get a different answer than ue ipconfig/ifconfig? – bmike Dec 26 '12 at 15:41
28

This can also be achieved with the following two commands :

sudo ipconfig set en0 BOOTP
sudo ipconfig set en0 DHCP

You can alias the two together in your bash profile:

alias renew="sudo ipconfig set en0 BOOTP && sudo ipconfig set en0 DHCP"

So then you just have one command called renew that will release and renew your DHCP.

| improve this answer | |
  • 2
    Rob's answer will certainly work - but ipconfig set always first de-configures the interface before setting up DHCP again. I've never needed the first command - and ipconfig is much more high level (it handles routes better) than ifconfig and I prefer it for the case you state. – bmike Jul 14 '11 at 3:21
  • 4
    The cli command "ipconfig set en0 DHCP" is not a dhcp-renew in the pure sense but a complete discover,offer,request,ack procedure. The "renew" button on the control pane just generates a dhcp-request (preceded by a release) and is answered by an ACK. There is a difference between both as renew is typically sent by a cpe at half the lease time to renew to lease before it expires. Internet access-devices like a cable modem termination system will react differently on both procedure. So I'm still looking for a pure dhcp-renew command – user37314 Dec 26 '12 at 14:03
  • @robzolkos Above command run perfectly fine for the Admin account but when I logged in as a standard user in MAC It prompts for password. If possible how I could skip this password part and a standard user can run this command. – Jyotish Singh Aug 10 '17 at 8:46
9

The way the renew button works in System Preferences is to create a key in the system configuration. One can create the key via:

echo "add State:/Network/Interface/en0/RefreshConfiguration temporary" | sudo scutil

Swapping en0 for the desired interface.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .