UNIX - How do you do a IP release/renew?

Murpheeee

Diamond Member
Apr 30, 2000
3,326
0
76
I am looking for a way to relese/renew an IP Address in Mac OS-X

It has to be something which can be run by clicking a shortcut on the desktop.

I figured som kind of UNIX code to run in Terminal might be easiest.....

Anyone help me out?
 

bersl2

Golden Member
Aug 2, 2004
1,617
0
0
DHCP on the client side is usually handled either by dhcpcd or dhclient.

But if this is a Mac, there's definitely a widget or two that controls this.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
I don't know how closely OSX adheres to linux commands, but I think you can release/renew with the "ifconfig" command. Try "ifconfig --help" or "man ifconfig" for more info.
 

doan

Golden Member
Dec 17, 2000
1,445
0
76
Not sure about Mac, but here's the linux way:

ifdown eth0
ifup eth0
 

fartbag

Member
Jul 8, 2005
80
0
0
How bout /etc/init.d/network stop
/etc/init.d/network start

in a shell script?

I'm not a Mac guy but if Unix is in there somewhere that should work.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
I found the syntax for the release:

ifconfig interface dhcp release

and for the renew:

ifconfig interface dhcp extend

interface would be the name of your network interface, usually eth0 on linux
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Brazen
I found the syntax for the release:

ifconfig interface dhcp release

and for the renew:

ifconfig interface dhcp extend

interface would be the name of your network interface, usually eth0 on linux

That doesn't work on OS X. eth0 only means stuff in Linux. It's en? in Mac OS X.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: fartbag
How bout /etc/init.d/network stop
/etc/init.d/network start

in a shell script?

I'm not a Mac guy but if Unix is in there somewhere that should work.

I think you're thinking of Linux and I guess SysV Unixes.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
man ipconfig

Maybe something like:
Apple Mac OS X (by command line):

* get an administrator password for the computer
* open a Terminal command window
* type the commands
o sudo ipconfig set en0 BOOTP
o sudo ipconfig set en0 DHCP
* enter the administrator password when asked to
* close the Terminal window
 

JDCentral

Senior member
Jul 14, 2004
372
0
0
To be honest, I think you'll introduce more problems if you have them double-click a shell script.

A simple log-out/log in should release/renew the DHCP lease (but maybe not... I usually just use the GUI method)
 

hopejr

Senior member
Nov 8, 2004
841
0
0
Originally posted by: n0cmonkey
Originally posted by: Brazen
I found the syntax for the release:

ifconfig interface dhcp release

and for the renew:

ifconfig interface dhcp extend

interface would be the name of your network interface, usually eth0 on linux

That doesn't work on OS X. eth0 only means stuff in Linux. It's en? in Mac OS X.

en0
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: hopejr
Originally posted by: n0cmonkey
Originally posted by: Brazen
I found the syntax for the release:

ifconfig interface dhcp release

and for the renew:

ifconfig interface dhcp extend

interface would be the name of your network interface, usually eth0 on linux

That doesn't work on OS X. eth0 only means stuff in Linux. It's en? in Mac OS X.

en0

That's the first one. I generally use en1 on my Powerbook, iBook, and mini. So en? is appropriate (for any reasonable value of ?). ;)
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
A simple log-out/log in should release/renew the DHCP lease (but maybe not... I usually just use the GUI method)

A logout should not do anything with the interface.
 

hopejr

Senior member
Nov 8, 2004
841
0
0
Originally posted by: n0cmonkey
Originally posted by: hopejr
Originally posted by: n0cmonkey
Originally posted by: Brazen
I found the syntax for the release:

ifconfig interface dhcp release

and for the renew:

ifconfig interface dhcp extend

interface would be the name of your network interface, usually eth0 on linux

That doesn't work on OS X. eth0 only means stuff in Linux. It's en? in Mac OS X.

en0

That's the first one. I generally use en1 on my Powerbook, iBook, and mini. So en? is appropriate (for any reasonable value of ?). ;)

on my ibook and imac, en0 is the ethernet adapter, and en1 is airport. fw0 is firewire. lo0 is loopback :p
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: Murpheeee
I am looking for a way to relese/renew an IP Address in Mac OS-X

It has to be something which can be run by clicking a shortcut on the desktop.

I figured som kind of UNIX code to run in Terminal might be easiest.....

Anyone help me out?

Install Debian.
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
If you can't find a command line way to do it, which I would be suprised if you didn't... but then again, it's apple.

Check out Apple scripting. I would expect there would be a way to do that with apple scripting.. although apple scripting is absolutely horribly documented (they want you to buy a apple script studio thingy I think). There are some nice books on the subject and it's something you'd defiantely want to know how to do if you have to administrate lots of apple computers and need to automate stuff.

 

halfadder

Golden Member
Dec 5, 2004
1,190
0
0
For onboard ethernet:
sudo ipconfig set en0 DHCP

For onboard Airport/802.11:
sudo ipconfig set en1 DHCP
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Murpheeee
Originally posted by: halfadder
For onboard ethernet:
sudo ipconfig set en0 DHCP

This takes care of the release, how about the renew?

Did you read the man page? How about my post like 10 posts before this telling you how to do this stuff?
 

volrath

Senior member
Feb 26, 2004
451
0
0
Maybe you should fix the network so that simple end users do not have to be fiddling with DHCP leases. Why do they need to release and renew?

Funny that for once something is easier on windows than osx. :p
 

NewBlackDak

Senior member
Sep 16, 2003
530
0
0
Open Script Editor(/Applications/AppleScript/Script Editor), and input the folliwing code:

set theInterface to "en0"
set theReturn to (do shell script ("/usr/sbin/ipconfig set " & theInterface & " DHCP") with administrator privileges)
if theReturn is not 0 then
display dialog "There was an error resetting interface " & theInterface & "." buttons {"OK"} giving up after 5
end if


You can change the en0 to whatever interface you need it to work for. Save it as an application, and run it whenever you need it.

You could also add an entry in your /etc/crontab that reads:
0 0 * * * root /usr/sbin/ipconfig set en0 DHCP
This will renew your lease every day at midnight. Of course you can change the time, or schedule it differently.
 

Childs

Lifer
Jul 9, 2000
11,313
7
81
Originally posted by: n0cmonkey
man ipconfig

Maybe something like:
Apple Mac OS X (by command line):

* get an administrator password for the computer
* open a Terminal command window
* type the commands
o sudo ipconfig set en0 BOOTP
o sudo ipconfig set en0 DHCP
* enter the administrator password when asked to
* close the Terminal window

All you have to do is put "sudo ipconfig set en0 BOOTP ;sudo ipconfig set en0 DHCP" in a file, and name it <something>.command. Now you can double click it.