Add a section about static route configuration (this addition contains
an ASCII art diagram, I'll add a graphic version ASAP). PR: docs/63310 Submitted by: Al Hoang <hoanga@mac.com>
This commit is contained in:
parent
73383c7a69
commit
e5417cbf82
Notes:
svn2git
2020-12-08 03:00:23 +00:00
svn path=/head/; revision=20189
1 changed files with 127 additions and 0 deletions
|
@ -455,6 +455,133 @@ host2.example.com link#1 UC 0 0
|
|||
however.</para>
|
||||
</sect2>
|
||||
|
||||
<sect2>
|
||||
<sect2info>
|
||||
<authorgroup>
|
||||
<author>
|
||||
<firstname>Al</firstname>
|
||||
<surname>Hoang</surname>
|
||||
<contrib>Contributed by </contrib>
|
||||
</author>
|
||||
</authorgroup>
|
||||
</sect2info>
|
||||
<!-- Feb 2004 -->
|
||||
<title>Setting Up Static Routes</title>
|
||||
|
||||
<sect3>
|
||||
<title>Manual Configuration</title>
|
||||
|
||||
<para>Let us assume we have a network as follows:</para>
|
||||
|
||||
<literallayout class="monospaced">
|
||||
INTERNET
|
||||
| (10.0.0.1/24) Default Router to Internet
|
||||
|
|
||||
|Interface xl0
|
||||
|10.0.0.10/24
|
||||
+------+
|
||||
| | RouterA
|
||||
| | (FreeBSD gateway)
|
||||
+------+
|
||||
| Interface xl1
|
||||
| 192.168.1.1/24
|
||||
|
|
||||
+--------------------------------+
|
||||
Internal Net 1 | 192.168.1.2/24
|
||||
|
|
||||
+------+
|
||||
| | RouterB
|
||||
| |
|
||||
+------+
|
||||
| 192.168.2.1/24
|
||||
|
|
||||
Internal Net 2
|
||||
</literallayout>
|
||||
|
||||
<para>In this scenario, <hostid>RouterA</hostid> is our &os;
|
||||
machine that is acting as a router to the rest of the
|
||||
Internet. It has a default route set to <hostid
|
||||
role="ipaddr">10.0.0.1</hostid> which allows it to connect
|
||||
with the outside world. We will assume that
|
||||
<hostid>RouterB</hostid> 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
|
||||
<hostid>RouterB</hostid> using <hostid
|
||||
role="ipaddr">192.168.1.1</hostid> as the gateway.)</para>
|
||||
|
||||
<para>If we look at the routing table for
|
||||
<hostid>RouterA</hostid> we would see something like the
|
||||
following:</para>
|
||||
|
||||
<screen>&prompt.user; <userinput>netstat -nr</userinput>
|
||||
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</screen>
|
||||
|
||||
<para>With the current routing table. <hostid>RouterA</hostid>
|
||||
will not be able to reach our Internal Net 2. It does not
|
||||
have a route for <hostid
|
||||
role="ipaddr">192.168.2.0/24</hostid>. One way to alleviate
|
||||
this is to manually add the route. The following command
|
||||
would add the Internal Net 2 network to
|
||||
<hostid>RouterA</hostid>'s routing table using <hostid
|
||||
role="ipaddr">192.168.1.2</hostid> as the next hop.</para>
|
||||
|
||||
<screen>&prompt.root; <userinput>route add network 192.168.2.0/24 192.168.1.2</userinput></screen>
|
||||
|
||||
<para>Now <hostid>RouterA</hostid> can reach any hosts on the
|
||||
<hostid role="ipaddr">192.168.2.0/24</hostid>
|
||||
network.</para>
|
||||
</sect3>
|
||||
|
||||
<sect3>
|
||||
<title>Persistent Configuration</title>
|
||||
|
||||
<para>The above example is perfect for configuring a static
|
||||
route on a running system. However, one problem is that the
|
||||
routing information will not persist if you reboot your &os;
|
||||
machine. The way to handle the addition of a static route
|
||||
is to put it in your <filename>/etc/rc.conf</filename>
|
||||
file:</para>
|
||||
|
||||
<programlisting># Add Internal Net 2 as a static route
|
||||
static_routes="internalnet2"
|
||||
route_internalnet2="network 192.168.2.0/24 192.168.1.2"</programlisting>
|
||||
|
||||
<para>The <literal>static_routes</literal> configuration
|
||||
variable is a list of strings seperated by a space. Each
|
||||
string references to a route name. In our above example we
|
||||
only have one string in <literal>static_routes</literal>.
|
||||
This string is <replaceable>internalnet2</replaceable>. We
|
||||
then add a configuration variable called
|
||||
<literal>route_<replaceable>internalnet2</replaceable></literal>
|
||||
where we put all of the configuration parameters we would
|
||||
give to the &man.route.8; command. For our example above we
|
||||
would have used the command:</para>
|
||||
|
||||
<screen>&prompt.root; <userinput>route add network 192.168.2.0/24 192.168.1.2</userinput></screen>
|
||||
|
||||
<para>so we need <literal>"network 192.168.2.0/24 192.168.1.2"</literal>.</para>
|
||||
|
||||
<para>As said above, we can have more than one string in
|
||||
<literal>static_routes</literal>. This allows us to
|
||||
create multiple static routes. The following lines shows
|
||||
an example of adding static routes for the <hostid
|
||||
role="ipaddr">192.168.0.0/24</hostid> and <hostid
|
||||
role="ipaddr">192.168.1.0/24</hostid> networks on an imaginary
|
||||
router:</para>
|
||||
|
||||
<programlisting>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"</programlisting>
|
||||
</sect3>
|
||||
</sect2>
|
||||
|
||||
<sect2>
|
||||
<title>Routing Propagation</title>
|
||||
<indexterm><primary>routing propagation</primary></indexterm>
|
||||
|
|
Loading…
Reference in a new issue