使用 Docker 快速架设一个 IPSec VPN Server

仅作记录使用,环境为 Ubuntu 18.04 LTS

Docker Image 来自 hwdsl2/docker-ipsec-vpn-server

# Install docker
apt update
apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update
apt install docker-ce docker-ce-cli containerd.io

# Pull the docker image
docker pull hwdsl2/ipsec-vpn-server

之后创建一个 env 文件规定 IPSec 使用的 PSK、用户名和密码,假设存储在 /home/user/.config/vpn.env

# Define your own values for these variables
# - DO NOT put "" or '' around values, or add space around =
# - DO NOT use these special characters within values: \ " '
VPN_IPSEC_PSK=your_ipsec_pre_shared_key
VPN_USER=your_vpn_username
VPN_PASSWORD=your_vpn_password

# (*Optional*) Define additional VPN users
# - Uncomment and replace with your own values
# - DO NOT put "" or '' around values, or add space around =
# - Usernames and passwords must be separated by spaces
# VPN_ADDL_USERS=additional_username_1 additional_username_2
# VPN_ADDL_PASSWORDS=additional_password_1 additional_password_2

# (*Optional*) Use alternative DNS servers
# - Uncomment and replace with your own values
# - By default, clients are set to use Google Public DNS
# - Example below shows Cloudflare's DNS service
# VPN_DNS_SRV1=1.1.1.1
# VPN_DNS_SRV2=1.0.0.1

# (*Optional*) Advanced users can set up IKEv2. See:
# https://git.io/ikev2docker

使用 systemd 开机自启动,假设文件在 /etc/systemd/system/ipsec.service:

[Unit]
Description=IPSec Docker
After=docker.service
Requires=docker.service

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
ExecStartPre=-/usr/bin/docker stop ipsec-vpn-server
ExecStartPre=-/usr/bin/docker rm ipsec-vpn-server
ExecStart=/usr/bin/docker run --name ipsec-vpn-server --env-file /home/user/.config/vpn.env --restart=always -p 500:500/udp -p 4500:4500/udp -d --privileged hwdsl2/ipsec-vpn-server
ExecStop=/usr/bin/docker stop ipsec-vpn-server
ExecStopPost=/usr/bin/docker rm ipsec-vpn-server

[Install]
WantedBy=multi-user.target

之后使用 docker logs ipsec-vpn-server 就能看到本次使用的登录凭据。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注