The Mediawiki system (the 'software' that runs this site) capitalises all articles. Please note that commands on most UNIX and Unix-like systems are entered in lower case. As an example the article documenting the Ln command would be issued from the command line as 'ln'.
The route command is used to manually configure the routing on FreeBSD. It differs in usage from the Microsoft command of the same name which can confuse system administrators migrating across platforms.
Typically the route command is not required since advanced routing requirements would ordinarily be maintained by the routed daemon.
The command itself has only a few options but makes up for this with what is described as a programmatic command language interface. The available options are as follows.
The -d option executes the request but does not implement it. It allows the request to be tested to ensure there are no issues arising from doing so.
The -n option instructs the route command to not resolve IP addresses to DNS names. This is useful where name resolution may slow down the presentation of information or otherwise where no DNS name servers are available or configured for use.
The -v option presents additional information on the screen.
The -q option suppresses information for certain commands, namely; 'add', 'change' and 'flush' (see below).
The following commands are exist:
The add command creates a new route entry into the routing table.
The flush command removes all routes from the routing table (use with caution).
The delete command removes a single route entry from the routing table.
The change command changes a specific element of a route already in the routing table.
The get command displays a specific entry of the routing table.
The monitor command continuously displays changes to or queries from the routing table.
Note: the following commands will modify the routing table but any changes will be lost upon the next reboot. See articles in the 'See also' section below for more advanced methods of route management.
Default route (gateway)
Adding a default gateway is done using the following command:
#route add -net default 192.168.0.1 add net default: gateway 192.168.0.1
The 'default' option is an inbuilt alias for the default gateway and '192.168.0.1' is the router IP in this instance.
Adding a static route is done using the following command:
#route add -net 192.168.20.0/24 192.168.0.2 add net 192.168.20.0: gateway 192.168.0.2
The '192.168.20.0/24' is the subnet of the remote network, which would have been specified as '192.168.20.0 mask 255.255.255.0' on Microsoft Windows or '192.168.20.0 netmask 255.255.255.0' on Linux and other platforms. The '192.168.0.2' is the router IP connecting to the remote network.
Deleting a route is done using the following command:
#route delete 192.168.20.0 delete net 192.168.20.0
The '192.168.20.0' is the route entry being deleted. This can also be specified as '192.168.20.0/24' where a more specific route is used.
Microsoft Windows equivalents
Many system administrators from the Microsoft world will be used to using the route show command to display current routing table information. This is not available from the FreeBSD command of the same name. However it is available using netstat -r command instead.
$ netstat -r Routing tables Internet: Destination Gateway Flags Refs Use Netif Expire default 172.27.0.1 UGS 0 1822642 fxp0 localhost localhost UH 0 3946 lo0 172.27/24 link#1 UC 0 0 fxp0 172.27.0.1 00:02:a5:77:5c:29 UHLW 2 0 fxp0 1193 mail 00:02:a5:84:d3:10 UHLW 1 22373 lo0 Internet6: Destination Gateway Flags Netif Expire localhost.domain localhost.domain UH lo0 fe80::%fxp0 link#1 UC fxp0 fe80::202:a5ff:fe8 00:02:a5:84:d3:10 UHL lo0 fe80::%lo0 fe80::1%lo0 U lo0 fe80::1%lo0 link#3 UHL lo0 ff01:1:: link#1 UC fxp0 ff01:3:: localhost.domain UC lo0 ff02::%fxp0 link#1 UC fxp0 ff02::%lo0 localhost.domain UC lo0