linux route命令解析

有两块网卡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 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值