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

Switch IP addresses remotely Network
Does anyone know of a way to change your IP address remotely? either through a shell script, Apple Script or a Perl Script? All I would want to do is log in (SSH, or a password protected web page) and run the script to toggle the Network 'Location' (my primary server went down today and my OS-X box is my backup server).

Or better yet does someone know of a script that will ping my primary server every few seconds, then if there is a non-response ping, run the above script.

[Editor's note: See the comments for the answer - 'scselect' is a Darwin-specific command-line utility to switch the current location!]

Panther proven!
  • Currently 1.33 / 5
  You rated: 2 / 5 (3 votes cast)

Switch IP addresses remotely | 9 comments | Create New Account
Click here to return to the 'Switch IP addresses remotely' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
How to change your IP
Authored by: jnm on Sep 21, '01 03:09:06PM


The command you need is 'ifconfig'
The syntax is (must be root) :
# ifconfig {interface} netmask {netmask} broadcast {broadcast}

Here's an example : suppose your network interface is 'en0', the IP address you want is and the netmask, the command is :
# ifconfig en0 netmask broadcast

The broadcast address is calculated from the IP and the netmask, but in your case, if the new IP is on the same subnet than your previous IP, the netmask and broadcast hasn't to be changed, and you can only use :
# ifconfig en0 {new_IP}

The only thing I'm not sure about is wether the application layer is warned when the IP changes, because it's slightly different than using locations in the network prefs...

If everything I told here seems a bit too confusing for you, it's just because it implies command line knowledge of Unix and several network skills ;o) If you don't manage to do what you need with a little script, just ask, I'll try to help you.

[ Reply to This | # ]
How to change your IP
Authored by: Hes Nikke on Sep 21, '01 05:12:04PM

hay thanks!
that is a great start! now all i need to do is next time this happens find a SSH program for what ever computer i'm on!
:) :) :)

[ Reply to This | # ]
How to change your IP
Authored by: fabiolecca on Sep 22, '01 08:44:23AM


I just discovered a VERY useful terminal command: with scselect you can switch your location settings just as if you were selecting the "Location" menu command from the GUI. It can be very useful from a remote connection and is much more faster than ifconfig.


[ Reply to This | # ]
How to change your IP
Authored by: victory on Sep 22, '01 08:07:12PM

What an incredibly useful command!
While usage is self-explanatory, it doesn't appear to have a man page nor any built-in documentation. It seems to be part of Darwin (not OSX-specific) so I managed to find and browse through the source for this command, which is very short. The conclusion is that it does what it does. No other hidden options, etc. Apparently it stands for [S]ystem [C]onfiguration select.

Thanks again. Maybe you should consider submitting this as a formal 'trick' so more readers will see it.

[ Reply to This | # ]
How to change your IP
Authored by: chabig on Dec 15, '02 09:07:03AM

Scselect has no man page, but if you type "scselect -h" it will display its usage.


[ Reply to This | # ]
How to change your IP
Authored by: mblakele on Apr 24, '03 12:11:41PM

Here's a related command: scutil

Reminiscent of niutil, scutil is an interactive console for configd settings. Fire it up and type 'help' for some online help (cryptic, unfortunately).

Here's how to pull the current location from scutil. This one-liner appeared in a UseNet posting by Stefan Haller:

scutil <<- EOT | awk 'BEGIN { FS = " : "} /UserDefinedName/ { print $2 } END { }'
   show Setup:/

[ Reply to This | # ]
How to change your IP
Authored by: mblakele on Apr 25, '03 09:11:17PM

I just noticed that scselect messes up the permissions on the /private/var/db/SystemConfiguration/preferences.xml file, which causes all the Locations to disappear from the Apple menu and the Networks PreferencePane.

The fix? Any time you run scselect, remember to chmod the file.

552$ ls -l /private/var/db/SystemConfiguration/preferences.xml 
-rw-r--r--   1 root     wheel      100198 Apr 25 18:01 /private/var/db/SystemConfiguration/preferences.xml
553$ scselect "Home"
CurrentSet updated to 1 (Home)
554$ ls -l /private/var/db/SystemConfiguration/preferences.xml 
-rw-------   1 root     wheel      100198 Apr 25 18:09 /private/var/db/SystemConfiguration/preferences.xml
555$ sudo chmod 644 /var/db/SystemConfiguration/preferences.xml
556$ ls -l /private/var/db/SystemConfiguration/preferences.xml 
-rw-r--r--   1 root     wheel      100198 Apr 25 18:09 /private/var/db/SystemConfiguration/preferences.xml

[ Reply to This | # ]
How to change your IP
Authored by: loeschl on Dec 15, '05 01:36:14AM

i had try it with a applescript under osx 10.4.3:

do shell script "ifconfig en0 netmask" user name "Administrator" password "xxxx" with administrator privileges

in the terminal i see that it is changed, but the osx application (safar,..) dont get this information and use the old ip adress and no connection to the internet.

what i must change, or what i do wrong ?


[ Reply to This | # ]
Panther Experiacnes
Authored by: Hes Nikke on Oct 28, '03 12:27:12AM

scselect still works in panther :)

(but is anyone surprised?)

vacuums do not suck. they merely provide an absence that allows other objects to take the place of what becomes absent.

[ Reply to This | # ]