Title: add_route


From add_route(8):

"add_route is used for manual entry of routes in the IP routing table.

add_route has the following syntax:

add_route -g gateway [-d destination [-n netmask ]] [-i ip device]

where

-g gateway specifies the gateway IP address to use.
-d destination specifies the destination(s) reached via this gateway.
-n netmask specifies a netmask when the destination is a net.
-i ip device specifies the ip device.

add_route is implemented in /cmd/src/commands/simple/add_route.c of the CMD TAZ installation floppy.
It makes use of a NWIOIPSROUTE ioctl():

result= ioctl(ip_fd, NWIOSIPIROUTE, &route);

note: before Minix 2.0.4 NWIOIPSROUTE was used instead of NWIOSIPIROUTE

Boot(8) has more information on the overall networking installation.

-- * --

At http://www.geocities.com/ctantignone/routing.txt, there is an example of add_route:

You can manually add routes that are to be used to route packets from one
interface to another, with "add_route -i" ("i" for input, the other `normal'
routes are called output routes)

For example, assume a machine with ip address 192.31.231.250 and netmask
255.255.255.0 on /dev/ip0

The command,
add_route -i -g 0.0.0.0 -d 192.31.231.0 -m 1 -n 255.255.255.0 -I /dev/ip0
adds a route to the directly attached ethernet. A packet for 192.31.231.1
that arrives at interface ip2 will be routed to ip0 and ARP will
be used to find the ethernet address associated with 192.31.231.1.

It is also possible to specify a remote router. For example,
add_route -i -g 192.31.231.174 -d 192.35.191.0 -m 2 -n 255.255.255.0
-I /dev/ip0
adds a route to network 192.35.191.0 through router 192.31.231.174.

A third option is to add a default route. For example,
add_route -i -g 192.31.231.1 -d 0.0.0.0 -m 5 -n 0.0.0.0 -I /dev/ip0

The "pr_routes -i" command shows the input routing table:
ent # dest netmask gateway dist pref flags
2 192.35.191.0 255.255.255.0 192.31.231.174 2 0 static
3 192.31.231.0 255.255.255.0 0.0.0.0 1 0 static
4 0.0.0.0 0.0.0.0 192.31.231.1 5 0 static

We also need a routing entry for the PPP interface. For example,
add_route -i -g 0.0.0.0 -d 10.0.0.0 -m 1 -n 255.0.0.0 -I/dev/ip2

The "pr_routes -ai" shows the routing table entries for all interfaces:
ent # dest netmask gateway dist pref flags
if
2 192.35.191.0 255.255.255.0 192.31.231.174 2 0 static
192.31.231.250
3 192.31.231.0 255.255.255.0 0.0.0.0 1 0 static
192.31.231.250
4 0.0.0.0 0.0.0.0 192.31.231.1 5 0 static
192.31.231.250
5 10.0.0.0 255.0.0.0 0.0.0.0 1 0 static
10.0.0.1
"


Note that the "add_route -i" command only affects the routing of packets
that arrive over a network (PPP or ethernet). Packets that are sent by processes are routed using the (normal) output routing table.

Another useful example can be found at Claudio Tantignone's web site.