route linux

Download Route Linux

If you can't read please download the document

Upload: kien-ha

Post on 20-Sep-2015

212 views

Category:

Documents


0 download

DESCRIPTION

Route Linux

TRANSCRIPT

Routing in Linux:route add -net 192.168.10.0 netmask 255.255.255.0 dev eth0route add -net 127.0.0.0 netmask 255.0.0.0 loroute add default gw 192.168.10.1netstat -rDestination Gateway Genmask FlagsMSS Window Irtt Iface192.168.10.0 * 255.255.255.0 U 40 0 0 eth0127.0.0.0 * 255.0.0.0 U 40 0 0 lodefault 192.168.10.1 0.0.0.0 UG 40 0 0 eth0route del -net 192.168.10.0Multinetwork 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 network and a second with the 192.168.10.0 network. There is a firewall between the two networks, with two network cards: eth0 is attached 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.168.10.0 network.Which will in turn forward packets to the Internet.In this scenario, youd set up the firewall system with two IP addresses: 10.0.0.1 on 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 eth1route add default gw 192.168.10.1route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0On 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 eth0route add default gw 10.0.0.1This tells each computer that the default gateway is 10.0.0.1, which is your firewall/router.With both the firewall and the 10.0.0.0 network set up, you should be able to route 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 routing table a little differently. Here, you would traditionally use:route add -net 192.168.10.0 netmask 255.255.255.0 dev eth0route add default gw 192.168.10.1This 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 lost 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 statement 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.25This command tells the kernel to route all packets destined for the 10.0.0.0 network 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.