static-route.sh
#!/bin/sh
# TODO 既存設定の有無チェック
route delete <宛先アドレス>
# TODO ゲートウェイへの疎通待ち
route add -host <宛先アドレス> <ゲートウェイ> <ネットマスク>
*※root権限で実行させるため /Library/LaunchDaemon/ 以下に入れる
/Library/LaunchDaemons/static.route.on.ifup.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>toggle.static.route.on.ifup</string>
<key>LowPriorityIO</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/path/to/static-route.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/etc/resolv.conf</string>
<string>/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist</string>
<string>/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist</string>
</array>
</dict>
</plist>
launchctl
sudo launchctl load /Library/LaunchDaemons/static.route.on.ifup.plist