Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Feb 2004 01:28:58 +0900 (JST)
From:      hoanga@mac.com
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   docs/63310: Configuring Static Routes example for Handbook
Message-ID:  <20040224162858.D83452E0BF@samsara.bebear.net>
Resent-Message-ID: <200402241630.i1OGUH4L059771@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         63310
>Category:       docs
>Synopsis:       Configuring Static Routes example for Handbook
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-doc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 24 08:30:17 PST 2004
>Closed-Date:
>Last-Modified:
>Originator:     Al Hoang
>Release:        FreeBSD 5.2.1-RC2 i386
>Organization:
Doctor M
>Environment:
System: FreeBSD samsara 5.2.1-RC2 FreeBSD 5.2.1-RC2 #1: Wed Feb 18 23:23:59 JST 2004 root@samsara:/usr/obj/usr/src/sys/SAMSARA i386


>Description:
	How to configure static routes in FreeBSD for the Handbook
>How-To-Repeat:
>Fix:
Setting up static routes

Setting up static routes in FreeBSD

Manual configuration

Let's assume you have a network as follows:

    INTERNET
      | (10.0.0.1/24) Default Router to Internet
      |
      |Interface xl0
      |10.0.0.10/24
   +------+
   |      | Router A
   |      | (FreeBSD gateway)
   +------+
      | Interface xl1
      | 192.168.1.1/24
      |                  
  +--------------------------------+
   Internal Net 1      | 192.168.1.2/24
                       |
                   +------+
                   |      | Router B  
                   |      |
                   +------+
                       | 192.168.2.1/24      
                       |
                     Internal Net 2

In this scenario, Router A is our FreeBSD machine that
is acting as a router to the rest of the Internet.  It
has a default route set to 10.0.0.1 which allows it to
connect with the outside world.  We will assume that
Router B is already configured properly and knows how
to get wherever it needs to go.  (This is simple in this
picture.  Just add a default route on B using 192.168.1.1
as the gateway).

If we look at the routing table for A we would
see something like the following:

% netstat -nr
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
default            10.0.0.1           UGS         0    49378    xl0
127.0.0.1          127.0.0.1          UH          0        6    lo0
10.0.0/24          link#1             UC          0        0    xl0
192.168.1/24       link#2             UC          0        0    xl1

With the current routing table.   A will not be able to reach our
Internal Net 2.  It does not have a route for 192.168.2.0/24.  One
way to alleviate this is to manually add the route add.   The
following command would add the Internal Net 2 network to
A's routing table using 192.168.1.2 as the next hop.
% route add network 192.168.2.0/24 192.168.1.2

Now A can reach any hosts on the 192.168.2.0/24 network.

Persistent Configuration

The above example is great for configuring a static route on
a running system.  However, one problem is that the routing
information will not persist if you reboot your FreeBSD machine.
The way to handle adding a static route is to put it in your
/etc/rc.conf file.

Example configuration:
# Add Internal Net 2 as a static route
static_routes="internalnet2"
route_internalnet2="network 192.168.2.0/24 192.168.1.2"

The static_routes configuration variable is a list of strings 
seperated by a space.  The string references to another
configuration variable that will be named route_.......
In our above example we only have one string in static_routes.
This string is internalnet2.   We then need a configuration
variable called route_internalnet2 where we add all of
the configuration parameters we would give to the route command.
For our example above we would have used the command
% route add network 192.168.2.0/24 192.168.1.2
So we need "network 192.168.2.0/24 192.168.1.2".

We could have more than one string in static_routes.  This
would allow us to create multiple static routes.   The
following snippet shows an example of adding
static routes for the 192.168.0.0/24 and 192.168.1.0/24 
on an imaginary router.
the following:

static_routes="net1 net2"
route_net1="network 192.168.0.0/24 192.168.0.1"
route_net2="network 192.168.1.0/24 192.168.1.1"





>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040224162858.D83452E0BF>