荣耀之链论坛

 找回密码
 立即注册
搜索
查看: 629|回复: 3

IKEV2

[复制链接]

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
发表于 2023-5-12 10:20 | 显示全部楼层 |阅读模式
这个是介绍
https://github.com/hwdsl2/setup- ... s/ikev2-howto-zh.md

这个是docker
https://github.com/hwdsl2/docker ... master/README-zh.md


  1. 先编辑环境配置文件
  2. VPN_PUBLIC_IP=192.168.11.157
  3. VPN_IPSEC_PSK=yourpsk
  4. VPN_USER=admin
  5. VPN_PASSWORD=Admin@123456

  6. VPN_ADDL_USERS=user1 user2
  7. VPN_ADDL_PASSWORDS=User1@123456 User2@123456

  8. 公共IP填外网IP,这个IP服务器和客户端要一致,我是内网测试,所以用的内网IP



  9. docker run \
  10. --name ikev2_8 \
  11. --env-file /root/docker/ikev2/vpn.env \
  12. --restart=unless-stopped \
  13. -v /root/docker/ikev2/ikev2-vpn-data:/etc/ipsec.d \
  14. -v /lib/modules:/lib/modules:ro \
  15. -p 500:500/udp \
  16. -p 4500:4500/udp \
  17. --network=docker_bridge_192_168_21 --ip=192.168.21.8 \
  18. -e TZ=Asia/Shanghai \
  19. -d --privileged \
  20. hwdsl2/ipsec-vpn-server

  21. 查看日志
  22. docker logs ikev2_8
  23. 输出如下信息说明成功了,如果没成功看看提示什么,再解决

  24. Trying to auto discover IP of this server...

  25. Starting IPsec service...

  26. ================================================

  27. IPsec VPN server is now ready for use!

  28. Connect to your new VPN with these details:

  29. Server IP: 192.168.11.157
  30. IPsec PSK: yourpsk
  31. Username: admin
  32. Password: Admin@123456

  33. Additional VPN users (username | password):
  34. user1 | User1@123456
  35. user2 | User2@123456

  36. Write these down. You'll need them to connect!

  37. VPN client setup: https://vpnsetup.net/clients2

  38. ================================================

  39. Setting up IKEv2. This may take a few moments...


  40. 然后服务器放行500 4500这2个UDP端口


  41. 客户端连接:

  42. 下载证书
  43. docker cp ikev2_8:/etc/ipsec.d/vpnclient.p12 /root/docker/ikev2/

  44. WIN10客户端安装方式:
  45. 把下面的内容保存为批处理,然后把批处理和证书文件放在同一个目录,然后运行批处理就行了

  46. @echo off
  47. :: IKEv2 Configuration Import Helper Script for Windows 8, 10 and 11
  48. :: Copyright (C) 2022 Lin Song <linsongui@gmail.com>
  49. :: This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
  50. :: Unported License: http://creativecommons.org/licenses/by-sa/3.0/
  51. :: Attribution required: please include my name in any derivative and let me
  52. :: know how you have improved it!

  53. setlocal DisableDelayedExpansion
  54. set "SPath=%SystemRoot%\System32"
  55. if exist "%SystemRoot%\Sysnative\reg.exe" (set "SPath=%SystemRoot%\Sysnative")
  56. set "Path=%SPath%;%SystemRoot%;%SPath%\Wbem;%SPath%\WindowsPowerShell\v1.0"
  57. set "_err====== ERROR ====="
  58. set "_work=%~dp0"
  59. if "%_work:~-1%"=="" set "_work=%_work:~0,-1%"

  60. for /f "tokens=4-5 delims=. " %%i in ('ver') do set version=%%i.%%j
  61. if "%version%" == "10.0" goto :Check_Admin
  62. if "%version%" == "6.3" goto :Check_Admin
  63. if "%version%" == "6.2" goto :Check_Admin
  64. goto :E_Win

  65. :Check_Admin
  66. reg query HKU\S-1-5-19 >nul 2>&1 || goto :E_Admin

  67. where certutil >nul 2>&1
  68. if %errorlevel% neq 0 goto :E_Cu
  69. where powershell >nul 2>&1
  70. if %errorlevel% neq 0 goto :E_Ps

  71. title IKEv2 Configuration Import Helper Script
  72. setlocal EnableDelayedExpansion
  73. cd /d "!_work!"
  74. @cls
  75. echo ===================================================================
  76. echo Welcome^^! Use this helper script to import an IKEv2 configuration
  77. echo into a PC running Windows 8, 10 or 11.
  78. echo For more details, see https://vpnsetup.net/ikev2
  79. echo.
  80. echo Before continuing, you must put the .p12 file you transferred from
  81. echo the VPN server in the *same folder* as this script.
  82. echo ===================================================================

  83. set client_name_gen=
  84. for /F "eol=| delims=" %%f in ('dir "*.p12" /A-D /B /O-D /TW 2^>nul') do (
  85.   set "p12_latest=%%f"
  86.   set "client_name_gen=!p12_latest:.p12=!"
  87.   goto :Enter_Client_Name
  88. )

  89. :Enter_Client_Name
  90. echo.
  91. echo Enter the name of the IKEv2 VPN client to import.
  92. echo Note: This is the same as the .p12 filename without extension.
  93. set client_name=
  94. set p12_file=
  95. if defined client_name_gen (
  96.   echo To accept the suggested client name, press Enter.
  97.   set /p client_name="VPN client name: [%client_name_gen%] "
  98.   if not defined client_name set "client_name=%client_name_gen%"
  99. ) else (
  100.   set /p client_name="VPN client name: "
  101.   if not defined client_name goto :Abort
  102. )
  103. set "client_name=%client_name:"=%"
  104. set "client_name=%client_name: =%"
  105. set "p12_file=%_work%\%client_name%.p12"
  106. if not exist "!p12_file!" (
  107.   echo.
  108.   echo ERROR: File "!p12_file!" not found.
  109.   echo You must put the .p12 file you transferred from the VPN server
  110.   echo in the *same folder* as this script.
  111.   goto :Enter_Client_Name
  112. )

  113. echo.
  114. echo Enter the IP address (or DNS name) of the VPN server.
  115. echo Note: This must exactly match the VPN server address in the output
  116. echo of the IKEv2 helper script on your server.
  117. set server_addr=
  118. set /p server_addr="VPN server address: "
  119. if not defined server_addr goto :Abort
  120. set "server_addr=%server_addr:"=%"
  121. set "server_addr=%server_addr: =%"

  122. set "conn_name_gen=IKEv2 VPN %server_addr%"
  123. powershell -command "Get-VpnConnection -Name '%conn_name_gen%'" >nul 2>&1
  124. if !errorlevel! neq 0 (
  125.   goto :Enter_Conn_Name
  126. )
  127. set "conn_name_gen=IKEv2 VPN 2 %server_addr%"
  128. powershell -command "Get-VpnConnection -Name '%conn_name_gen%'" >nul 2>&1
  129. if !errorlevel! neq 0 (
  130.   goto :Enter_Conn_Name
  131. )
  132. set "conn_name_gen=IKEv2 VPN 3 %server_addr%"
  133. powershell -command "Get-VpnConnection -Name '%conn_name_gen%'" >nul 2>&1
  134. if !errorlevel! equ 0 (
  135.   set conn_name_gen=
  136. )

  137. :Enter_Conn_Name
  138. echo.
  139. echo Provide a name for the new IKEv2 connection.
  140. set conn_name=
  141. if defined conn_name_gen (
  142.   echo To accept the suggested connection name, press Enter.
  143.   set /p conn_name="IKEv2 connection name: [%conn_name_gen%] "
  144.   if not defined conn_name set "conn_name=%conn_name_gen%"
  145. ) else (
  146.   set /p conn_name="IKEv2 connection name: "
  147.   if not defined conn_name goto :Abort
  148. )
  149. set "conn_name=%conn_name:"=%"
  150. powershell -command "Get-VpnConnection -Name '%conn_name%'" >nul 2>&1
  151. if !errorlevel! equ 0 (
  152.   echo.
  153.   echo ERROR: A connection with this name already exists.
  154.   goto :Enter_Conn_Name
  155. )

  156. echo.
  157. echo Importing .p12 file...
  158. certutil -f -p "" -importpfx "%p12_file%" NoExport >nul 2>&1
  159. if !errorlevel! equ 0 goto :Create_Conn
  160. echo When prompted, enter the password for client config files, which can be found
  161. echo in the output of the IKEv2 helper script on your server.
  162. :Import_P12
  163. certutil -f -importpfx "%p12_file%" NoExport
  164. if !errorlevel! neq 0 goto :Import_P12

  165. :Create_Conn
  166. echo.
  167. echo Creating VPN connection...
  168. powershell -command "Add-VpnConnection -ServerAddress '%server_addr%' -Name '%conn_name%' -TunnelType IKEv2 -AuthenticationMethod MachineCertificate -EncryptionLevel Required -PassThru"
  169. if !errorlevel! neq 0 (
  170.   echo ERROR: Could not create the IKEv2 VPN connection.
  171.   goto :Done
  172. )

  173. echo Setting IPsec configuration...
  174. powershell -command "Set-VpnConnectionIPsecConfiguration -ConnectionName '%conn_name%' -AuthenticationTransformConstants GCMAES128 -CipherTransformConstants GCMAES128 -EncryptionMethod AES256 -IntegrityCheckMethod SHA256 -PfsGroup None -DHGroup Group14 -PassThru -Force"
  175. if !errorlevel! neq 0 (
  176.   echo ERROR: Could not set IPsec configuration for the IKEv2 VPN connection.
  177.   goto :Done
  178. )

  179. echo IKEv2 configuration successfully imported^^!
  180. echo To connect to the VPN, click on the wireless/network icon in your system tray,
  181. echo select the "%conn_name%" VPN entry, and click Connect.
  182. goto :Done

  183. :E_Admin
  184. echo %_err%
  185. echo This script requires administrator privileges.
  186. echo Right-click on the script and select 'Run as administrator'.
  187. goto :Done

  188. :E_Win
  189. echo %_err%
  190. echo This script requires Windows 8, 10 or 11.
  191. echo Windows 7 users can manually import IKEv2 configuration. See https://vpnsetup.net/ikev2
  192. goto :Done

  193. :E_Cu
  194. echo %_err%
  195. echo This script requires 'certutil', which is not detected.
  196. goto :Done

  197. :E_Ps
  198. echo %_err%
  199. echo This script requires 'powershell', which is not detected.
  200. goto :Done

  201. :Abort
  202. echo.
  203. echo Abort. No changes were made.

  204. :Done
  205. echo.
  206. echo Press any key to exit.
  207. pause >nul
  208. goto :eof


  209. linux客户端和iphone客户端自己看教程吧
  210. 特别是linux客户端,教程写的太不完善了,我用rockylinux8的minimal模式 死活不能连上

  211. 写在最后
  212. WIN10客户端连上了,然后服务端没有IP 这个模式和L2TP不一样,不知道怎么ping服务端了,也许服务端也需要一个docker-ikev2-client
  213. 估计这样才能ping通吧
复制代码


回复

使用道具 举报

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
 楼主| 发表于 2023-5-15 15:34 | 显示全部楼层
用docker配置完毕 但是WIN10连接的时候提示

IKE 身份验证凭证不可接受

用教程里面提供的批处理文件,创建的VPN链接正常连接上了

但是有个问题

客户端获取到了IP
但是IKEV2服务器端没有IP啊

这样怎么做端口转发?  

访问服务器的端口自动转发到VPN客户端 这个需求用PPTP和L2TP都可以做到,但是IKEV2做不到
这个需求我大概明白是什么实现了,需要在服务器上也安装IKEV2客户端
这样服务器和我家里的电脑就属于同一个网络了,就可以转发了,有点麻烦

IKEV2和L2TP的使用上还是有些区别的

感觉还是L2TP简单明了  手动添加路由表就可以实现各个地区的公司内网互访  
IKEV2感觉就是想把用户当傻瓜,自动同步各个客户端的路由表,我觉得有点过犹不及了


回复 支持 反对

使用道具 举报

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
 楼主| 发表于 2023-5-15 16:01 | 显示全部楼层
总结一下:
用docker一个命令配置IKEV2服务端
  1. docker run \
  2.     --name ipsec-vpn-server \
  3.     --restart=always \
  4.     -v ikev2-vpn-data:/etc/ipsec.d \
  5.     -v /lib/modules:/lib/modules:ro \
  6.     -p 500:500/udp \
  7.     -p 4500:4500/udp \
  8.     -d --privileged \
  9.     hwdsl2/ipsec-vpn-server
复制代码


然后服务器放行1701 500 4500这3个UDP端口

然后输入命令
  1. docker logs ipsec-vpn-server
复制代码
查看用户名和密码
里面还有psk,好像这个psk客户端不需要关注

最后就是客户端配置
Client configuration is available inside the
Docker container at:
/etc/ipsec.d/vpnclient.p12 (for Windows & Linux)
/etc/ipsec.d/vpnclient.sswan (for Android)
/etc/ipsec.d/vpnclient.mobileconfig (for iOS & macOS)


win10客户端配置 需要把证书下载下来
  1. docker cp ipsec-vpn-server:/etc/ipsec.d/vpnclient.p12 ./
复制代码

然后把证书下载到本地
然后根据这个教程
https://github.com/hwdsl2/setup- ... s/ikev2-howto-zh.md
先下载cmd脚本 用这个脚本自动的配置连接 就行了




我按照他的教程手动创建的链接,证书导入了,注册表也改了,结果死活提示  IKE 身份验证凭证不可接受
最后我用他的批处理就行了


回复 支持 反对

使用道具 举报

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
 楼主| 发表于 2023-5-15 16:16 | 显示全部楼层
https://developer.aliyun.com/ask/53504

如何通过strongswan等工具搭建IKEv2 VPN服务,从而远程组建办公局域网?
希望通过strongswan等工具,搭建一个IKEv2的VPN隧道,将不同地区的员工组成内网通讯,但各自外网流量不经过vpn。

设备:
    1. 阿里云ECS充当VPN主机,安装strongswan搭建IKEv2 VPN服务;
    2. 公司电脑A,同事电脑B,同事电脑C;

需要效果:
    3. 电脑A、B、C三者使用各自账号连接VPN服务后,取得对应的固定虚拟IP地址;
    4. 电脑A、B、C三者之间可以互相通讯,但不能访问VPN主机的资源;
    5. 电脑A、B、C三者访问的外网流量不经过VPN,直接使用本地互联网;




这个是阿里云上一个用户的提问,最后他的需求没有得到解决
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

荣耀之链

GMT+8, 2025-6-18 05:12 , Processed in 0.013375 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表