FreeBSD Static Routing Configuration

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.

ADVERTISEMENTS

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:

networkrouter 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.1via 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
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
14 comments… add one
  • Feargal Reilly Mar 20, 2009 @ 14:34

    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.

    • 🐧 nixCraft Mar 20, 2009 @ 15:23

      You can use KVM / KVMoIP for remote systems.

  • SEanS Apr 27, 2009 @ 14:46

    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

  • Sukri May 6, 2009 @ 17:13

    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

  • Bayou Jun 29, 2009 @ 7:23

    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

  • Bayou Jul 5, 2009 @ 3:24

    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

  • M. O. Afeef Sep 25, 2009 @ 23:17

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

  • Thord matre Jun 23, 2010 @ 13:40

    You should also apply default to your list of static routes.

    static_routes=”lan default”
    route_lan=”-net 192.168.1.0/24 192.168.4.1″

    defaultrouter=”aaa.bbb.215.185″

  • eric Aug 11, 2011 @ 11:11

    Hi, everyone.

    can i ask some technical question, i have a setup lucent IP telephony i want to connect to the abudhabi using ip telephony also it is posible use freebsd as my firewall?

    Thank you.

  • Dánial Nov 1, 2011 @ 11:31

    I’m running FreeBSD 8.2 and after adding the routes to rc.conf I activated them by running:

    # /etc/rc.d/routing static
    
    • Leandro TNK Dec 6, 2011 @ 5:40

      Danial

      Tons of thx man, you’re the man!!! =D
      I spent hours trying to solve this problem and this command worked like a charm to me =D

      now freebsd can resolve names =D

      thx thx thx

      • Shaukat Nov 27, 2014 @ 7:18

        Thanks a lot bro… It works with
        # /etc/rc.d/routing static

  • chatzki Feb 25, 2014 @ 8:25

    From 9.0 version it is sufficient to restart only ‘routing’ service:
    # service routing restart

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.