how do you release & renew IP addresses?

Not open for further replies.
does anyone know how to release & renew IP addresses from the terminal app? kinda like the unix (OS X) equivalent of windows "ipconfig /release" & "ipconfig /renew". i thought ifconfig was the command line utility to do it however, i just can't seem to find the right parameters to make it work? i'm tired of having to go to the Network System Preferences window to do the task. i usually have terminal open and i'd REALLY like to be able to do it from there. any ideas?


Rusher of Din
Maybe there is a way to do it, but I always just changed it in /etc/hosts and rebooted. For OS X, I guess you would need one of the NetInfo commands.
i've always opened up the Network System Preferences Panel, and then switched between static ip & dhcp hitting the apply button both times (i normally keep my machine on dhcp setting). this normally does the trick for me and in my opinion is quicker than editting the /etc/hosts file and rebooting. any other ideas?
Check out the OS X Locations functionality:

You can configure multiple network setups on your machine (default is Automatic) and then simply select one from the Apple Menu/Locations.

I have:

1) Home (Wired Ethernet + Airport Ethernet)
2) Home DSL (Wired DSL Connection)
3) Work 1 (a static IP address)
4) Work 2 (a DHCP derived IP address)

Works a treat. Get into work, plug in the ethernet cable, Apple Menu -> Locations -> Work, and hey presto, I'm on the work network. And vice versa the other way round :)

thanks for the input on configuring multiple network setups however this is for my home desktop that pretty much stays put in my room. the reason why i'm looking for a command line way to release & renew ip address is that my ISP leases out IPs on a weekly time scale. i usually don't turn off my machine and i just leave it on running all the time. it get's annoying when i return to my machine to find out the IP address has been revoked because it's run past it's leasing time and i have to run over to the Network System Preferences panel to renew my IP address. i almost always have an open terminal window and i'd REALLY like to be able to renew the IP information from their like you could on a wintel box typing in "ipconfig /release" followed by "ipconfig /renew". come on .. i KNOW someone out there knows how to do this ...
I believe ifconfig should do it. Remember that ifconfig is a tool to configure a network interface. You will usually have the en0 interface, which is the first ethernet card in your system. You will always have the lo0 interface, which is the loopback adaptor. And you may have a ppp0 interface which would be your dial-up (modem) interface.

In order to reconfigure the interface with a new ip address, you'll probably have to take it down
ifconfig en0 down

then give it a new ip address and bring it back up again
ifconfig en0 up

but definitely read up on the man pages there. I haven't played with this *too* much (I did once manage to manually configure my ethernet card on my linux box using ifconfig)

Perhaps some of the hard-core unix networking gurus could provide some more detailed infos??

Hope this is of some help,

thanks that was pretty insightfull. i've actually got wireless network running at home and my wireless airport card in my desktop pops up as en1 interface. i've tried the following:

prompt%> ifconfig en1 down
prompt%> ifconfig en1 up

however this resulted in no IP address being assigned when i broughth the interface back up. thanks to your insight, i know realize i have to assign it an address when i bring an interface up. but if this is the case, how do you tell it to grab an IP from a DHCP server (which in my case is the wireless router)? i've tried reading the man pages but i didn't make much head way there. i'm by no means a unix guru .. just a dabbler looking to have a little fun. any other ideas or suggestions ???
Your best bet is to set up locations in the GUI, then use the command line tool scselect to change locations. [DHCP, other]

Then you could have a script change locations to the other location and switch back to DHCP to obtain a new lease. This script could then be made into a crontab to run on a regular basis, or you could run it at will from the command line.
Hey there,

Been digging a bit. Here's something that *might* work:

ifconfig en1 down
ifconfig en1 -DHCP- up

this is an extrapolation of a description of the iftab file from - I tried that syntax on my machine and it *seemed* to work - but I didn't play about with it too much. Let me know what results you get :)

(PS: If it messes your interface configuration up all you have to do is switch from one location to the next to have the system configure the interface properly again - either with the apple menu or with the scselect command :))


LordCoven .. i just tried your suggestion of:

ifconfig en1 down
ifconfig en1 -DHCP- up

and i recieved the following message:

ifconfig: -DHCP-: bad value

do you have any other ideas on how to get this bad boy to work?
Use SystemStarter to restart your network interface. This should have the net effect of renewing your network interface and obtaining a new DHCP lease, without having to resort to changing locations and back.

sudo SystemStarter restart Network
... forgot to ask: which version of X are you running? I'm running 10.1.5 .... didn't get that error msg when I tried :( ... I'll have another dig l8r and let you know ...

LordCoven .. i'm running 10.2.1 and that's the error i recieved when i tried it. if you get a chance to take another look, that'd be GREAT!!!
awwweee come on. you could install that bad boy and she'd never know the difference?!?! well that is .. untill you started running iCal .. iChat .. started browsing windows network effortlessly hmmmmm ;)
... she handles all the finances, so she'd probably notice it at that price tag (don't get me wrong - I don't think its too much and will gladly pay the fee when I'm allowed to :)))

This sounds a lot more promising.

sudo ipconfig en1 DHCP

I got this from a web site where someone seemed to have a similar problem to yourself:
is think link there.

Haven't actually tried this myself, so plz let me know how it works for you :)))

I was trying to find a manual for conigd / ipconfig, but couldn't find one (but stumbled accross the site above) ... if anyone knows good manuals for either or both of those tools, I'd be much obliged to hear from you :)


Not open for further replies.