浏览:67 时间:2025-09-18
IPsec(Internet Protocol Security)是一种网络协议套件,通过对IP数据包进行加密和认证来保护网络通信安全。通过OpenWrt搭建IPsec隧道,可以实现:
在开始配置前,请确保:
通过SSH登录OpenWrt,安装IPsec相关组件:
opkg update
opkg install strongswan-full
修改/etc/ipsec.conf:
config setup
charondebug="all"
uniqueids=yes
conn %default
ikelifetime=60m
keylife=20m
rekeymargin=3m
keyingtries=1
keyexchange=ikev2
authby=secret
conn site-to-site
left=本地公网IP
leftsubnet=本地子网
leftid=本地标识
right=远程公网IP
rightsubnet=远程子网
rightid=远程标识
auto=start
编辑/etc/ipsec.secrets:
本地公网IP 远程公网IP : PSK "你的预共享密钥"
确保允许IPsec相关流量:
# 允许IKE协商(UDP 500)
# 允许NAT-T(UDP 4500)
# 允许ESP协议(IP协议50)
启动IPsec服务:
/etc/init.d/strongswan start
/etc/init.d/strongswan enable
检查连接状态:
ipsec status
通过本教程,您应该能够成功在OpenWrt上搭建稳定的IPsec隧道。如需更高级配置,请参考StrongSwan官方文档。