# how do you release & renew IP addresses?



## keyizm (Sep 25, 2002)

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?


----------



## hazmat (Sep 25, 2002)

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.


----------



## keyizm (Sep 25, 2002)

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?


----------



## LordCoven (Sep 26, 2002)

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 

C


----------



## keyizm (Sep 26, 2002)

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 ...


----------



## LordCoven (Sep 26, 2002)

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 123.123.123.123 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,

C


----------



## keyizm (Sep 26, 2002)

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 ???


----------



## gatorparrots (Sep 26, 2002)

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.


----------



## LordCoven (Sep 29, 2002)

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 www.darwinfo.net - 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 )

Cheers,

C


----------



## keyizm (Oct 2, 2002)

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?


----------



## gatorparrots (Oct 2, 2002)

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
```


----------



## LordCoven (Oct 2, 2002)

... 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 ...

C


----------



## keyizm (Oct 4, 2002)

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!!!


----------



## LordCoven (Oct 4, 2002)

... I'm still running 10.1.5 ... could be that ifconfig behaves different between the two versions - I'll still have a look tho.

C


----------



## keyizm (Oct 4, 2002)

if you could 2x check on that for me, that'd be great?! how come you're still running 10.1.5?


----------



## LordCoven (Oct 4, 2002)

the boss won't let me  (But I'm working on it and she may let me buy it in the next few months ... )

C


----------



## keyizm (Oct 4, 2002)

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


----------



## LordCoven (Oct 4, 2002)

... 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 ))

C


----------



## LordCoven (Oct 5, 2002)

This sounds a lot more promising.
Try:

sudo ipconfig en1 DHCP

I got this from a web site where someone seemed to have a similar problem to yourself:
http://www.macwindows.com/MacOSX.html
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 

Cheers,

C


----------



## LordCoven (Oct 5, 2002)

ARGH! TYPE! That command should have read:

sudo ipconfig set en1 DHCP

Sorry!!! 

C


----------



## keyizm (Oct 5, 2002)

Lord Coven .. you are DA MAN?! it worked .. THANKS!!! actually .. what's interesting is if you leave off the "DHCP" at the end of the command, you'll get prompted back with the other flags you can utilize (see below):

[kyon@Keyizm kyon]$ sudo ipconfig set en1 
usage: set  <interface name> < BOOTP | MANUAL | DHCP | INFORM | NONE > <method args>

thanks again for you help


----------



## LordCoven (Oct 6, 2002)

n.p.  Just glad we got it sorted in the end   

C


----------



## stztech (Oct 3, 2013)

keyizm said:


> 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?



To do this, type in ifconfig in Terminal. You will get a bunch of interfaces available on the Mac device, and each interface will be marked as active or inactive. Determine which interface you want to do a release/renew on. Refer to screenshots

For this example, I will be working on my wifi interface, *en1*





While in Terminal, type the following command in to disable the interface. Keep in mind, you will have to have superuser permissions to do this. so make sure you type sudo before the command




When it asks for a password, type in your password, or the administrator password for your computer. 

Once this completes, your terminal session no longer requires you to type sudo for further commands. 

To enable it




Quit Terminal 

Hope this helps


----------

