5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【OSX】ネットワークインターフェースUP時に静的ルーティング設定を行う

Last updated at Posted at 2015-12-08
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
5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?