Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Persistent static routes.

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?

Thanks in advance!

-KJ

Mac Pro, Mac OS X (10.5.3)

Posted on Jun 24, 2008 1:50 PM

Reply
18 replies

Jun 24, 2008 2:41 PM in response to Community User

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.

Hope this makes a little more sense. 🙂

-KJ

Jun 24, 2008 2:51 PM in response to jevel

First, why subnet like that.

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.

Jun 24, 2008 3:28 PM in response to jevel

Actually, do this. Open Script Editor, and type this in:

tell application "Terminal"
do script "route add -net IP ADDRESS -netmask SUBNET MASK DEFAULT GATEWAY"
do script "route add -net IP ADDRESS -netmask SUBNET MASK DEFAULT GATEWAY"
.... add as needed
quit
end tell

when you are done, File>Save As>Application

Now, set the application to open on Login, and press Run when it prompts you.

Jun 24, 2008 3:34 PM in response to jevel

OK. Well, just put the commands in the quotes, and run that when you turn the computer on. Make sure to save as an Application.

Just remember that each new terminal command is +do script "COMMAND"+

This will be the Script (remember: Save As>Application):

tell application "Terminal"
do script "COMMAND"
do script "COMMAND"
.... add as needed
quit
end tell

Jun 24, 2008 3:49 PM in response to Community User

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. 🙂

-KJ

Jun 24, 2008 10:35 PM in response to Community User

I didn't neccessarily mean graphical.

Let me explain:

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. 😉

http://www.osxfaq.com/tips/kluskens/index.ws

The link above is how I have it solved at the moment, and it works like it's supposed to, it's just not an elegant way to do it IMO.

-KJ

Jun 24, 2008 10:45 PM in response to jevel

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.

Jun 26, 2008 8:07 AM in response to jevel

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:

ifconfig en2 inet 11.22.33.5 netmask 255.255.255.252
route -n add 11.22.33.xx/xx 22.33.44.x

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.

Jun 26, 2008 9:47 AM in response to jevel

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.

Good luck.

Jun 26, 2008 12:13 PM in response to Community User

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.

Persistent static routes.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.