1. 安装依赖环境
yum install -y gcc make autoconf automake libtool pkgconfig flex \
bison gperf openssl-devel gmp-devel
2. 下载源码包并编译安装
①下载源码:
wget https://download.strongswan.org/strongswan-5.9.14.tar.gz
3. 配置两端IPsec第一二阶段配置文件 ① 配置Centos客户端 配置文件路径: /usr/local/strongswan/config/ipsec.conf 建议修改前,先备份一份原有的配置文件 ② 配置深信服防火墙 4. 放通防火墙规则 5. 开启Centos流量转发 6. 查看连接状态及测试两端网络是否打通 # 查看连接状态 # 测试网络联通性 7. 后续优化 # 通过systemctl进行服务管理 # 增加开机启动tar -zxvf strongswan-5.9.14.tar.gz
./configure --prefix=/usr/local/strongswan \
--sysconfdir=/usr/local/strongswan/config \
--enable-eap-identity \
--enable-eap-md5 \
--enable-eap-mschapv2 \
--enable-eap-tls \
--enable-eap-ttls \
--enable-eap-peap \
--enable-eap-tnc \
--enable-eap-dynamic \
--enable-xauth-eap \
--enable-nat-transport \
--enable-opensslmake && make install
config setup
charondebug="ike 2, cfg 2" # 调试日志
uniqueids=no # 允许重复ID
conn sangfor-aggressive
# 协议模式
keyexchange=ikev1 # 强制IKEv1
aggressive=yes # 启用野蛮模式
type=tunnel # 隧道模式
# 本地配置
left=%any # 动态IP适用
leftsubnet=192.168.246.128/32 # 本地子网
leftid=@ddsh.vpn.com # 本地标识(两端配置需一致)
# 对端配置
right=1.2.6.1 # 对端公网IP
rightsubnet=172.16.0.0/24 # 对端内网
rightid=@test.vpn.com # 对端标识
# 第一阶段参数
ike=aes256-sha256-modp1024 # 加密/HASH/DH组
ikelifetime=86400s # SA生命周期
# 第二阶段参数
esp=aes256-sha1 # ESP加密组合
lifetime=3600s # IPSec SA超时
authby=secret # 预共享密钥(指定为文件)
auto=start # 自动发起连接#编辑预共享密钥文件
vi /usr/local/strongswan/conf/ipsec.secrets
# ipsec.secrets - strongSwan IPsec secrets file
1.2.6.1 @test : PSK "test@1234."#添加防火墙端口规则
firewall-cmd --zone=public --add-protocol=esp --permanent
firewall-cmd --zone=public --add-port=500/udp --permanent
firewall-cmd --zone=public --add-port=4500/udp --permanent
#重载防火墙规则
firewall-cmd –reload
#确定开放端口列表
firewall-cmd --zone=public --list-ports# 临时开启流量转发
echo 1 > /proc/sys/net/ipv4/ip_forward
# 永久开启流量转发
1. 打开/etc/sysctl.conf
vi /etc/sysctl.conf
2. 文件中添加如下配置
net.ipv4.ip_forward = 1
# 生效配置
sysctl -p[Unit]
Description=strongSwan IPsec IKEv1/IKEv2 daemon
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/strongswan/sbin/ipsec start
ExecStop=/usr/local/strongswan/sbin/ipsec stop
ExecReload=/usr/local/strongswan/sbin/ipsec reload
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target生效systemctl文件:
systemctl daemon-reload
启动服务:
systemctl start strongswan
设置开机启动:
systemctl enable strongswan
本文链接:https://www.kinber.cn/post/5210.html 转载需授权!
推荐本站淘宝优惠价购买喜欢的宝贝: