有两块网卡if1和if2
eth0: 192.168.10.23/255.255.255.0
eth1: 192.168.20.22/255.255.255.0
添加路由命令如下
route add -net 192.168.10.0 netmask 255.255.255.0 dev eth0
route add -net 192.168.20.0 netmask 255.255.255.0 dev eth1
通过上面两个命令, 发往192.168.10.0网段的IP包会通过eth0发送, 发往192.168.20.0网段的IP包会通过eth1发送.
如果其它网段的IP包如何发送? 需要设置一个默认网关, 命令如下
route add default gw 192.168.20.1
通过上面命令, 会将除了这两个网络的IP包都发往192.168.20.1网关, 如何转发到192.168.20.1网关? 在上面的两条路由项中已经定义了, 会通过eth1网口转发,
通过 route -n 命令查看默认网关
通过 route del -net 192.168.10.0 netmask 255.255.255.0 命令可以删除此指定路由项
130|shell@android:/etc # busybox route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 202 0 0 eth0
192.168.1.0 * 255.255.255.0 U 202 0 0 eth0
192.168.1.1 * 255.255.255.255 UH 0 0 0 eth0
eth0 Link encap:Ethernet HWaddr BE:8A:A6:64:BA:E0
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fd04:25bf:4e57:0:bc8a:a6ff:fe64:bae0/64 Scope:Global
inet6 addr: fe80::bc8a:a6ff:fe64:bae0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:224 errors:0 dropped:0 overruns:0 frame:0
TX packets:231 errors:4 dropped:0 overruns:0 carrier:4
collisions:0 txqueuelen:1000
RX bytes:40108 (39.1 KiB) TX bytes:139234 (135.9 KiB)
Interrupt:114 Base address:0x4000