{"repo":"hwdsl2/docker-ipsec-vpn-server","free":true,"listed":false,"github":"https://github.com/hwdsl2/docker-ipsec-vpn-server","clone":"git clone https://github.com/hwdsl2/docker-ipsec-vpn-server.git","description":"Docker image to run an IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2. Auto-generates server config and supports VPN client setup on Linux, Windows, macOS, iOS and Android.","language":"Shell","stars":7118,"topics":["cisco-ipsec","docker","docker-compose","docker-image","encryption","ikev2","ipsec","l2tp","libreswan","linux","network","privacy","raspberry-pi","security","self-hosted","strongswan","vpn","vpn-client","vpn-server"],"license":null,"category":"network_service","readme_excerpt":"[English](README.md) | [简体中文](README-zh.md) | [繁體中文](README-zh-Hant.md) | [Русский](README-ru.md)\n\n# IPsec VPN Server on Docker\n\n[![Build Status](https://github.com/hwdsl2/docker-ipsec-vpn-server/actions/workflows/main-alpine.yml/badge.svg)](https://github.com/hwdsl2/docker-ipsec-vpn-server/actions/workflows/main-alpine.yml) [![GitHub Stars](https://raw.githubusercontent.com/hwdsl2/badges/main/img/github-stars-docker-ipsec-vpn-server.svg)](https://github.com/hwdsl2/docker-ipsec-vpn-server/stargazers) [![Docker Stars](https://raw.githubusercontent.com/hwdsl2/badges/main/img/docker-stars-ipsec-vpn-server.svg)](https://hub.docker.com/r/hwdsl2/ipsec-vpn-server/) [![Docker Pulls](https://raw.githubusercontent.com/hwdsl2/badges/main/img/docker-pulls-ipsec-vpn-server.svg)](https://hub.docker.com/r/hwdsl2/ipsec-vpn-server/)\n\nDocker image to run an IPsec VPN server, with IPsec/L2TP, Cisco IPsec and IKEv2.\n\nBased on Alpine 3.23 or Debian 12 with [Libreswan](https://libreswan.org) (IPsec VPN software) and [xl2tpd](https://github.com/xelerance/xl2tpd) (L2TP daemon).\n\nAn IPsec VPN encrypts your network traffic, so that nobody between you and the VPN server can eavesdrop on your data as it travels via the Internet. This is especially useful when using unsecured networks, e.g. at coffee shops, airports or hotel rooms.\n\n**Features:**\n\n- Automatically generates VPN credentials and IKEv2 configuration on first start\n- Supports IKEv2 with strong and fast ciphers (e.g. AES-GCM)\n- Generates VPN profiles to auto-configure iOS, macOS and Android devices\n- Supports Windows, macOS, iOS, Android, Chrome OS and Linux as VPN clients\n- Includes a helper script to manage IKEv2 users and certificates\n- Automatically built and published via [GitHub Actions](https://github.com/hwdsl2/docker-ipsec-vpn-server/actions)\n- Persistent data via a Docker volume\n- Multi-arch: `linux/amd64`, `linux/arm64`, `linux/arm/v7`\n\n**Also available:**\n\n- VPN: [IPsec without Docker](https://github.com/hwdsl2/setup-ipsec-vpn), [WireGuard](https://github.com/hwdsl2/docker-wireguard), [OpenVPN](https://github.com/hwdsl2/docker-openvpn), [Headscale](https://github.com/hwdsl2/docker-headscale)\n- AI: [Self-Hosted AI Stack](https://github.com/hwdsl2/self-hosted-ai-stack) for local LLMs, chat, RAG, voice and AI tools\n- :books: **Books:** [The Self-Hosted AI Builder’s Guide](https://books2read.com/aiguide?store=amazon), [Privacy Tools in the Age of AI](docs/vpn-book.md)\n\n## Quick start\n\nUse this command to set up an IPsec VPN server on Docker:\n\n```bash\ndocker run \\\n    --name ipsec-vpn-server \\\n    --restart=always \\\n    -v ikev2-vpn-data:/etc/ipsec.d \\\n    -v /lib/modules:/lib/modules:ro \\\n    -p 500:500/udp \\\n    -p 4500:4500/udp \\\n    -d --privileged \\\n    hwdsl2/ipsec-vpn-server\n```\n\nYour VPN login details will be randomly generated. See [Retrieve VPN login details](#retrieve-vpn-login-details).\n\nAlternatively, you may [set up IPsec VPN without Docker](https://github.com/hwdsl2/setup-ipsec-vpn). To learn more about how to use this image, read the sections below.\n\n## Community\n\n- 📬 [Subscribe for project updates](https://selfhostedstack.beehiiv.com/subscribe?utm_campaign=vpn) (1–2 emails/month) — get free VPN and AI deployment guides (PDF)\n- 💬 Join the [r/selfhostedstack](https://www.reddit.com/r/selfhostedstack/) community for discussions\n- ⭐ Star the repository if you find it useful — it helps others discover it\n\n## Requirements\n\n- A Linux server with a public IP address or DNS name\n- Docker installed\n- VPN ports open in your firewall (UDP 500 and 4500)\n- You may also use [Podman](https://docs.podman.io) to run this image, after creating an alias for `docker`\n\n**Note:** Advanced users can use this image on macOS with [Docker for Mac](https://docs.docker.com/desktop/setup/install/mac-install/). Before using IPsec/L2TP mode, you may need to restart the container once with `docker restart ipsec-vpn-server`. This image does not support Docker for Windows.\n\n## Download\n\nGet the trusted build from the [Docker Hub registry](https://hub.docker.com/r/hwdsl2/ipsec-vpn-server/):\n\n```bash\ndocker pull hwdsl2/ipsec-vpn-server\n```\n\nAlternatively, you may download from [Quay.io](https://quay.io/repository/hwdsl2/ipsec-vpn-server):\n\n```bash\ndocker pull quay.io/hwdsl2/ipsec-vpn-server\ndocker image tag quay.io/hwdsl2/ipsec-vpn-server hwdsl2/ipsec-vpn-server\n```\n\nSupported platforms: `linux/amd64`, `linux/arm64` and `linux/arm/v7`.\n\nAdvanced users can [build from source code](docs/advanced-usage.md#build-from-source-code) on GitHub.\n\n### Image comparison\n\nTwo pre-built images are available. The default Alpine-based image is only ~19 MB.\n\n|                   | Alpine-based             | Debian-based                   |\n| ----------------- | ------------------------ | ------------------------------ |\n| Image name        | hwdsl2/ipsec-vpn-server  | hwdsl2/ipsec-vpn-server:debian |\n| Compressed size   | ~ 19 MB                  | ~ 62 MB                        |\n| Base image        | Alpine Linux 3.23        | Debian Linux 12                |\n| Platforms         | amd64, arm64, arm/v7     | amd64, arm64, arm/v7           |\n| Libreswan version | 5.3.2                    | 5.3.2                          |\n| IPsec/L2TP        | ✅                       | ✅                              |\n| Cisco IPsec       | ✅                       | ✅                              |\n| IKEv2             | ✅                       | ✅                              |\n\n**Note:** To use the Debian-based image, replace every `hwdsl2/ipsec-vpn-server` with `hwdsl2/ipsec-vpn-server:debian` in this README. These images are not currently compatible with Synology NAS systems.\n\n<details>\n<summary>\nI want to use the older Libreswan version 4.\n</summary>\n\nIt is generally recommended to use the latest [Libreswan](https://libreswan.org/) version 5, which is the default version in this project. However, if you want to use the older Libreswan version 4, you can build the Docker image from source code:\n\n```bash\ngit clone https://github.com/hwdsl2/docker-ipsec-vpn-server\ncd docker-ipsec-vpn-server\n# Specify Libreswan version 4\nsed -i 's/SWAN_VER=5\\..*/SWAN_VER=4.15/' Dockerfile Dockerfile.debian\n# To build Alpine-based image\ndocker build -t hwdsl2/ipsec-vpn-server .\n# To build Debian-based image\ndocker build -f Dockerfile.debian -t hwdsl2/ipsec-vpn-server:debian .\n```\n</details>\n\n## How to use this image\n\n### Environment variables\n\n**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.\n\nThis Docker image uses the following variables, that can be declared in an `env` file (see [example](vpn.env.example)):\n\n```\nVPN_IPSEC_PSK=your_ipsec_pre_shared_key\nVPN_USER=your_vpn_username\nVPN_PASSWORD=your_vpn_password\n```\n\nThis will create a user account for VPN login, which can be used by your multiple devices[\\*](#important-notes). 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`.\n\nAdditional 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.\n\n```\nVPN_ADDL_USERS=additional_username_1 additional_username_2\nVPN_ADDL_PASSWORDS=additional_password_1 additional_password_2\n```\n\nThe variables above are only for IPsec/L2TP and IPsec/XAuth (\"Cisco IPsec\") modes. For IKEv2, see [Configure and use IKEv2 VPN](#configure-and-use-ikev2-vpn).\n\n**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.\n\n**Note:** If you modify the `env` file after the Docker container is already created, you must remove and re-create the container for the changes to take effect. Refer to [Update Docker image](#update-docker-image).\n\n### Additional environment variables\n\nAdvanced users can optionally specify a DNS name, client name and/or custom DNS servers.\n\n<details>\n<summary>\nLearn how to specify a DNS name, client name and/or custom DNS servers.\n</summary>\n\nAdvanced users can optionally specify a DNS name for the IKEv2 server address. The DNS name must be a fully qualified domain name (FQDN). Example:\n\n```\nVPN_DNS_NAME=vpn.example.com\n```\n\nYou may specify a name for the first IKEv2 client. Use one word only, no special characters except `-` and `_`. The default is `vpnclient` if not specified.\n\n```\nVPN_CLIENT_NAME=your_client_name\n```\n\nBy default, clients are set to use [Google Public DNS](https://developers.google.com/speed/public-dns/) when the VPN is active. You may specify custom DNS server(s) for all VPN modes. Example:\n\n```\nVPN_DNS_SRV1=1.1.1.1\nVPN_DNS_SRV2=1.0.0.1\n```\n\nFor more details and a list of some popular public DNS providers, see [Use alternative DNS servers](docs/advanced-usage.md).\n\nBy default, no password is required when importing IKEv2 client configuration. You can choose to protect client config files using a random password.\n\n```\nVPN_PROTECT_CONFIG=yes\n```\n\n**Note:** The variables above have no effect for IKEv2 mode, if IKEv2 is already set up in the Docker container. In this case, you may remove IKEv2 and set it up again using custom options. Refer to [Configure and use IKEv2 VPN](#configure-and-use-ikev2-vpn).\n</details>\n\n### Start the IPsec VPN server\n\nCreate a new Docker container from this image (replace `./vpn.env` with your own `env` file):\n\n```bash\ndocker run \\\n    --name ipsec-vpn-server \\\n    --env-file ./vpn.env \\\n    --restart=always \\\n    -v ikev2-vpn-data:/etc/ipsec.d \\\n    -v /lib/modules:/lib/modules:ro \\\n    -p 500:500/udp \\\n    -p 4500:4500/udp \\\n    -d --privileged \\\n    hwdsl2","default_branch":"master","files":36,"tree":[".dockerignore",".github/ISSUE_TEMPLATE/00-bug-report.md",".github/ISSUE_TEMPLATE/10-bug-report-zh.md",".github/ISSUE_TEMPLATE/20-enhancement-request.md",".github/ISSUE_TEMPLATE/30-enhancement-request-zh.md",".github/PULL_REQUEST_TEMPLATE.md",".github/workflows/buildx.yml",".github/workflows/check_update.yml",".github/workflows/cron-alpine.yml",".github/workflows/cron-debian.yml",".github/workflows/main-alpine.yml",".github/workflows/main-debian.yml",".github/workflows/shellcheck.yml",".github/workflows/test-alpine.yml",".github/workflows/test-debian.yml",".github/workflows/vpn_test.yml",".gitignore","CONTRIBUTING.md","Dockerfile","Dockerfile.debian","LICENSE.md","README-ru.md","README-zh-Hant.md","README-zh.md","README.md","docker-compose.yml","docs/advanced-usage-zh.md","docs/advanced-usage.md","docs/images/badges/docker-pulls.svg","docs/images/badges/docker-stars.svg","docs/images/badges/github-stars.svg","docs/vpn-book-zh-Hant.md","docs/vpn-book-zh.md","docs/vpn-book.md","run.sh","vpn.env.example"],"storefront":"/r/hwdsl2","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/hwdsl2/docker-ipsec-vpn-server/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}