Deploying an L2TP VPN on Google Cloud Platform (GCP) provides a reliable way to offer remote access with compatibility across Windows, macOS, Linux, iOS, and Android. This guide provides a detailed, practical walkthrough for system administrators, developers, and enterprise operators who need a self-managed L2TP/IPsec solution on GCP. It assumes familiarity with Linux server administration and basic GCP concepts (projects, VPC, firewall rules, and Compute Engine). The instructions focus on a Debian/Ubuntu-based Compute Engine instance and use strongSwan for IPsec and xl2tpd for L2TP.
Overview and prerequisites
Before beginning, ensure you have the following:
- A GCP project with billing enabled.
- Compute Engine API enabled and an SSH key or access to the VM via the console.
- A static external IP address reserved in the project (recommended for stable client configuration).
- A Linux VM image (Debian 11 or Ubuntu 20.04/22.04 are recommended) with at least 1 vCPU and 1 GB RAM, though production should use more.
- Root or sudo privileges on the VM.
Network planning on GCP
Architect the VPC and firewall rules carefully. L2TP over IPsec requires several ports and protocols to be allowed:
- UDP 500 (IKE)
- UDP 4500 (NAT-T)
- UDP 1701 (L2TP)
- IP Protocol 50 (ESP) — GCP’s VPC firewall does not filter by protocol number for external traffic, but ensure no network policies block ESP.
Create a VPC firewall rule to allow these ports from the expected client IP ranges. For initial testing you may allow 0.0.0.0/0, but for production restrict to trusted addresses where possible. Also allow TCP 22 for SSH.
Provisioning the Compute Engine instance
Create a new VM in the intended region and zone, use a recommended Linux distribution, and attach the static external IP. Under the networking settings, enable IP forwarding (this is critical because the server must forward packets between VPN clients and other networks). In the VM’s network interface, set “IP forwarding” to on via the instance’s configuration or by using a custom image that has net.ipv4.ip_forward enabled later.
Initial system configuration
After SSH into the VM, perform basic setup:
- Update packages: apt-get update && apt-get upgrade -y
- Install required packages: strongSwan, xl2tpd, ppp, and iptables tools: apt-get install -y strongswan xl2tpd ppp iptables-persistent
- Enable IP forwarding permanently by editing /etc/sysctl.conf: set net.ipv4.ip_forward=1 and apply with sysctl -p.
IPsec (strongSwan) configuration
Configure strongSwan to handle IKE and ESP. Edit /etc/ipsec.conf with a connection definition tailored for L2TP/IPsec. Key points:
- Use ike=aes256-sha1-modp1024 (or stronger algorithms if clients support them), esp=aes256-sha1.
- Set left to the server’s public IP or %defaultroute and leftid to the public IP or a DNS name.
- Accept pre-shared keys or certificates; this guide uses PSK for simplicity with /etc/ipsec.secrets.
Example configuration elements (insert into /etc/ipsec.conf):
config setup and a connection block named, e.g., l2tp-psk, setting auto=add and specifying keyexchange=ikev1. Set also leftsendcert=never if using PSK. Avoid posting full file contents inline here to keep structure concise—ensure the connection contains correct left and right parameters for your environment.
Edit /etc/ipsec.secrets to define the PSK: your-public-ip : PSK “your_pre_shared_key”. Use a strong random string and protect the file permissions (chmod 600).
xl2tpd and PPP configuration
Configure xl2tpd to provide L2TP tunnels and ppp options to authenticate clients and assign IP addresses.
- Edit /etc/xl2tpd/xl2tpd.conf. Provide an [global] and an [lns default] section. In the lns section, set local ip (server VPN IP) and remote ip range for clients (e.g., 10.10.10.0/24 but in pxp format like 10.10.10.2-10.10.10.254).
- Edit /etc/ppp/options.xl2tpd. Important settings: refuse-eap, require-mschap-v2, noccp, auth, mtu and mru 1400 to avoid fragmentation issues over IPsec. Add ms-dns entries if you want to push DNS servers to clients.
- For user authentication add /etc/ppp/chap-secrets lines: username password
Set permissions for chap-secrets to 600.
Firewall rules and NAT
Configure iptables to allow forwarding and perform source NAT for outgoing traffic so client packets egress with the server’s external IP:
- Enable NAT (MASQUERADE) on the external interface: iptables -t nat -A POSTROUTING -s 10.10.10.0/24 -o eth0 -j MASQUERADE (replace eth0 with the interface name observed on the VM, e.g., ens4).
- Allow forwarding between the VPN subnet and the internal network: iptables -A FORWARD -s 10.10.10.0/24 -j ACCEPT and iptables -A FORWARD -d 10.10.10.0/24 -j ACCEPT.
- Allow UDP 500, 4500, 1701 in the filter table and ensure RELATED,ESTABLISHED rules are present.
Persist these rules using iptables-persistent or by saving a script to /etc/network/if-up.d/ that reapplies the rules at boot.
Tuning for reliability and performance
Pay attention to these practical details:
- MTU/MRU: Set PPP mtu/mru to 1400 or 1380 to avoid fragmentation over the IPsec tunnel, especially with additional encapsulation.
- sysctl tuning: Ensure net.ipv4.ip_forward=1 and consider net.ipv4.conf.all.rp_filter=0 to avoid reverse-path filtering issues with asymmetric routing; set these in /etc/sysctl.conf.
- conntrack: Increase conntrack table size if you expect many simultaneous sessions: echo 262144 > /proc/sys/net/netfilter/nf_conntrack_max.
- Logging: Enable verbose logging temporarily in strongSwan and xl2tpd to troubleshoot, but reduce verbosity once stable.
Starting and testing services
Start or restart services: systemctl restart strongswan-starter (or strongswan) and systemctl restart xl2tpd. Check logs: use journalctl -u strongswan -f and tail -f /var/log/syslog (or /var/log/auth.log) to monitor IPsec and PPP negotiation.
From a client, configure a new L2TP/IPsec connection: set the server address to your reserved external IP, enter the PSK, and configure username/password as defined in chap-secrets. Verify the client obtains an IP from the remote range and can reach internal and external resources. On the server, check ipsec status via ipsec statusall and verify ppp0 (or similar) interfaces with ip addr show.
Troubleshooting checklist
- Client can’t establish IPsec: Check UDP 500/4500 reachability from client to server (use nc or packet capture). Confirm PSK matches and strongSwan logs show IKE SA attempts.
- L2TP fails after IPsec: Ensure UDP 1701 is allowed and xl2tpd is running. Check ppp options and chap-secrets entries.
- No internet access for clients: Confirm NAT rule exists and POSTROUTING MASQUERADE is applied to the correct external interface. Verify ip_forward is enabled.
- Intermittent disconnects: Tune MTU, disable aggressive connection rekeying, and check idle-timeouts in strongSwan.
Security and operational considerations
While L2TP/IPsec remains widely supported, it is older than modern VPN options like OpenVPN or WireGuard and can be less robust with NAT traversal. For production environments:
- Use strong cryptographic algorithms (AES-GCM, SHA2, longer Diffie-Hellman groups) where clients support them.
- Prefer certificate-based authentication over PSK for better security and scalability.
- Limit firewall exposure to known client IPs and use two-factor authentication at the application layer if possible.
- Regularly update the server OS and VPN software for security patches.
Scaling and high availability
For enterprise use, consider the following:
- Deploy multiple VPN gateways behind a TCP/UDP load balancer is non-trivial for IPsec because of stateful ESP. Instead, use client routing to specific gateway IPs or use NAT load balancers with careful session affinity.
- Use configuration management (Ansible, Terraform) to standardize deployments and secrets handling.
- Consider using GCP Cloud VPN (managed IPsec) for site-to-site tunnels and combine with a separate remote-access solution if required.
Implementing L2TP/IPsec on GCP offers wide client compatibility and gives administrators full control over authentication, routing, and policies. The steps above cover the essential configuration and operational considerations for a secure and reliable deployment. Test thoroughly with representative client platforms and monitor logs and metrics to maintain uptime and performance.
For more detailed guides and service options, visit Dedicated-IP-VPN at https://dedicated-ip-vpn.com/.