通信人家园

 找回密码
 注册

只需一步,快速开始

短信验证,便捷登录

搜索
查看: 1359|回复: 0
打印

公网隧道 [复制链接]

军衔等级:

  新兵

注册:2016-12-7
跳转到指定楼层
1#
发表于 2021-8-11 10:10:48 |只看该作者 |倒序浏览
开启内核路由转发:
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf sysctl -p  
加载GRE内核模块
需要加载ip_gre内核模块,并设置开机自动加载
modprobe ip_gre
设置开机自动加载
echo "/sbin/modprobe ip_gre > /dev/null2>&1"> /etc/sysconfig/modules/ip_gre.modules && chmod 755/etc/sysconfig/modules/ip_gre.modules
在主机1上执行:
modprobe ip_gre
ip tunnel add tun1 mode gre remote 112.35.99.17 local 10.0.3.5 #建立隧道ip link set tun1 up  #拉起tun1ip addr add 172.16.0.1 peer 172.16.0.2 dev tun1  #设置互联IProute add -net 192.168.0.0/24 dev tun1  #添加对端网段静态路由
主机2上执行(与1主机相反):
modprobe ip_greip tunnel add tun1 mode gre remote 36.156.154.210 local 192.168.0.236   ##建立tunnel隧道ip link set tun1 up  ##拉起ip addr add 172.16.0.2 peer 172.16.0.1 dev tun1 ##设置互联IProute add -net 10.0.0.0/20 dev tun1 ##添加对端网段的静态路由
从主机1 ,ping主机2 内网IP:
[root@lishf-gre-test01 ~]# ping 192.168.0.236PING 192.168.0.236 (192.168.0.236) 56(84) bytes of data.64 bytes from 192.168.0.236: icmp_seq=1 ttl=64 time=22.5 ms64 bytes from 192.168.0.236: icmp_seq=2 ttl=64 time=22.5 ms64 bytes from 192.168.0.236: icmp_seq=3 ttl=64 time=22.5 ms64 bytes from 192.168.0.236: icmp_seq=4 ttl=64 time=22.5
从主机2,ping主机1内网IP:
[root@lishf-gre-test02 ~]# ping 10.0.3.5PING 10.0.3.5 (10.0.3.5) 56(84) bytes of data.64 bytes from 10.0.3.5: icmp_seq=1 ttl=64 time=28.7 ms64 bytes from 10.0.3.5: icmp_seq=2 ttl=64 time=28.4 ms64 bytes from 10.0.3.5: icmp_seq=3 ttl=64 time=28.4 ms
若想要双方子网内的主机,能够ping通对端子网任意内网IP,则需在两侧的vpc上添加对侧网段路由,下一跳为本侧配置好的网关(vm内网IP)。
需要在2台云主机的安全组中配置GRE协议
######重要,如果需要开机启动,需要参考以下配置######
配置GRE隧道tunnel开机自动执行,新建一个/etc/init.d/gre.sh,将该文件加载到开机启动的系统文件/etc/rc.d/rc.local中
主机1机器执行
vi /etc/init.d/gre.sh
#把下面的内容添加进去
modprobe ip_gre
ip tunnel add tun1 mode gre remote 112.35.99.17 local 10.0.3.5 #建立隧道ip link set tun1 up  #拉起tun1ip addr add 172.16.0.1 peer 172.16.0.2 dev tun1  #设置互联IProute add -net 192.168.0.0/24 dev tun1  #添加对端网段静态路由
#vi保存
#执行命令

举报本楼

您需要登录后才可以回帖 登录 | 注册 |

手机版|C114 ( 沪ICP备12002291号-1 )|联系我们 |网站地图  

GMT+8, 2024-5-12 02:09 , Processed in 0.224638 second(s), 15 queries , Gzip On.

Copyright © 1999-2023 C114 All Rights Reserved

Discuz Licensed

回顶部