FreeBSD Static Routing Configuration

by Vivek Gite · 8 comments

Q. How do I configure FreeBSD for static routing? I'd like to set default route to 60.1.2.3 and static route for network 192.168.1.0/24 using 192.168.1.254 router. How do make configuration persistence?

A. You can use FreeBSD route command to setup a default route / gateway. You need to edit /etc/rc.conf configuration file to setup static and default routing.

FreeBSD Static Routing Configuration

Open /etc/rc.conf file using a text editor:
# vi /etc/rc.conf
Set default router IP to 60.1.2.3:
defaultrouter="60.1.2.3"
Create static routing for lan network 192.168.1.0/24, append following two lines:
static_routes="lan"
route_lan="-net 192.168.1.0/24 192.168.1.254"

Save and close the file. Where,

  • static_routes="lan" : Set to the list of static routes that are to be addedat system boot time.
  • route_lan="-net 192.168.1.0/24 192.168.1.254" : Specify roting network and router IP address
  • defaultrouter="60.1.2.3" : Set a default route to this host name or IP address. It is recommended that you use an IP address.

Restart FreeBSD networking service to update routing information:
# /etc/rc.d/netif restart
To view routing table, enter:
# netstat -r
# netstat -rn

How do I add multiple static routes?

For each whitespace (blank space) separated element in the value, a route_ variable is assumed to exist whose contents will later be
passed to a route add operation at boot time. For example, setup static routing as follows:

network router IP
lan (192.168.1.0/24) 192.168.1.254
mumoffice (10.0.0.0/8) 10.30.110.5
foo 169.254.1.1 via loopback (lo0)

Add following to /etc/rc.conf
static_routes="lan mumoffice foo"
route_lan="-net 192.168.1.0/24 192.168.1.254"
route_mumoffice="-net 10.0.0.0/8 10.30.110.5"
route_foo="-host 169.254.1.1 -iface lo0"

FreeBSD Multicast Roting Configuration

Multicast routing requires that support be compiled into the kernel with the following option:
options MROUTING
In addition, the multicast routing daemon, mrouted must be installed and configured to set up tunnels and DVMRP via /etc/mrouted.conf. See mrouted page at offical FreeBSD project page for more information.

Further readings:

  • See man pages - mrouted, router and rc.conf

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 8 comments… read them below or add one }

1 Feargal Reilly 03.20.09 at 2:34 pm

Note: Using “/etc/rc.d/netif restart” over a remote connection can be a bad idea. It’ll tear down all of your interfaces so you will lose your connection. Things such as ppp may get confused, leaving you unable to reconnect.

2 Vivek Gite 03.20.09 at 3:23 pm

You can use KVM / KVMoIP for remote systems.

3 SEanS 04.27.09 at 2:46 pm

I have set up the BSD routing so many time it is a joke but when I ping google.le it still tells me:
ping: cannot resolve google.ie: Host name lookup failure
So can some one please show me what to do?
Thanks in advance, SEanS

4 Vivek Gite 04.27.09 at 3:11 pm

What about /etc/resolv.conf file?

5 Sukri 05.06.09 at 5:13 pm

may be you not input dns corectly
please input primary &secondary DNS

#primary DNS
nameserver=xxx.xxx.xxx.xxx
#secondary DNS
nameserver=xxx.xxx.xxx.xxx

Good luck

6 Bayou 06.29.09 at 7:23 am

Him

I have two nic card.
de0 public ip address
r10 private ip address
when I enter de0 first i did the host and then gateway and the ip4 public aand subnett
BUT when I try to enter the private ip on r10 I see the previous confguration I did with de0
Please advise how to enter r10 the private ip address. Please show me an example how to make it work?

Thanks, B

7 Bayou 07.05.09 at 3:24 am

I have two nic card.
de0 public ip address
r10 private ip address
when I enter de0 first i did the host and then gateway and the ip4 public aand subnett
BUT when I try to enter the private ip on r10 I see the previous confguration I did with de0
Please advise how to enter r10 the private ip address. Please show me an example how to make it work?

Thanks, B

8 M. O. Afeef 09.25.09 at 11:17 pm

I have Modem Speedtoutch it is working Put Without Password
Imean The wirelees link Is open I need to look it .

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All