When working with Linux you get used to the way Linux does things, but when you switch from Linux to Mac OS X you notice that some things are handled differently.
One of these differences I came across recently. It’s about the way you read out the routes you currently have active. I was used to the way you show them in Linux with the following command:
$ route -n
I like to add the “-n” parameter to not resolve the IP addresses to names. This can make the output of the routes much faster.
But when you switch over to OS X you will notice that the command “route” exists but work differently. If you open the man page of “route” on a Linux system and then on OS X you will immediately see the following difference.
The Linux man pages show you this description for the command:
route - show / manipulate the IP routing table
But the OS X man page will only show this in the description:
route -- manually manipulate the routing tables
The missing word “show” gives the hint that the route command will not show us the routes as we are used to from Linux. To get a similar list of active routing entries as on Linux the following command has to be executed:
$ netstat -rn
The output of the netstat command on Mac OS X is very similar to the output you are used to from Linux. The option “-r” tell netstat to show the routing table and the “-n” option as with the “route” command avoids DNS resolution. The netstat command is used to show more then just the routing table and is also available on Linux. When executed on Linux it will show the same output as the route command.
Adding a route
For adding a route to the routing table Linux as well as OS X use the route command, but be aware that even here there are differences. In OS X, to specify a route for network 10.0.0.0/24 to be routed to gateway 10.0.0.1 you use the following command.
$ route -n add 10.0.0.0/24 10.0.0.1
But if you are on a Linux system you will have to use the following command to do the same:
$ route -n add -net 10.0.0.0/24 gw 10.0.0.1
The syntax is very close to the syntax of OS X but it is not identical. In the OS X the destination and gateway parameter is defined by its position in the command line, the Linux command expects the parameters to be prefixed with “-net” and “gw”.
The man page of the related commands are usually a good source of what is different between Linux and Mac OS X.
Read more of my posts on my blog at http://blog.tinned-software.net/.