上海区域网段 上海区域外网地址 | 10.10.1.0/24 122.112.193.146 |
北京区域网段 | 10.20.1.0/24 10.20.2.0/24 |
ipsec网关地址 | 123.60.251.79 |
我是购买了上海区域得到ECS模拟云下环境,直接从创建ipsec连接开始
ssh到配置openswan的服务器,进行配置(此处用的xhsell)
安装openswan
yum -y install openswan
修改内核参数
cat <<EOF>> /etc/sysctl.conf
net.ipv4.ip_forward=1
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.eth0.send_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.eth0.accept_redirects=0
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.eth0.rp_filter=0
net.ipv4.conf.lo.rp_filter=0
EOF
使修改生效
sysctl -p
配置ipsec密钥连接文件
echo -e "122.112.193.146 123.60.251.239:PSK\"ict@2021ict\"">> /etc/ipsec.d/huawei.secrets
前面为上海区域外网地址,后面为北京区域vpn网关地址,psk与之前创建保持一致
配置ipsec的配置文件
conn huawei
authby=secret
auto=start
ikev2=never
ike=aes128-sha1;modp1536
keyexchange=ike
ikelifetime=86400s
phase2=esp
phase2alg=aes128-sha1;modp1536
compress=no
pfs=yes
salifetime=3600s
type=tunnel
left=10.10.1.156 #openswan的本地地址
leftid=122.112.193.146 #上海区域的外网地址
leftsubnet=10.10.1.0/24 #上海区域的子网网段
leftnexthop=10.10.1.1 #上海区域子网的网关地址
right=123.60.251.239 #VPN网关地址
rightid=123.60.251.239 #VPN的网关地址
rightsubnets={10.20.1.0/24,10.20.2.0/24} #北京区域需要互通的网段地址
rightnexthop=defaultroute
启动服务
systemctl start ipsec
查看服务状态
[root@ecs-openswan ~]# ipsec verify
Verifying installed system and configuration files
Version check and ipsec on-path [OK]
Libreswan 3.25 (netkey) on 3.10.0-1160.53.1.el7.x86_64
Checking for IPsec support in kernel [OK]
NETKEY: Testing XFRM related proc values
ICMP default/send_redirects [OK]
ICMP default/accept_redirects [OK]
XFRM larval drop [OK]
Pluto ipsec.conf syntax [OK]
Two or more interfaces found, checking IP forwarding [OK]
Checking rp_filter [OK]
Checking that pluto is running [OK]
Pluto listening for IKE on udp 500 [OK]
Pluto listening for IKE/NAT-T on udp 4500 [OK]
Pluto ipsec.secret syntax [OK]
Checking 'ip' command [OK]
Checking 'iptables' command [OK]
Checking 'prelink' command does not interfere with FIPS [OK]
Checking for obsolete ipsec.conf options [OK]
这里可以看到服务全部ok了,但是北京区域这边的web端一直显示未连接状态
这个问题也是困扰我好久,看了华为得到官方文档也没用,有兴趣的小伙伴可以看看华为的官网文档此处附上链接https://support.huaweicloud.com/admin-vpn/vpn_01_0007.html
后来发现那边的版本是基于Centos6.8,我们环境使用的是Centos7.6
解决问题:使用一条启动隧道的命令才可以建立连接,先关闭隧道再启动
ipsec auto --down huawei
ipsec auto --up huawei
此时已经连接状态为正常