Strongswan搭建IPSecVPN


概述:

Strongswan是一款開源的IPSecVPN解決方案,支持ikev1和ikev2密鑰交換協議。

場景:

在StrongSwan的官網上提供了很多測試場景,依次點擊官網TestScenarios->The strongSwan test suites,即可查看(點擊直接訪問)。
列表中我們選擇ike最新版本ikev2,在本文中我們對工作中最常使用的net2net-psknet2net-rsa進行實驗模擬。

基本環境搭建:

根據拓撲圖搭建實驗環境,配置IP地址保證基本聯通性。需要注意一點,網關moon和sun需要開啟路由轉發功能ip_forward

安裝Strongswan:

可以選擇源碼編譯安裝或者使用apt/yum倉庫進行安裝:

apt install strongswan -y  #Debian/ubuntu,本文使用ubuntu16.04
yum install strongswan -y  #Centos
配置Strongswan:
相關端口:udp:500 udp:4500

相關配置文件:
/etc/ipsec.conf  #IPsec配置文件
/etc/ipsec.secret  #密鑰認證配置文件
/etc/ipsec.d  #用於存放認證證書等文件
/etc/strongswan.conf  #Strongswan配置文件
/etc/strongswan.d  #Strongswan子配置文件

相關管理命令:
ipsec start/stop/restart/reload  #啟動/停止/重啟/重載 Daemon;
ipsec up/down <connection name> #建立/斷開 指定conn鏈接;
ipsec status/statusall/listall  #IPsec相關查看命令;
配置net2net-psk

配置網關moonsunipsec.confipsec.secretsstrongswan.conf這三個配置文件<參考官網測試場景net2net-psk>:

########## Strongswan配置文件說明,以網關moon為例 ##########

# /etc/ipsec.conf - strongSwan IPsec configuration file

config setup

conn %default      #設定所有鏈接默認配置;
	ikelifetime=60m      #設定ISAKMP/IKE SA重新協商時間
	keylife=20m      #
	rekeymargin=3m
	keyingtries=1
	authby=secret      #設定認證方法,secret和psk都是預共享密鑰認證;
	keyexchange=ikev2      #設定密鑰交換協議
	mobike=no

conn net-net      #自定義conn鏈接
	left=192.168.0.1
	leftsubnet=10.1.0.0/16
	leftid=@moon.strongswan.org
	leftfirewall=yes      #自動在iptables的forward鏈中增加規則
	right=192.168.0.2
	rightsubnet=10.2.0.0/16
	rightid=@sun.strongswan.org
	auto=add      #add載入conn但不啟動,route載入conn並安裝kernel—traps同樣不啟動,start載入並啟動,ignore忽略此conn;

# /etc/ipsec.secrets - strongSwan IPsec secrets file

@moon.strongswan.org @sun.strongswan.org : PSK 0sv+NkxY9LLZvwj4qCC2o/gGrWDF2d21jL
@moon.strongswan.org %any : PSK 0x45a30759df97dc26a15b88ff 
@sun.strongswan.org : PSK "This is a strong password"  
: PSK 'My "home" is my "castle"!'
192.168.0.1 : PSK   "Andi's home"

# /etc/strongswan.conf - strongSwan configuration file

charon {
  load = random nonce aes sha1 sha2 curve25519 hmac stroke kernel-netlink socket-default updown
  multiple_authentication = no
}
root@fw1-moon:~# iptables -nvL   {leftfirewall=yes 不加也能通並且私網地址}
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  eth0   *       10.2.0.0/24          10.1.0.0/24        policy match dir in pol ipsec reqid 2 proto 50
    0     0 ACCEPT     all  --  *      eth0    10.1.0.0/24          10.2.0.0/24        policy match dir out pol ipsec reqid 2 proto 50

root@fw1-moon:~# ip route show table 220
10.2.0.0/24 via 192.168.0.2 dev eth0  proto static  src 10.1.0.1 
配置net2net-rsa


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM