CentOS 的 ikev2网关
这个东西还是有点麻烦的,主要是坑很多
pppoe 配置略
注意:不要使用 firewalld 的 MASQUERADE
服务器端 strongswan 配置(其他内容略,只写主要的):
该配置主要是给特定的 id - > Earth 提供静态虚拟 ipconn earthleftcert=SunCert.derleftsendcert=alwaysleftid=vpn.xxx.comleftsubnet=x.x.x.x/24leftfirewall=yesleftauth=pubkeydpdaction=clearfragmentation=yesrightid="CN=Earth"auto=addrightsourceip=%config
vpn 网关的 strongswan 配置(其他内容略,只写主要的):conn sunleft=%anyleftsourceip=x.x.x.zleftcert=EarthCert.pemleftid="CN=Earth"leftfirewall=yesright=vpn.xxx.comrightsubnet=x.x.x.x/24rightid=vpn.xxx.comauto=start
这样 CentOS 网关一开机就是自动连接这个 VPN,ip 地址固定为 x.x.x.z
接下来就是比较关键的,防火墙 NAT 配置,直接使用 direct rule
不要使用 firewalld 的 MASQUERADEfirewall-cmd --direct --get-all-rulesipv4 nat POSTROUTING 5 -s 172.16.1.0/24 -o ppp0 -j MASQUERADEipv4 nat POSTROUTING 1 -d x.x.x.x/24 -o ppp0 -j SNAT --to-source x.x.x.zipv4 filter FORWARD 0 -s 172.16.1.0/24 -j ACCEPT
这是我尝试多次以后最稳定的设置,注意顺序,访问公网的 MASQUERADE 序号必须比访问 VPN 的 SNAT 大
如果要对内部访问 VPN 网络的特定地址做限制,也建议使用 direct rule
结果:
CentOS 网关自动拨号上网,给内网做正常 NAT,同时自动连接 VPN 网络,固定 ip 为 x.x.x.z,凡是访问 x.x.x.x 网络的链接都被 NAT,源地址改写为 x.x.x.z
同时其他不使用 Earth 做 id 的客户链接 VPN,保持正常的动态 ip 获取
附:
SElinux 会对 strongswan 找麻烦,如此处理ausearch -c 'starter' --raw | audit2allow -M my-startersemodule -i my-starter.ppausearch -c 'charon' --raw | audit2allow -M my-charonsemodule -i my-charon.pp