Linux路由表的含义及使用

本机ip地址 eth0 : 192.168.11.100
[root@localhost /]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags   Metric     Ref        Use   Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG      0          0          0     eth0
169.254.0.0     0.0.0.0         255.255.0.0     U       1002       0          0     eth0
192.168.11.0    0.0.0.0         255.255.255.0   U       0          0          0     eth0
1.  路由表的匹配规则是,dst ip 与Genmask做与运算,如果和Destination一样,修改目的mac地址,将数据包发往 Gateway
2.  Gateway是0.0.0.0,表示发送到的目的IP地址不需要路由。eg. 192.168.11.100->192.168.11.101 一个网段中不需要路由
3.  路由顺序: eg. 192.168.11.100 -> 152.115.263.325 出的时候走的是第一条default路由,进来的时候走的是第三条路由
4.  默认路由是最后执行的,表示其它路由项都不符合条件。
5.  ping 百度   
[root@localhost /]# ping www.baidu.com

PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=55 time=23.9 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=55 time=23.6 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 23.626/23.776/23.927/0.215 ms

根据ip地址配置一条路由信息:
[root@localhost /]# route add -net 61.135.0.0/16 dev eth0

显示如下:
[root@localhost /]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 eth0
61.135.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

再ping百度
[root@localhost /]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 2999ms
[root@localhost /]# 
6.  一些基本命令:

route add -net 17.1.0.0 netmask 255.255.0.0 dev port4
route add -net 17.1.0.0 netmask 255.255.0.0 gw 17.1.1.1 dev port4
route add -net 61.135.0.0/ netmask 255.255.0.0 dev eth0
route add -net 61.135.0.0/16 dev eth0
route del -net 61.135.0.0/16 dev eth0
route add -host 61.135.185.32/32 dev eth0
route del -host 61.135.185.32
route add -net 17.1.1.0/24  dev eth1
route add -net 0.0.0.0/24 gw 17.1.1.1 dev eth1
route del -net 0.0.0.0/24 gw 17.1.1.1 dev eth1
route del -net 17.1.1.0/24

7.

https://blog.csdn.net/centerpoint/article/details/37601477
操作系统上静态路由优先, 路由设备上直连路由优先.  当然这都是在相同网段的前提下, 在网段不同的时候, 都遵循深度优先原则, 即网段越小优先级越高.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值