≡ Menu

route command

Understanding Routing Table

Q.What is a routing table? Can you explain its usage under Linux / UNIX operating system?
[click to continue…]

Linux route Add Command Examples

I am a new Linux user. How do I add a new or default gateway using route command on Linux operating systems? How can I use route command to show or set a new route on Linux based server or desktop system?
[click to continue…]

FreeBSD Static Routing Configuration

Q. How do I configure FreeBSD for static routing? I'd like to set default route to and static route for network using router. How do make configuration persistence?
[click to continue…]

FreeBSD Set a Default Route / Gateway

Q. How do I modify or set a default route for my FreeBSD server? How do I make default route configuration persistent?

A. The route command is used under FreeBSD to manually manipulate the network routing tables. It provides six commands:
=> add : Add a route.

=> flush :Remove all routes.

=> delete : Delete a specific route.

=> change : Change aspects of a route (such as its gateway).

=> get : Lookup and display the route for a destination.

=> monitor : Continuously report any changes to the routing information base, routing lookup misses, or suspected network partitionings.

Task: View / Display FreeBSD Routing Table

Use netstat command with -r option:
$ netstat -r
$ netstat -rn


Routing tables
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            61.221.xx.yy       UGS         0      247    em1
10               UGS         0       50    em0
10.10.110/26       link#1             UC          0        0    em0        00:1b:0d:e6:58:40  UHLW        2        0    em0   1145
61.221.xx.yy/29    link#2             UC          0        0    em1
61.221.xx.yy       00:1b:0d:e6:57:c0  UHLW        2        0    em1   1055
61.221.xx/24       link#2             UC          0        0    em1          UH          0        0    lo0

The first two line displays default routes.

Task: FreeBSD Set a default route

All network packets that cannot be sent according to the previous entries of the routing table are sent through the following default gateway:
# route add default

How do I save routing information to a configuration file?

If you reboot FreeBSD box, the routing configuration will be lost i.e. the routing information will not persist. You need to edit /etc/rc.conf file to set defaultroute:
# vi /etc/rc.conf
Set default route by editing defaultrouter variable:
Save and close the file.

Task: Start and Stop FreeBSD Configured Interfaces

To apply changes to a configuration file, you need to stop and restart the corresponding FreeBSD networking interface. The following command will also update routing information:
# /etc/rc.d/netif restart
# /etc/rc.d/routing stop
# /etc/rc.d/routing start

Further readings:

  • Read man pages netstat, route, rc.conf

How do I find out my gateway IP for a computer or a network device that allows or controls access to another computer or network under Linux / UNIX operating systems?
[click to continue…]

Debian / Ubuntu Linux Setting a Default Gateway

Q. How do I setup a default gateway on Debian or Ubuntu Linux? My router IP is and I'd like to setup this as a default gateway for Debian Linux.

A. You can use command line tool such as
a] ip command - show / manipulate routing, devices, policy routing and tunnels

b] route command - show / manipulate the IP routing table

c] Save routing information to a configuration file so that after reboot you get same default gateway.

ip command to set a default router to

Login as the root and type:
# ip route add default via
$ sudo ip route add default via

route command to set a default router to

Login as the root and type:
# route add default gw
$ sudo route add default gw

Save routing information to a configuration file /etc/network/interfaces

Open /etc/network/interfaces file
# vi /etc/network/interfaces
$ sudo vi /etc/network/interfaces
Find eth0 or desired network interface and add following option
Save and close the file. Restart networking:
# /etc/init.d/networking restart
$ sudo /etc/init.d/networking restart

Linux setup default gateway with route command

How do I setup default gateway with a route command on a Linux operating systems?
[click to continue…]