Professional Documents
Culture Documents
The process of readdressing for the new network involves three steps. It is clea
r in Example 1.5, ifconfig and route output before the change , that morgan is conf
igured for a different network than the main office desktop network. First, the
active interface must be brought down, then a new address must be configured on
the interface and brought up, and finally a new default route must be added. If
the networking configuration is correct and the process is successful, the machi
ne should be able to connect to local and non-local destinations.
Example 1.6. Bringing down a network interface with ifconfig
[root@morgan]# ifconfig eth0 down
The routing table on morgan should look exactly like the initial routing table o
n tristan. Compare the routing tables in Example 1.1, Sample ifconfig output and E
xample 1.8, Adding a default route with route .
These changes to the routing table on morgan will stay in effect until they are
manually changed, the network is restarted, or the machine reboots. With knowled
ge of the addressing scheme of a network, and the use of ifconfig and route it's
simple to readdress a machine on just about any Ethernet you can attach to. The
benefits of familiarity with these commands extend to non-Ethernet IP networks
as well, because these commands operate on the IP layer, independent of the link
layer.
1.3.3. Adding and removing a static route
Now that morgan has joined the LAN at the main office and can reach the Internet
, a static route to the branch office would be convenient for accessing resource
s on that network.
A static route is any route entered into a routing table which specifies at leas
t a destination address and a gateway or device. Static routes are special instr
uctions regarding the path a packet should take to reach a destination and are u
sually used to specify reachability of a destination through a router other than
the default gateway.
As we saw above, in Section 1.2.3, Static Routes to Networks , a static route provi
des a specific route to a known destination. There are several pieces of informa
tion we need to know in order to be able to add a static route.
*
the address of the destination (192.168.98.0)
*
the netmask of the destination (255.255.255.0)
o
EITHER the IP address of the router through which the destination (1
92.168.99.1) is reachable
o
OR the name of the link layer device to which the destination is dir
ectly connected
Example 1.9. Adding a static route with route
[root@morgan]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.99.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 192.168.99.254 0.0.0.0 UG 0 0 0 eth0
[root@morgan]# route add -net 192.168.98.0 netmask 255.255.255.0 gw 192.168.99.1
[root@morgan]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.99.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.98.0 192.168.99.1 255.255.255.0 UG 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 192.168.99.254 0.0.0.0 UG 0 0 0 eth0
Example 1.9, Adding a static route with route shows how to add a static route to t
he 192.168.98.0/24 network. In order to test the reachability of the remote netw
ork, ping any machine on the 192.168.98.0/24 network. Routers are usually a good
choice, since they rarely have packet filters and are usually alive.
Because a more specific route is always chosen over a less specific route, it is
even possible to support host routes. These are routes for destinations which a
re single IP addresses. This can be accomplished with a manually added static ro
ute as below.
Example 1.10. Removing a static network route and adding a static host route
[root@morgan]# route del -net 192.168.98.0 netmask 255.255.255.0 gw 192.168.99.1
[root@morgan]# route add -net 192.168.98.42 netmask 255.255.255.255 gw 192.168.9
9.1
[root@morgan]# route add -host 192.168.98.42 gw 192.168.99.1
SIOCADDRT: File exists
[root@morgan]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.99.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.98.42 192.168.99.1 255.255.255.255 UGH 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 192.168.99.254 0.0.0.0 UG 0 0 0 eth0