Bug 63310 - Configuring Static Routes example for Handbook
Summary: Configuring Static Routes example for Handbook
Status: Closed FIXED
Alias: None
Product: Documentation
Classification: Unclassified
Component: Books & Articles (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Marc Fonvieille
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-24 16:30 UTC by hoanga
Modified: 2004-02-26 20:30 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description hoanga 2004-02-24 16:30:17 UTC
	How to configure static routes in FreeBSD for the Handbook

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"
Comment 1 Marc Fonvieille freebsd_committer freebsd_triage 2004-02-24 16:42:02 UTC
Responsible Changed
From-To: freebsd-doc->blackend

I will work on this interesting addition.
Comment 2 Marc Fonvieille freebsd_committer freebsd_triage 2004-02-26 20:29:11 UTC
State Changed
From-To: open->closed

I committed a slightly different version of your submission.  Thanks!