Archive for January, 2012

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

January 22nd, 2012 Matthias Pölzinger No comments

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 -
    lion01:~ root#


  2. Create a launchd file in /Library/LaunchDaemons
    In this example we want to add a route for the network and configure 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"
    <plist version="1.0">
    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
    Destination        Gateway            Flags        Refs      Use   Netif Expire
    192.168.4/24      UGSc            1        8     en0
    Destination                             Gateway                         Flags         Netif Expire
    lion01:~ root# 
    lion01:~ root# ping -c 3
    PING ( 56 data bytes
    64 bytes from icmp_seq=0 ttl=64 time=0.403 ms
    64 bytes from icmp_seq=1 ttl=64 time=0.445 ms
    64 bytes from icmp_seq=2 ttl=64 time=0.545 ms
    --- 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#