OpenVPN client gateway with NAT, routing and subnet filtering (Ubuntu 24.04)
1.2K
softfour/openvpn-gw is a lightweight container based on Ubuntu 24.04 (noble) that runs an
OpenVPN client and configures NAT/masquerade and iptables rules to
route traffic from the container network through the VPN tunnel (tun0).
It also supports static routes and forwarding restrictions to specific subnets.
ubuntu:nobleopenvpn, iptables, iproute2, iputils-ping, net-tools, procps, tzdata/entrypoint:
ROUTE_MAPS)tun0FIREWALL_SUBNETS)/opt/openvpn/client.ovpnTUN device available in the container
Network capabilities to manage iptables
docker run -d --name ovpn-gw
--cap-add=NET_ADMIN
--device /dev/net/tun
-e TZ=UTC
-e ROUTE_MAPS="10.10.0.0/16:192.168.1.1, 172.16.0.0/12:192.168.1.1"
-e FIREWALL_SUBNETS="192.168.1.0/24; 192.168.2.0/24"
-v $(pwd)/client.ovpn:/opt/openvpn/client.ovpn:ro
softfour/openvpn-gw:latest
services: ovpn-gw: image: softfour/openvpn-gw:latest container_name: ovpn-gw cap_add: - NET_ADMIN devices: - /dev/net/tun environment: TZ: "UTC" ROUTE_MAPS: "10.10.0.0/16:192.168.1.1,172.16.0.0/12:192.168.1.1" FIREWALL_SUBNETS: "192.168.1.0/24; 192.168.2.0/24" volumes: - ./client.ovpn:/opt/openvpn/client.ovpn:ro restart: unless-stopped
TZ (default: UTC) – Container timezone.ROUTE_MAPS (optional) – Comma/semicolon/space-separated list of CIDR:GATEWAY. Example: 10.10.0.0/16:192.168.1.1, 172.16.0.0/12:192.168.1.1. Adds routes with ip route add <CIDR> via <GATEWAY> dev eth0.FIREWALL_SUBNETS (optional) – Comma/semicolon/space-separated list of subnets allowed to forward traffic to tun0. If unset, forwarding is allowed for all traffic.MASQUERADE on traffic to tun0, allowing ESTABLISHED,RELATED connections.ROUTE_MAPS for multi-network static routing.FIREWALL_SUBNETS.This container uses open source packages from Ubuntu. Please verify licensing for OpenVPN and dependencies in your environment.
Content type
Image
Digest
sha256:703506ff0…
Size
67.7 MB
Last updated
about 1 month ago
docker pull softfour/openvpn-gw