commit e1f64570d6ca076a1cbb813706faa768cf0a1fe9
parent 5c3a9bedfe38e2b6ecef524e59984fb7dc681ac6
Author: nolash <dev@holbrook.no>
Date: Wed, 21 Apr 2021 07:28:28 +0200
Add docker vpn article stub
Diffstat:
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/content/20210421_docker_vpn.rst b/content/20210421_docker_vpn.rst
@@ -0,0 +1,35 @@
+Using Docker with VPN
+#####################
+
+:date: 2021-04-21 06:53
+:modified: 2021-04-21 06:53
+:category: Hygiene
+:author: Louis Holbrook
+:tags: vpn,openvpn,iproute,docker
+:slug: docker-vpn
+:summary: Using docker network while openvpn in running
+:lang: en
+:status: published
+
+
+Need to route through the tun interface, which Docker doesn't seem to automatically do.
+
+.. code-block:: bash
+
+ $ ip route ls
+ [...]
+ 10.7.3.0/24 dev tun0 proto kernel scope link src 10.7.3.6
+
+::
+
+ ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network
+
+The simplest solution I have found is to exchange the gateway redirect from the OpenVPN server [1]_ and add the VPN interface as the default route.
+
+.. include:: code/docker-vpn/docker_vpn_routes.sh
+ :code: bash
+
+
+..
+
+ .. [1] https://stackoverflow.com/a/62333327
diff --git a/content/code/docker-vpn/docker_vpn_routes.sh b/content/code/docker-vpn/docker_vpn_routes.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+default_route_vpn_gateway=`ip route | awk '{if ($3 ~ /^tun/) { print $9; }}'`
+route_vpn_gateway=${VPN_GATEWAY:-$default_route_vpn_gateway}
+
+echo "Adding default route to $route_vpn_gateway with /0 mask..."
+ip route add default via $route_vpn_gateway
+
+echo "Removing /1 routes..."
+ip route del 0.0.0.0/1 via $route_vpn_gateway
+ip route del 128.0.0.0/1 via $route_vpn_gateway