정보기술/Mac

How to add or delete static routes

fermi 2013. 2. 13. 14:31

1. host


route add x.x.x.x gateway

route delete x.x.x.x gateway


sudo route add 10.8.0.2 192.168.0.1

sudo route delete 10.8.0.2 192.168.0.1



2. subnet


route add x.x.x.x/24 gateway

route delete x.x.x.x/24 gateway


route add 10.8.0.0/24 192.168.0.1

route delete 10.8.0.0/24 192.168.0.1



3. Automatically set static routs


참고: http://www.andre-aulich.de/en/perm/setting-static-routes-in-mac-os-x-104105-client-and-server


We can simply use a launchd entry in /Library/LaunchDaemons, which can look like this. 


<?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>setstaticroute</string>

<key>ProgramArguments</key>

<array>

<string>route</string>

<string>add</string>

<string>-host</string>

<string>192.168.2.100</string>

<string>192.168.1.254</string>

</array>

<key>RunAtLoad</key>

<true/>

<key>StartInterval</key>

<integer>1200</integer>

</dict>

</plist>


Just copy the file into /Library/LaunchDaemons/ and activate it by typing


sudo launchctl load -w /Library/LaunchDaemons/setstaticroute.plist