Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

samh

macrumors 6502
Original poster
Oct 29, 2009
317
3
Here's what I'm after:

I want to avoid getting my TCP/IP settings by DHCP at work and home, but the networks are different (one is a 192.168.1.xxx subnet and one is a 192.168.0.xxx subnet) and have different gateways and DNS servers. Is there any way for OS X to automatically apply these, without me manually selecting a profile from network settings?

i.e. when I connect to WorkWiFi, OSX assigns an IP Address, DHCP, DNS server, etc. When I go home and connect to MyHomeWiFi, OSX assigns a different IP Address, DHCP, DNS, etc.?
 
Not sure why you would want this headache when you have DHCP, but I think Locations will do what you want.
 
Not sure why you would want this headache when you have DHCP, but I think Locations will do what you want.

Notice, the OP wants to do it without selecting a profile. Suggesting the OP is already using Locations.

To answer the question, there is nothing built in to automatically switch. But you could easily write something to handle the switching of the profile for you.

1. Create a launchd job. Something like this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
	"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.my.locationchanger</string>
	<key>ProgramArguments</key>
	<array>
		<string>/path/to/script</string>
	</array>
	<key>WatchPaths</key>
	<array>
		<string>/Library/Preferences/SystemConfiguration</string>
	</array>
</dict>
</plist>

2. The script needs to be written to detect certain variables which it can then use to determine the location and then perform actions based on that location.

For example, listing available WiFi networks and selecting a network location based on what it determines (this can be done with scselect).

This is an explanation at a pretty high level, it assumes you know how to write scripts as well as how to work with launchd. Hopefully this sets you in the right direction.
 
Notice, the OP wants to do it without selecting a profile. Suggesting the OP is already using Locations.

To answer the question, there is nothing built in to automatically switch. But you could easily write something to handle the switching of the profile for you.

1. Create a launchd job. Something like this:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
	"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.my.locationchanger</string>
	<key>ProgramArguments</key>
	<array>
		<string>/path/to/script</string>
	</array>
	<key>WatchPaths</key>
	<array>
		<string>/Library/Preferences/SystemConfiguration</string>
	</array>
</dict>
</plist>

2. The script needs to be written to detect certain variables which it can then use to determine the location and then perform actions based on that location.

For example, listing available WiFi networks and selecting a network location based on what it determines (this can be done with scselect).

This is an explanation at a pretty high level, it assumes you know how to write scripts as well as how to work with launchd. Hopefully this sets you in the right direction.

That gives me something to explore. I'm still relatively new to the mac world (14 months) after a lifetime in Windows, but I have IT and programming experience and I'm sure I can work something out.

I will likely just use DHCP reservations to accomplish this but wanted to see if there was something easy on the client end. I think Windows 7 can do something like this, but I may not be entirely correct on that.

One reason for my question is that our DHCP server at work assigns a particular set of DNS servers (belonging to our ISP). When I'm at work, my MBP plays better on the network if I assign our Domain Controller as the DNS server. However, during certain weeks of the year we have 100 or more clients on the network and network congestion suffers if everybody is hitting the internal server for DNS. I don't want DHCP assigning the internal DNS server to all clients, but I want it assigned to me. However, when I go home, that IP address is not a valid DNS server. I do not want to be shuffling between profiles--especially if, say, my wife pulls the MBP out and I haven't switched it over.

Windows server will allow me to make the reservation on the server end and that's good enough until I can figure out the launchd script.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.