IPsec(Internet Protocol Security)是一种用于加密和认证网络通信的协议套件,常用于构建VPN(虚拟专用网络)。以下是IPsec的详细配置说明,涵盖主流操作系统和设备:
bash
# Linux (strongSwan)
sudo systemctl start strongswan
bash
# /etc/ipsec.conf 示例(strongSwan)
conn myvpn
authby=secret
left=192.168.1.1 # 本地公网IP
leftsubnet=10.0.1.0/24 # 本地内网
right=203.0.113.2 # 对端公网IP
rightsubnet=10.0.2.0/24 # 对端内网
ike=aes256-sha256-modp2048!
esp=aes256-sha256!
keyingtries=0
ikelifetime=8h
lifetime=1h
auto=start
bash
# /etc/ipsec.secrets
192.168.1.1 203.0.113.2 : PSK "YourSharedKey"
bash
sudo ipsec restart
sudo ipsec status
bash
sudo apt install strongswan
bash
sudo ipsec up myvpn
sudo tail -f /var/log/syslog
powershell
Add-VpnConnection -Name "IPsec VPN" -ServerAddress "203.0.113.2" -TunnelType IKEv2 -EncryptionLevel Required -AuthenticationMethod MachineCertificate
crypto ikev2 policy MY_POLICY
encryption aes-cbc-256
integrity sha256
group 14
!
crypto ipsec profile MY_PROFILE
set ikev2-profile MY_POLICY
!
interface Tunnel0
tunnel protection ipsec profile MY_PROFILE
config vpn ipsec phase1-interface
edit "VPN_to_Remote"
set interface "wan1"
set ike-version 2
set peertype any
set net-device enable
set proposal aes256-sha256
set dhgrp 14
set remote-gw 203.0.113.2
set psksecret ENC YourSharedKey
next
end
tcpdump
抓包:
bash
sudo tcpdump -i eth0 udp port 500 or port 4500
ip route show table all
。/var/log/syslog
或 journalctl -u strongswan
。通过以上步骤,您可以完成IPsec的配置并建立安全的加密隧道。如需更复杂的场景(如跨云厂商互联),需结合具体环境调整参数。