mac os添加静态路由

2015/11/18 13:05
阅读数 2.2K

How-To: Add Static Route in Mac OS X

And because i feel lucky today, (0n a Friday the 13th, that looks kind of odd), here’s another how-to. This is how I added a static route on some Xserves.

Simple solution: route -n add 10.0.0.0/8 10.16.3.254

Permanent solution: Add a startup item (to avoid doing the above command every reboot)

cd /System/Library/StartupItems
mkdir AddRoutes
cd AddRoutes

Create a file called AddRoutes (note: same as the folder name)
vi AddRoutes

——————
#!/bin/sh

# Set static routing tables

. /etc/rc.common

StartService ()
{
if [ “${ADDROUTES:=-NO-}” = “-YES-” ]; then
ConsoleMessage “Adding Static Routing Table”
sudo route -nv add 10.0.0.0/8 10.16.3.254
fi
}

StopService ()
{
return 0
}

StopService ()
{
return 0
}

RestartService ()
{
return 0
}

RunService “$1″
——————

Then create a file StartupParameters.plist
——————
{
Description = “Add static routing tables”;
Provides = (”AddRoutes”);
Requires = (”Network”);
OrderPreference = “None”;
}
—————-

Then change permissions:
chmod 755 AddRoutes StartupParameters.plist

Reboot your computer. Verify with netstat -nr

展开阅读全文
打赏
0
1 收藏
分享
加载中
更多评论
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部