routeThe route command can be used not only to view your routing table, but to alter it as well. You need to be careful here, however, as you can break the network and effectively landlock your computer. Let's say your machine keeps dropping the Gateway, effectively making it impossible for any packets to leave your LAN for the Internet (this really happened to me once with a box). Run the route command, verify that the Gateway is missing, and then add it in with route (although viewing the route can be done as a normal user, changes to route requires root access). # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 # route add -net default gw 192.168.0.1 dev eth0 # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 Let's break down that command. add indicates that you're adding a new route (to remove one, use del). The -net option tells the kernel that the target you're adding is a network, in this case the default destination. gw indicates that you want to route packets matching the destination (here the default, therefore utilizing a Genmask of 0.0.0.0) using a gateway at 129.168.0.1. Finally, dev eth0 specifies the device to use, in this case the Ethernet card at eth0. Let's say that in addition to your Ethernet card at eth0, you also have a wireless card at ath0. You want that wireless card to access resources on a LAN that uses 10.1.xxx.xxx as its base. You don't want the wireless card to be able to access the Internet at all. To add a route matching those criteria, you'd use these commands: # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 # route add -net 10.1.0.0 netmask 255.255.0.0 dev ath0 # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 10.1.0.0 * 255.255.0.0 U 0 0 0 ath0 default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 Here you indicated the wireless card with dev ath0, and then specified the netmask as 255.255.0.0 so routing would occur correctly. If you later want to remove that route, you'd use the following: # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 10.1.0.0 * 255.255.0.0 U 0 0 0 ath0 default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 # route del -net 10.1.0.0 netmask 255.255.0.0 dev eth0 # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 Everything is the same, except you use del instead of add. Now that's easy! |