Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Reset network to renew DHCP when changing locations Network
When changing locations in Network via System Preferences and the DHCP service does not provide directly a new IP address, one does not need to restart the computer. A network reset suffices. This can be given via the terminal:
% sudo /System/Library/StartupItems/NetworkExtensions/NetworkExtensions stop
% sudo /System/Library/StartupItems/NetworkExtensions/NetworkExtensions start
A tcsh "Network-restart" script can be easily put into ~/bin to make this easier. Make the script executable with chmod +x Network-restart. Here's the "Network-restart" script:
#!/bin/tcsh -f
#
# aim:      restart network
# usage:  Network-restart

sudo /System/Library/StartupItems/NetworkExtensions/NetworkExtensions stop
sudo /System/Library/StartupItems/NetworkExtensions/NetworkExtensions start
[robg adds: I haven't tested this one.]
    •    
  • Currently 1.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[11,600 views]  

Reset network to renew DHCP when changing locations | 13 comments | Create New Account
Click here to return to the 'Reset network to renew DHCP when changing locations' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Reset network to renew DHCP when changing locations
Authored by: mervTormel on Oct 22, '03 10:57:21AM

why tcsh?

there is nothing tcsh specific in that script.

just use the smaller /bin/sh

refrain from writing scripts in tcsh



[ Reply to This | # ]
Reset network to renew DHCP when changing locations
Authored by: rae on Nov 07, '03 04:38:16PM
sh is *not* smaller than tcsh.

# /bin/ls -il /bin/*sh
7093 -rwxr-xr-x  1 root  wheel  603488 24 Sep 02:47 /bin/bash
7097 -r-xr-xr-x  2 root  wheel  348068 24 Sep 02:47 /bin/csh
7117 -r-xr-xr-x  1 root  wheel  603488 24 Sep 02:47 /bin/sh
7097 -r-xr-xr-x  2 root  wheel  348068 24 Sep 02:47 /bin/tcsh
7125 -rwxr-xr-x  1 root  wheel  479120 24 Sep 02:46 /bin/zsh
Because sh is now a hard link to bash, tcsh and the hard-linked-to-tcsh csh are much smaller.

So everyone can feel free to use tcsh. Avoid sh/bash! (Based on the smaller-is-better theory, which I don't agree with when the size is less than the size of the CPU cache these days).

[ Reply to This | # ]

Reset network to renew DHCP when changing locations
Authored by: Fofer on Oct 22, '03 11:17:02AM

Hmm... in the past I have just changed the "Configure:" pull down to "Manually," clicked "Apply Now," then switchced it back to "Using DHCP."

It always seemed to refresh DHCP just fine. Why go to all the hassle? Oh, I forgot, you folks just loooove Terminal. ;-)



[ Reply to This | # ]
...or make a "No Network" Location
Authored by: mosxman on Oct 23, '03 09:52:36AM

Another "non-cli" approach is to make a new Network Location in the Network System Preference and then in the "Show" port configuration popdown, deactivate all of the interface checkboxes. When you want to reset networking (or need to shutdown all networking except lo0), just select this "No Network" Location, reselect the Location you want, and you're done.



[ Reply to This | # ]
...or make a "No Network" Location
Authored by: merlyn on Oct 23, '03 10:18:19AM

I call mine "Working without a net". Seemed more appropriate. {grin}



[ Reply to This | # ]
Reset network to renew DHCP when changing locations
Authored by: weefle on Oct 22, '03 11:23:02AM

This is, of course, unnecessary in Panther, in which the Network Preference Pane offers a "Renew DHCP Lease" button.



[ Reply to This | # ]
I still feel ipconfig is better
Authored by: avramd on Oct 22, '03 01:24:42PM
as described in this hint In a terminal, "sudo ipconfig set en0 DHCP" (use en1 for airport) sadly, ipconfig is poortly documented.

[ Reply to This | # ]
Reset network to renew DHCP when changing locations
Authored by: ynolo on Oct 22, '03 01:30:31PM

If all fails in 10.2 before going to the terminal or writing a script you can simply turn off/on the interface not getting a new ip in the Network panels.

Just go to the Network Port Configurations where all the network interfaces are listed and turn off the one not working. Then turn it back on and that is it.

This has happened to me quite a few times and turning it on/off has always worked.

---
i don\'t have one



[ Reply to This | # ]
One line command
Authored by: googoo on Oct 22, '03 03:12:14PM

How about this command?

% sudo SystemStarter restart NetworkExtensions

That should do the same thing as the two commands in the original hint.

-Mark

[ Reply to This | # ]

Reset network to renew DHCP when changing locations
Authored by: peterjhill on Oct 23, '03 06:54:03AM

How about the "real" way to do this.

sudo ifconfig en1 down
sudo ifconfig en1 up

en1 is typically the airport interface
en0 is usually the wired interface

you can use the command

ifconfig -a
to list all of your network interfaces

use the command
man ifconfig
to get a man page on its usage.

I think using the network extensions to play with networking is a bad idea. The preferred method in a *nix environment is the ifconfig command

Don't even touch the ipconfig command... I don't know why they even put it in there. No real sysadmin uses that command.



[ Reply to This | # ]
Reset network to renew DHCP when changing locations
Authored by: force_quit on Oct 24, '03 09:12:54AM

Thankfully the shipping version of Panther seems to eliminate the DHCP bug making this unnecessary!



[ Reply to This | # ]
Off Location
Authored by: spnyc on Oct 24, '03 10:56:42AM
to fix this issue, since it has always been an issue, i created an "OFF" location where all the ports in the network pref pane > network port configuration are (surprise surprise) OFF.

so when i switch locations, i actually go from location1 -> OFF -> location2 and that seems to tell the system to get off it's butt and renew...

again, i have to agree with everyone else in hoping that panther will solve this one.

[ Reply to This | # ]
Reset network to renew DHCP when changing locations
Authored by: kon21 on Sep 13, '06 12:32:17PM

peterjhill suggestion is still valid and works on 10.4.7

Every now and then, after changing networks multiple times, DHCP refuses to work. This trick saves me from rebooting.

GL.. and TY.

Peterjhills quote:
How about the "real" way to do this.

sudo ifconfig en1 down
sudo ifconfig en1 up

en1 is typically the airport interface
en0 is usually the wired interface



[ Reply to This | # ]