0
点赞
收藏
分享

微信扫一扫

GRE隧道+策略路由,实现路由转发

GRE隧道+策略路由

image.png

徐州上的配置

加载模块

modprobe ip_gre

开启转发

/etc/sysctl.conf
net.ipv4.ip_forward = 1

防火墙设置

iptables -t nat -A POSTROUTING -j MASQUERADE

徐州-韩国隧道(模拟专线)

ip tunnel add tunnel2 mode gre local 2.2.2.2 remote 4.4.4.4 ttl 255
ip addr add 172.16.33.1 dev tunnel2 peer 172.16.33.2/32
ip link set tunnel2 up

徐州-美国隧道(模拟专线)

ip tunnel add tunnel3 mode gre local 2.2.2.2 remote 3.3.3.3 ttl 255
ip addr add 172.16.34.1 dev tunnel3 peer 172.16.34.2/32
ip link set tunnel3 up

徐州-扬州隧道

ip tunnel add tunnel4 mode gre local 2.2.2.2 remote 1.1.1.1 ttl 255
ip addr add 172.16.35.1 dev tunnel4 peer 172.16.35.2/32
ip link set tunnel4 up

韩国配置

加载模块

modprobe ip_gre

开启转发

/etc/sysctl.conf
net.ipv4.ip_forward = 1

防火墙设置

iptables -t nat -A POSTROUTING -j MASQUERADE

徐州-韩国隧道(模拟专线)

ip tunnel add tunnel2 mode gre local 4.4.4.4 remote 2.2.2.2 ttl 255
ip addr add 172.16.33.2 dev tunnel2 peer 172.16.33.1/32
ip link set dev tunnel2 up

美国配置

加载模块

modprobe ip_gre

开启转发

/etc/sysctl.conf
net.ipv4.ip_forward = 1

防火墙设置

iptables -t nat -A POSTROUTING -j MASQUERADE

徐州-美国隧道(模拟专线)

ip tunnel add tunnel3 mode gre local 3.3.3.3 remote 2.2.2.2 ttl 255
ip addr add 172.16.34.2 dev tunnel3 peer 172.16.34.1/32
ip link set dev tunnel3 up

扬州配置

加载模块

modprobe ip_gre

开启转发

/etc/sysctl.conf
net.ipv4.ip_forward = 1

防火墙设置

iptables -t nat -A POSTROUTING -j MASQUERADE

徐州-扬州隧道

ip tunnel add tunnel4 mode gre local 1.1.1.1 remote 2.2.2.2 ttl 255
ip addr add 172.16.35.2 dev tunnel4 peer 172.16.35.1/32
iptables -A INPUT -s 2.2.2.2 -j ACCEPT

添加策略路由

扬州节点

添加路由表,以国家代码命名,以韩国为例

echo 100	kr >>/etc/iproute2/rt_tables

添加路由, 访问韩国的ip,进入kr表

ip rule to 24.53.192.0/19 table kr

在kr表添加规则,访问韩国的ip,下一跳是 徐州

ip route add 24.53.192.0/19 via 172.16.35.1 table kr

徐州节点

添加路由表,以国家代码命名,以韩国为例

echo 100	kr >>/etc/iproute2/rt_tables

添加路由, 访问韩国的ip,进入kr表

ip rule to 24.53.192.0/19 table kr

在kr表添加规则,访问韩国的ip,下一跳是 韩国

注意:

在路由规则需要单独配置: 徐州连接韩国节点的IP,通过默认网关出去,不能走隧道

因为徐州-韩国隧道是通过公网IP连接的

ip route add 24.53.192.0/19 via 172.16.33.2 table kr

完成!

问题:

隧道的ip和策略路由在服务器重启后就失效了,需要添加脚本,在启动时自动加载配置。

举报

相关推荐

0 条评论