search by tags

for the user

adventures into the land of the command line

adding a persistent static route to your mac

Nooooooormally, on other linux style OSes, you just add the route into like, /etc/network/interfaces or whatever, but on a mac, how do you do it?

You can check your network interfaces.

$ networksetup -listallnetworkservices

An asterisk (*) denotes that a network service is disabled.
Wi-Fi
USB Ethernet
iPhone USB
Bluetooth PAN

You can get info on a specific interface.

$ networksetup -getinfo 'Wi-Fi'

DHCP Configuration
IP address: 192.168.1.68
Subnet mask: 255.255.255.0
Router: 192.168.1.1
Client ID:
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Wi-Fi ID: e9:12:7f:05:e6:24

To add a new route (you’ll need to enter your apple-id password).

$ sudo networksetup -setadditionalroutes  [  ]

$ sudo networksetup -setadditionalroutes 'Wi-Fi' 10.0.0.0 255.255.255.0 192.168.0.250
Password:

Check your new route is added.

$ networksetup -getadditionalroutes 'Wi-Fi'
10.0.0.0 255.255.255.0 192.168.0.250

Check it in a more familiar way with netstat. And there it is, second from the top.

$ netstat -nr
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.1.1        UGSc          291        0     en0
10/24              192.168.0.250      UGSc            0        0     en0
127                127.0.0.1          UCS             2     1989     lo0
127.0.0.1          127.0.0.1          UH              9   248104     lo0
.
.
.