linux配置路由命令

linux配置路由命令,第1张

ip rule是linux中用于配置路由命令(应该说是ip 命令的route选项),相当于

通过路由表 inr.ruhep 路由来自源地址为192.203.80/24的数据包 windows的route命令;

linux对应的用法是:

ip rule add from 192.167.80/24 table inr.ruhep prio 220 

windows 对应的用法是:

route add 192.167.80.0 mask 255.255.255.0

另外,linux还有个命令iptables功能强大得多,可以设置端口转发,以供外部的主机享用路由规则

1、查看本机路由信息

[root@Router ~]# ip route ls

192.168.70.0/24 dev eth0 proto kernel scope link src 192.168.70.70

192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.70

169.254.0.0/16 dev eth1 scope link

default via 192.168.1.1 dev eth0

2、确认是否需要改变默认路由

[root@Router ~]# ip route replace default via 192.168.70.254 dev eth0 table main

[root@Router ~]# ip route ls

192.168.70.0/24 dev eth0 proto kernel scope link src 192.168.70.70

192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.70

169.254.0.0/16 dev eth1 scope link

default via 192.168.1.1 dev eth0

3、建立特殊路由表

[root@Router ~]# vi /etc/iproute2/rt_tables

255 local

254 main

253 default

200 test

4、向test路由表中添加它自己的默认路由

[root@Router ~]# ip route add default via 192.168.1.1 table test

注意:这个table test一定不要忘了写,否则写到了主路由表中

5、先看看机器当前的ip rule

[root@Router ~]# ip rule ls

0: from all lookup local

32766: from all lookup main

32767: from all lookup default

可以看到,规则中走了3个路由表,local、main、default

我们平常用route看到的,实际是路由表main

这些规则是按序号大小顺序走的,一个不同,则走下一个,知道通路或走完为止

6、添加路由到路由表test中

[root@Router ~]# ip rule add to 59.76.0.0/16 pref 10000 table test

这个意思是说,去向IP地址范围为59.76.0.0/16的访问,则启用test的路由表中的路由规则

而test的路由规则是什么呢?上面已经设置了,走的是202.196.x.1的路由.

现在再来看一下当前的ip rule

[root@Router ~]# ip rule ls

0: from all lookup local

10000: from all to 59.76.0.0/16 lookup test

32766: from all lookup main

32767: from all lookup default


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8277773.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-14
下一篇2023-04-14

发表评论

登录后才能评论

评论列表(0条)

    保存