前言:当有一个局域网络,在外想通过外网访问局域网时,可以通过VPN实现,下面是搭建局域网VPN教程,搭建完后需要在路由器配置对应的端口映射。

一、下载镜像

docker pull hwdsl2/ipsec-vpn-server:latest

二、启动容器

version: '3'
services:
  ipsec-vpn-server:
    image: hwdsl2/ipsec-vpn-server:latest
    container_name: ipsec-vpn-server
    restart: always
    privileged: true
    ports:
      - "500:500/udp"
      - "4500:4500/udp"
    volumes:
      - ./data:/lib/modules
    environment:
      - "VPN_IPSEC_PSK=123qwe"
      - "VPN_USER=admin"
      - "VPN_PASSWORD=123456"
      - "VPN_NETWORK_INTERFACE=ens33"
      - "VPN_PUBLIC_IP=192.168.17.101"
      - "VPN_ADDL_USERS=aa bb cc"
      - "VPN_ADDL_PASSWORDS=aa123 bb123 cc123"

参数解释

# VPN_IPSEC_PSK
预共享密钥
# VPN_USER
账号
# VPN_PASSWORD
密码
# VPN_NETWORK_INTERFACE
网卡
# VPN_PUBLIC_IP
公网IP,一般是家用宽带的公网IP或者企业宽带的公网IP
# VPN_ADDL_USERS
其它账号,用空格隔开
# VPN_ADDL_PASSWORDS
对应其它账号的密码,用空格隔开

启动正常

image-20210902090545338

三、连接步骤

添加VPN

image-20210902090736924

选择VPN类型,其它信息对应添上,点击保存

image-20210902091010312

点击连接即可

image-20210902091126936

连接正常

image-20210902091145954

获取IP正常

image-20210902091332288

四、常见问题

问题:

Windows10一直在连接连不上

解决:

新建两个注册表

Fix_VPN_Error_809_Windows_Vista_7_8_10_Reboot_Required.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PolicyAgent]
"AssumeUDPEncapsulationContextOnSendRule"=dword:00000002


Fix_VPN_Error_809_Allow_IPsec_Reboot_Required.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RasMan\Parameters]
"ProhibitIpSec"=dword:00000000


image-20210902090106496

双击安装,然后重启电脑即可

image-20210902090138548