Netstat combined with the -r option will display the kernel routing tables. Nevertheless as it is still widely used, we have included it here.
While this is a popular way of printing out routing information in Linux, netstat is actually deprecated and replaced instead with ip route – it even says so in the manual page. While this is the current recommended method of printing out the routing table in Linux, you will see that the output doesn’t look as nice as older options.Ĭheck out our IP command examples for further information on how you can use this to display networking information. If you’re in a hurry you can also shorten this to ‘ip r’ which will print the same output. The current recommended way of printing the routing table in Linux is with the ip command followed by route, as demonstrated below.
If you’re instead trying to create a new static route in Linux check out our guide here. Here are three different commands that you can use to print out the routing table in Linux.
The man page of the related commands are usually a good source of what is different between Linux and Mac OS X.The routing table is used to show you where various different network subnets will be routed to. 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 syntax is very close to the syntax of OS X but it is not identical. $ route -n add 10.0.0.0/24 10.0.0.1īut 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 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. Adding a routeįor 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. When executed on Linux it will show the same output as the route command. The netstat command is used to show more then just the routing table and is also available on Linux. The option “-r” tell netstat to show the routing table and the “-n” option as with the “route” command avoids DNS resolution.
The output of the netstat command on Mac OS X is very similar to the output you 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 missing word “show” gives the hint that the route command will not show us the routes as we are used to from Linux. The Linux man pages show you this description for the command: route - show / manipulate the IP routing tableīut the OS X man page will only show this in the description: route - manually manipulate the routing tables If you open the man page of “route” on a Linux system and then on OS X you will immediately see the following difference. This can make the output of the routes much faster.īut when you switch over to OS X you will notice that the command “route” exists but work differently. I like to add the “-n” parameter to not resolve the IP addresses to names. I was used to the way you show them in Linux with the following command: $ route -n It’s about the way you read out the routes you currently have active. One of these differences I came across recently. 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.