linux下如何设置策略路由,给举个例子说明一下哦?
答案:2 悬赏:10 手机版
解决时间 2021-11-30 19:26
- 提问者网友:却不属于对方
- 2021-11-30 10:32
linux下如何设置策略路由,给举个例子说明一下哦?
最佳答案
- 五星知识达人网友:蕴藏春秋
- 2021-11-30 11:36
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
[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
全部回答
- 1楼网友:杯酒困英雄
- 2021-11-30 12:39
ip route add 10.0.0.0/24 via 10.0.0.1
ip route add 20.0.0.0/24 via 20.0.0.1
ip route add 20.0.0.0/24 via 20.0.0.1
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯