All Projects → hwdsl2 → Docker Ipsec Vpn Server

hwdsl2 / Docker Ipsec Vpn Server

Licence: other
Docker image to run an IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2

Programming Languages

shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to Docker Ipsec Vpn Server

Setup Ipsec Vpn
Scripts to build your own IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2
Stars: ✭ 16,987 (+289.97%)
Mutual labels:  network, vpn, vpn-client, vpn-server, encryption, ipsec, ikev2, l2tp, libreswan, cisco-ipsec
Algo
Set up a personal VPN in the cloud
Stars: ✭ 24,275 (+457.28%)
Mutual labels:  vpn, vpn-client, vpn-server, encryption, ipsec, ikev2
Aws Vpn Server Setup
Setup your own private, secure, free* VPN on the Amazon AWS Cloud in 10 minutes. CloudFormation
Stars: ✭ 672 (-84.57%)
Mutual labels:  vpn, vpn-client, vpn-server, encryption, ipsec
Strongswan
strongSwan - IPsec-based VPN
Stars: ✭ 1,112 (-74.47%)
Mutual labels:  vpn, vpn-client, vpn-server, ipsec
Wg Install
Wireguard road warrior installer for Ubuntu, Debian, CentOS and Fedora
Stars: ✭ 99 (-97.73%)
Mutual labels:  vpn, vpn-client, vpn-server, encryption
Softethervpn
Cross-platform multi-protocol VPN software. Pull requests are welcome. The stable version is available at https://github.com/SoftEtherVPN/SoftEtherVPN_Stable.
Stars: ✭ 8,531 (+95.84%)
Mutual labels:  vpn, vpn-server, ipsec, l2tp
KidVPN
The world's smallest VPN server and client.
Stars: ✭ 63 (-98.55%)
Mutual labels:  vpn, vpn-server, vpn-client
Vpncn.github.io
2021中国翻墙软件VPN推荐以及科学上网避坑,稳定好用。对比SSR机场、蓝灯、V2ray、老王VPN、VPS搭建梯子等科学上网与翻墙软件,中国最新科学上网翻墙梯子VPN下载推荐。
Stars: ✭ 3,925 (-9.89%)
Mutual labels:  vpn, vpn-client, vpn-server
Ovpm
OpenVPN Management Server - Effortless and free OpenVPN server administration
Stars: ✭ 256 (-94.12%)
Mutual labels:  network, vpn, vpn-server
Shadowsocks Heroku
本项目已删除
Stars: ✭ 224 (-94.86%)
Mutual labels:  vpn, vpn-client, vpn-server
Subnet
Simple, auditable & elegant VPN, built with TLS mutual authentication and TUN.
Stars: ✭ 1,040 (-76.12%)
Mutual labels:  vpn, vpn-client, vpn-server
Tizi
✅ ✅ ✅ 梯子 TOP推荐(持续更新) ✅ ✅ ✅ PC梯子,Windows梯子,电脑梯子,国外好用梯子,推荐翻墙梯子软件,海外加速器梯子,国外vpn,科学上网工具,靠谱iPhone/iPad/安卓/Android/Mac/Linux/PC/路由器都可以用的梯子
Stars: ✭ 168 (-96.14%)
Mutual labels:  vpn, vpn-client, vpn-server
iosvpn.github.io
iPhone和iOS 翻墙梯子VPN推荐,2022中国苹果手机iPhone翻墙软件和科学上网避坑指南,稳定梯子推荐。
Stars: ✭ 72 (-98.35%)
Mutual labels:  vpn, vpn-server, vpn-client
Vpngate With Proxy
vpn gate client for linux, be able to connect to open vpn server through proxy
Stars: ✭ 150 (-96.56%)
Mutual labels:  vpn, vpn-client, vpn-server
Softethervpn
A Docker Automated Build Repository for SoftEther VPN
Stars: ✭ 297 (-93.18%)
Mutual labels:  vpn, vpn-server, docker-image
Docker Openvpn
🔐 Out of the box stateless openvpn-server docker image which starts in less than 2 seconds
Stars: ✭ 174 (-96.01%)
Mutual labels:  vpn, vpn-server, docker-image
useful-unix-stuff
a collection of useful unix commands/scripts/etc.
Stars: ✭ 64 (-98.53%)
Mutual labels:  ipsec, vpn, l2tp
Pi Hole On Google Compute Engine Free Tier With Full Tunnel And Split Tunnel Wireguard Vpn Configs
Run your own privacy-first ad blocking service at home, or in the cloud for free with Google Cloud Services.
Stars: ✭ 343 (-92.13%)
Mutual labels:  vpn, vpn-client, vpn-server
Node
Mysterium Network Node - official implementation of distributed VPN network (dVPN) protocol
Stars: ✭ 681 (-84.37%)
Mutual labels:  vpn, vpn-client, vpn-server
Macosvpn
🔧 Create macOS VPNs programmatically (L2TP & Cisco)
Stars: ✭ 348 (-92.01%)
Mutual labels:  vpn, vpn-client, ipsec

IPsec VPN Server on Docker

Build Status GitHub Stars Docker Stars Docker Pulls

Docker image to run an IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2.

Based on Alpine 3.14 or Debian 10 with Libreswan (IPsec VPN software) and xl2tpd (L2TP daemon).

» See also: IPsec VPN Server on Ubuntu, Debian and CentOS

Read this in other languages: English, 简体中文.

Table of Contents

Quick start

Use this command to set up an IPsec VPN server on Docker:

docker run \
    --name ipsec-vpn-server \
    --restart=always \
    -v ikev2-vpn-data:/etc/ipsec.d \
    -p 500:500/udp \
    -p 4500:4500/udp \
    -d --privileged \
    hwdsl2/ipsec-vpn-server

Your VPN login details will be randomly generated. See Retrieve VPN login details.

To learn more about how to use this image, read the sections below.

Install Docker

First, install Docker on your Linux server. You may also use Podman to run this image, after creating an alias for docker.

Advanced users can use this image on macOS with Docker for Mac. Before using IPsec/L2TP mode, you may need to restart the Docker container once with docker restart ipsec-vpn-server. This image does not support Docker for Windows.

Download

Get the trusted build from the Docker Hub registry:

docker pull hwdsl2/ipsec-vpn-server

Alternatively, you may download from Quay.io:

docker pull quay.io/hwdsl2/ipsec-vpn-server
docker image tag quay.io/hwdsl2/ipsec-vpn-server hwdsl2/ipsec-vpn-server

Supported platforms: linux/amd64, linux/arm64 and linux/arm/v7.

Advanced users can build from source code on GitHub.

Image comparison

Two pre-built images are available. The default Alpine-based image is only ~16MB.

Alpine-based Debian-based
Image name hwdsl2/ipsec-vpn-server hwdsl2/ipsec-vpn-server:debian
Compressed size ~ 16 MB ~ 57 MB
Base image Alpine Linux 3.14 Debian Linux 10
Platforms amd64, arm64, arm/v7 amd64, arm64, arm/v7
Libreswan version 4.5 4.5
IPsec/L2TP
Cisco IPsec
IKEv2

Note: To use the Debian-based image, replace every hwdsl2/ipsec-vpn-server with hwdsl2/ipsec-vpn-server:debian in this README.

How to use this image

Environment variables

Note: All the variables to this image are optional, which means you don't have to type in any variable, and you can have an IPsec VPN server out of the box! To do that, create an empty env file using touch vpn.env, and skip to the next section.

This Docker image uses the following variables, that can be declared in an env file (see example):

VPN_IPSEC_PSK=your_ipsec_pre_shared_key
VPN_USER=your_vpn_username
VPN_PASSWORD=your_vpn_password

This will create a user account for VPN login, which can be used by your multiple devices*. The IPsec PSK (pre-shared key) is specified by the VPN_IPSEC_PSK environment variable. The VPN username is defined in VPN_USER, and VPN password is specified by VPN_PASSWORD.

Additional VPN users are supported, and can be optionally declared in your env file like this. Usernames and passwords must be separated by spaces, and usernames cannot contain duplicates. All VPN users will share the same IPsec PSK.

VPN_ADDL_USERS=additional_username_1 additional_username_2
VPN_ADDL_PASSWORDS=additional_password_1 additional_password_2

Note: In your env file, DO NOT put "" or '' around values, or add space around =. DO NOT use these special characters within values: \ " '. A secure IPsec PSK should consist of at least 20 random characters.

Advanced users can optionally specify a DNS name for the VPN server's address. The DNS name must be a fully qualified domain name (FQDN). It will be included in the server certificate for IKEv2 mode. Example:

VPN_DNS_NAME=vpn.example.com

You may optionally specify a name for the first IKEv2 client. Use one word only, no special characters except - and _. The default is vpnclient if not specified.

VPN_CLIENT_NAME=your_client_name

Note that the VPN_DNS_NAME and VPN_CLIENT_NAME variables have no effect if IKEv2 is already set up in the Docker container.

Start the IPsec VPN server

Create a new Docker container from this image (replace ./vpn.env with your own env file):

docker run \
    --name ipsec-vpn-server \
    --env-file ./vpn.env \
    --restart=always \
    -v ikev2-vpn-data:/etc/ipsec.d \
    -p 500:500/udp \
    -p 4500:4500/udp \
    -d --privileged \
    hwdsl2/ipsec-vpn-server

In this command, we use the -v option of docker run to create a new Docker volume named ikev2-vpn-data, and mount it into /etc/ipsec.d in the container. IKEv2 related data such as certificates and keys will persist in the volume, and later when you need to re-create the Docker container, just specify the same volume again.

It is recommended to enable IKEv2 when using this image. However, if you prefer not to enable IKEv2 and use only the IPsec/L2TP and IPsec/XAuth ("Cisco IPsec") modes to connect to the VPN, remove the -v option from the docker run command above.

Note: Advanced users can also run without privileged mode.

Retrieve VPN login details

If you did not specify an env file in the docker run command above, VPN_USER will default to vpnuser and both VPN_IPSEC_PSK and VPN_PASSWORD will be randomly generated. To retrieve them, view the container logs:

docker logs ipsec-vpn-server

Search for these lines in the output:

Connect to your new VPN with these details:

Server IP: your_vpn_server_ip
IPsec PSK: your_ipsec_pre_shared_key
Username: your_vpn_username
Password: your_vpn_password

The output will also include details for IKEv2 mode, if enabled. To start using IKEv2, see Configure and use IKEv2 VPN.

(Optional) Backup the generated VPN login details (if any) to the current directory:

docker cp ipsec-vpn-server:/etc/ipsec.d/vpn-gen.env ./

Next steps

Get your computer or device to use the VPN. Please refer to:

Configure and use IKEv2 VPN

Configure IPsec/L2TP VPN Clients

Configure IPsec/XAuth ("Cisco IPsec") VPN Clients

If you get an error when trying to connect, see Troubleshooting.

Enjoy your very own VPN!

Important notes

Read this in other languages: English, 简体中文.

Windows users: For IPsec/L2TP mode, a one-time registry change is required if the VPN server or client is behind NAT (e.g. home router).

The same VPN account can be used by your multiple devices. However, due to an IPsec/L2TP limitation, if you wish to connect multiple devices simultaneously from behind the same NAT (e.g. home router), you must use IKEv2 or IPsec/XAuth mode.

If you wish to add, edit or remove VPN user accounts, first update your env file, then you must remove and re-create the Docker container using instructions from the next section. Advanced users can bind mount the env file.

For servers with an external firewall (e.g. EC2/GCE), open UDP ports 500 and 4500 for the VPN. Aliyun users, see #433.

Clients are set to use Google Public DNS when the VPN is active. If another DNS provider is preferred, read this section.

Update Docker image

To update the Docker image and container, first download the latest version:

docker pull hwdsl2/ipsec-vpn-server

If the Docker image is already up to date, you should see:

Status: Image is up to date for hwdsl2/ipsec-vpn-server:latest

Otherwise, it will download the latest version. To update your Docker container, first write down all your VPN login details. Then remove the Docker container with docker rm -f ipsec-vpn-server. Finally, re-create it using instructions from How to use this image.

Configure and use IKEv2 VPN

Read this in other languages: English, 简体中文.

Using this Docker image, advanced users can configure and use IKEv2. This mode has improvements over IPsec/L2TP and IPsec/XAuth ("Cisco IPsec"), and does not require an IPsec PSK, username or password. Read more here.

First, check container logs to view details for IKEv2:

docker logs ipsec-vpn-server

Note: If you cannot find IKEv2 details, IKEv2 may not be enabled in the container. Try updating the Docker image and container using instructions from the Update Docker image section.

During IKEv2 setup, an IKEv2 client (with default name vpnclient) is created, with its configuration exported to /etc/ipsec.d inside the container. To copy config file(s) to the Docker host:

# Check contents of /etc/ipsec.d in the container
docker exec -it ipsec-vpn-server ls -l /etc/ipsec.d
# Example: Copy a client config file from the container
# to the current directory on the Docker host
docker cp ipsec-vpn-server:/etc/ipsec.d/vpnclient.p12 ./

After that, use the IKEv2 details from above to configure IKEv2 VPN clients.

You can manage IKEv2 clients using the helper script. See examples below. To customize client options, run the script without arguments.

# Add a new client (using default options)
docker exec -it ipsec-vpn-server ikev2.sh --addclient [client name]
# Export configuration for an existing client
docker exec -it ipsec-vpn-server ikev2.sh --exportclient [client name]
# List the names of existing clients
docker exec -it ipsec-vpn-server ikev2.sh --listclients
# Show usage information
docker exec -it ipsec-vpn-server ikev2.sh -h

Note: If you encounter error "executable file not found", replace ikev2.sh above with /opt/src/ikev2.sh.

In certain circumstances, advanced users may need to remove IKEv2 and set it up again using custom options. This can be done using the helper script. Note that this will override variables you specified in the env file, such as VPN_DNS_NAME and VPN_CLIENT_NAME, and the Docker container's logs will no longer show up-to-date information for IKEv2.

Warning: All IKEv2 configuration including certificates and keys will be permanently deleted. This cannot be undone!

# Remove IKEv2 and delete all IKEv2 configuration
docker exec -it ipsec-vpn-server ikev2.sh --removeikev2
# Set up IKEv2 again using custom options
docker exec -it ipsec-vpn-server ikev2.sh

Advanced usage

See Advanced usage.

Technical details

There are two services running: Libreswan (pluto) for the IPsec VPN, and xl2tpd for L2TP support.

The default IPsec configuration supports:

  • IPsec/L2TP with PSK
  • IKEv1 with PSK and XAuth ("Cisco IPsec")
  • IKEv2

The ports that are exposed for this container to work are:

  • 4500/udp and 500/udp for IPsec

See also

License

Note: The software components inside the pre-built image (such as Libreswan and xl2tpd) are under the respective licenses chosen by their respective copyright holders. As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.

Copyright (C) 2016-2021 Lin Song View my profile on LinkedIn
Based on the work of Thomas Sarlandie (Copyright 2012)

Creative Commons License
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License
Attribution required: please include my name in any derivative and let me know how you have improved it!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].