I have googled a bit, and all I can find is hacks to run a script that enables the routes after a reboot.
Surely there must be a more elegant way? I called AppleCare, and they directed me to the developer website while telling me they do not support terminal(!?!). What kind of answer is that to a totally legit request for support?
Is there a way to post feature requests for future OS X versions in case this is not supported?
Sorry. Spent a full fifteen minutes explaining AppleCare what I meant, and then post a oneliner here, expecting you guys read my mind... 🙂
This is what I want to do:
My Mac is hooked up to a separate network from my office network, where I use a separate gateway to give me access to a couple of other networks that is not available to the rest of the network.
To show you an example:
My computer is on the 10.0.0.0 network with my "special" gateway at 192.168.0.100. The normal gateway on this network is 192.168.0.1, and I need to use that gateway to access servers, shares, mail and DNS. All these are gathered on the 10.10.0.0 segment, so all I need to do is send all my traffic for the 10.10.0.0 network to the normal gateway at 192.168.0.1.
To do this in OS X, I open terminal and type "route add -net 10.10.0.0 -netmask 255.255.0.0 192.168.0.1"
This way the computer adds this line into its routing table, and all network traffic meant for the 10.10.0.0 network is sent to the correct gateway. The rest of the traffic is sent to my "special" gateway at 192.168.0.100 as it's told to use from the DHCP server.
My problem is that I cannot find an elegant way to make this added route live through a reboot, so I keep adding these routes each time I have to reboot.
In other OSes I use there's a way to add these routes so they stick (persistent routes), and that is what I seek in OS X as well.
Two, you should never have more than one default gateway per connection. If you are on your home network, you should one have one default gateway, no special ones.
Third, the best I can think of, that would be the easiest would be to type the commands into Text Edit and save it as Routes.command
You can run it like and it will execute the commands.
As I menation in my first post, this is what I already have found. I also have found a hack to make the script run on boot so I won't need to interact.
What I seek is a native way in OS X to handle this. There are wyas to do this in all other OSes I use, so I was hoping there is one in OS X that has been overlooked.
But thanks for your input. If I hadn't already googled a bit, it would have been an option for me. 🙂
If you want to do this in Windows, you'd add a "-p" to the end of the "route add" command. This is a built in feature as opposed to the script in OS X that basically is a hack. 😉
The reason is that a computer should not contain routes. A proper setup would be such that the DHCP server provides the default gateway, IP address, and subnet mask. The computer forwards ALL traffic to the default gateway, where it is than routed by the router.
You can set Locations in System Preferences under Network, which can contain basic static information, but just IP address, subnet, default gateway, and authentication settings.
Otherwise, your way of doing it is the only way. Maybe you should write a program to do it and sell it. You would make a lot of money off it. It is a well known issue.
Here´s a quick summary of the info from macosxhints.com, just in case the link dies:
The trick here is that you must use an ifconfig command in the rc.local script. This means that at a later point in the process, the GUI-specified interface configuration will be done redundantly. If you do not do this, the route command will fail, because there will be no device configured for the bridging subnet.
Here is the critical portion of the rc.local script:
Once you understand that (1) rc.local is still the best place for this (not the GUI), and (2) you have to do an early ifconfig to help the route command do the right thing, adding static routes is really simple. Now, you could probably do it in LaunchDaemons or StartupItems, if you do ifconfig before route, but in truth, no daemon is launched here, and StartupItems is deprecated, so rc.local may be the best option.
It goes without saying that you have to make sure that the ifconfig in rc.local matches what the GUI assumes about the interfaces, otherwise you're in big trouble.
jevel, very good & thorough post. All you're asking is how to make a permanent route in OS X. As you know, that
should be very simple but alas it's not.
If you haven't found it yet, there's a very good article at
http://www.afp548.com/article.php?story=20041015131913324 that explains this situation. (The short story is that Apple is trying make IP more user friendly by dynamically altering network settings to accommodate changes in the network. That's why your route may be unexpectedly deleted.)
A "route add" startup script is convenient but if your network changes your route is likely lost. For pre-10.5, consider hooking into kicker.bundle. For 10.5, try hooking into launchd. (See
http://tech.inhelsinki.nl/locationchanger/) These are more dynamic solutions that may help.
In your world all computers have a single network interface and gateway. In the real world some computers are multi-homed and have to have enough intelligence to route to the proper interface.
The reason is that a computer should not contain routes. A proper setup would be > such that the DHCP server provides the default gateway, IP address, and subnet >mask. The computer forwards ALL traffic to the default gateway, where it is than >routed by the router.