Home > Uncategorized > Lion / Lion Server: How to add/configure a static route

Lion / Lion Server: How to add/configure a static route

Problem description:

You need to add a static route on your Mac OS X Lion or Lion Server installation, so that after a reboot the route will be readded.

 
Problem resolution:

With Mac OS X Lion you can use launchd to configure the route during startup.

Just follow the next steps:

  1. Become root
    lion01:~ myuser$ sudo su -
    Password:
    lion01:~ root#

     

  2. Create a launchd file in /Library/LaunchDaemons
    In this example we want to add a route for the network 192.66.4.0/24 and configure 192.168.0.254 as the gateway:

    lion01:~ root# cd /Library/LaunchDaemons/
    lion01:LaunchDaemons root# 
    lion01:LaunchDaemons root# vi local.lion01.route.plist 
    lion01:LaunchDaemons root# 
    lion01:LaunchDaemons root# cat local.lion01.route.plist 
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>local.lion.route</string>
      <key>OnDemand</key>
      <false/>
      <key>ProgramArguments</key>
      <array>
      <string>route</string>
      <string>add</string>
      <string>192.166.4.0/24</string>
      <string>192.168.0.254</string>
      </array>
      <key>KeepAlive</key>
      <false/>
      <key>RunAtLoad</key>
      <true/>
      <key>ServiceIPC</key>
      <false/>
      <key>UserName</key>
      <string>root</string>
      <key>LaunchOnlyOnce</key>
      <true/>
    </dict>
    </plist>
    lion01:LaunchDaemons root#

     

  3. Run launchctl
    lion01:LaunchDaemons root# launchctl load /Library/LaunchDaemons/local.lion01.route.plist 
    lion01:LaunchDaemons root#

     

  4. Now you should be able to reach the destination
    lion01:~ root# netstat -rn
    Routing tables
     
    Internet:
    Destination        Gateway            Flags        Refs      Use   Netif Expire
    ...
    ...
    192.168.4/24       192.168.0.254      UGSc            1        8     en0
    ...
    ...
     
    Internet6:
    Destination                             Gateway                         Flags         Netif Expire
    ...
    ...
    lion01:~ root# 
    lion01:~ root# ping -c 3 192.168.4.1
    PING 192.168.4.1 (192.168.4.1): 56 data bytes
    64 bytes from 192.168.4.1: icmp_seq=0 ttl=64 time=0.403 ms
    64 bytes from 192.168.4.1: icmp_seq=1 ttl=64 time=0.445 ms
    64 bytes from 192.168.4.1: icmp_seq=2 ttl=64 time=0.545 ms
     
    --- 192.168.4.1 ping statistics ---
    3 packets transmitted, 3 packets received, 0.0% packet loss
    round-trip min/avg/max/stddev = 0.403/0.464/0.545/0.060 ms
    lion01:~ root#
Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.

Connect with Facebook