Operation Systems

Configure/Set default gateway under FreeBSD

In this tutorial I will give answers on a couple of fundamental questions about FreeBSD . First sections will explain how to modify or set a default gateway in FreeBSD operating system and second is how to make the route persistent.
First I will introduce to you the route command. It is a native utility that every FreeBSD user uses. Here is a short output from the man pages.
For full manual check FreeBSD man pages

The route utility 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 partition-ings.

Generally for the purposes of this tutorial we will use only add option. First I would recommend that you check what your current routing configuration is. This can be easily done by the netstat command line utility. Simply execute the commands below.
The -r options is to display routing table and -n option is preventing the reverse DNS look up. In most of the cases you just need the IP addresses not the hostnames. Anyway I would recommend to copy paste the output of both these commands in a text file.

root@localhost:~# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.0.0 * 255.255.255.0 U 0 0 0 wlan0
link-local * 255.255.0.0 U 0 0 0 wlan0
default gw.onlinehowto 0.0.0.0 UG 0 0 0 wlan0

root@localhost:~# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.0.0 * 255.255.255.0 U 0 0 0 wlan0
link-local * 255.255.0.0 U 0 0 0 wlan0
default 192.168.0.2 0.0.0.0 UG 0 0 0 wlan0

Now next step is to modify (or set in case that you are just setting this up for the first time) your default gateway The meaning of default gateway is this : all network packets that cannot be sent according to the previous entries of the routing table are sent through the default gateway

root@localhost:~# route add default 192.168.1.254

The file that takes care of that is /etc/rc.conf .Open the file in your favourite editor and set defaultrouter:

root@localhost:~# vi /etc/rc.conf

Set default route by editing defaultrouter variable. Save and close the file.

defaultrouter=”192.168.1.254″

Leave a Reply