由于阿里云上有一些限制,在阿里云ECS上部署待见IPSec和普通服务器有不一样的地方。

安装strongswan

apt-get update
apt-get install strongswan strongswan-plugin-xauth-generic

编辑/etc/ipsec.secrets

vi /etc/ipsec.secrets

增加:

: PSK "test"
user1 : XAUTH "user1password"

其中PSK是预共享密钥,是用于验证 L2TP/IPSec 连接的 Unicode 字符串。user1为用户名, user1password是密码。

编辑 /etc/ipsec.conf

config setup
    cachecrls=yes
    uniqueids=yes

conn ios
    keyexchange=ikev1
    authby=xauthpsk
    xauth=server
    left=%defaultroute
    leftsubnet=0.0.0.0/0
    leftfirewall=yes
    right=%any
    rightsubnet=192.168.0.1/16
    rightsourceip=192.168.0.1/16
    rightdns=223.5.5.5
    auto=add

注意使用192.168网段而不是10.0.0.1网段,10.0.0.1网段在阿里云上好像有问题(据说被禁了?)。

重启 strongswan

ipsec restart

修改阿里云服务器对应安全组规则

增加 公网入网 UDP 500和 UDP 4500两个端口

打开IPv4转发,设置NAT规则

sysctl net.ipv4.ip_forward=1

iptables -t nat -A POSTROUTING -s 192.168.0.1/16 -o eth1 -j MASQUERADE

注意是使用 eth1,而不是eth0.
ECS中eth1绑定外网网卡,eth0是内网网卡。

(转自 https://wuwawuwa.cn

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐