Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Routing in Linux:

route add -net 192.168.10.0 netmask 255.255.255.0 dev eth0


route add -net 127.0.0.0 netmask 255.0.0.0 lo
route add default gw 192.168.10.1
netstat -r
Destination
MSS
Window
192.168.10.0
40
127.0.0.0
U
default
40

Irtt
*
0

Gateway
Iface

Genmask
0

*
40
0

0
192.168.10.1
0

Flags

255.255.255.0 U
eth0
255.0.0.0
0
lo
0.0.0.0
UG
eth0

route del -net 192.168.10.0


Multinetwork routing:
So what happens if you have a more complicated network?
Let's assume for a moment that you have two LANs, the first with the 10.0.0.0 ne
twork and a second with the 192.168.10.0 network.
There is a firewall between the two networks, with two network cards: eth0 is at
tached to the 10.0.0.0 network.
While eth1 is attached to the 192.168.10.0 network.
This firewall needs to route packets from the 10.0.0.0 network through the 192.1
68.10.0 network.
Which will in turn forward packets to the Internet.
In this scenario, you d set up the firewall system with two IP addresses: 10.0.0.1 o
n eth1 and 192.168.10.25 on eth0.
The gateway to the Internet on the 192.168.10.0 network is still 192.168.10.1.
On the firewall system, you would run route with the following commands:
route add -net 192.168.10.0 netmask 255.255.255.0 dev eth1
route add default gw 192.168.10.1
route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
On the router, this defines both networks: 192.168.10.0 on eth1 and 10.0.0.0 on
eth0. It also assigns 192.168.10.1 as the default gateway.
On the computers in the 10.0.0.0 network, you would use route like this:
route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
route add default gw 10.0.0.1
This tells each computer that the default gateway is 10.0.0.1, which is your fir
ewall/router.
With both the firewall and the 10.0.0.0 network set up, you should be able to ro
ute all packets from the 10.0.0.0 network to the Internet and to the 192.168.10.
0 network. So what happens if you have a system in the 192.168.10.0 network you
want to be able to talk to systems in the 10.0.0.0 network?
On each system in the 192.168.10.0 network, you will have to configure your rout
ing table a little differently. Here, you would traditionally use:
route add -net 192.168.10.0 netmask 255.255.255.0 dev eth0
route add default gw 192.168.10.1

This configures the network and the default gateway. However, in this case, 192.
168.10.1 knows nothing about the 10.0.0.0 network, so your packets would get los
t because 192.168.10.1 has no idea where to send the packets and will attempt to
send them through the default gateway. You need to add another routing statemen
t to each system in the 192.168.10.0 network like this:
route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.10.25
This command tells the kernel to route all packets destined for the 10.0.0.0 net
work to 192.168.10.25, which it defines as a gateway. So now, by using the three
route commands, your kernel will know where to send packets. In this situation,
a few things happen:
Packets to 192.168.10.0 are handled without a gateway.
Packets to 10.0.0.0 are sent to the defined gateway, 192.168.10.25.
Packets traveling anywhere else are sent to the default gateway, 192.168.10.1.

You might also like