Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
    
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
add comment

2 Answers 2

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.

share|improve this answer
1  
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
1  
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.