Skip to content

Commit 579e0f7

Browse files
authored
feat: support for configuring iptables masquerading for NAT (#2)
Signed-off-by: Aurora Gaffney <aurora@blinklabs.io>
1 parent 363b9ca commit 579e0f7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ COPY bin/ /usr/local/bin
44

55
RUN apt-get update \
66
&& apt-get dist-upgrade -y \
7-
&& apt-get install -y openvpn \
7+
&& apt-get install -y openvpn iptables \
88
&& apt-get clean \
99
&& rm -rf /var/lib/apt/lists/* \
1010
&& chmod +x /usr/local/bin/*

bin/entrypoint

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
#!/bin/bash
22

3+
CONFIG_DIR=/etc/openvpn
4+
5+
ENABLE_NAT=${ENABLE_NAT:-1}
6+
NAT_SOURCE=${NAT_SOURCE:-10.8.0.0/24}
7+
NAT_DEVICE=${NAT_DEVICE:-eth0}
8+
39
# Create device for tun interfaces
410
mkdir -p /dev/net
511
if [ ! -c /dev/net/tun ]; then
6-
mknod /dev/net/tun c 10 200
12+
mknod /dev/net/tun c 10 200
13+
fi
14+
15+
if [[ $ENABLE_NAT = 1 ]]; then
16+
iptables -t nat -A POSTROUTING -s ${NAT_SOURCE} -o ${NAT_DEVICE} -j MASQUERADE
717
fi
818

9-
openvpn --config /etc/openvpn/openvpn.conf $@
19+
exec openvpn --config ${CONFIG_DIR}/openvpn.conf --cd ${CONFIG_DIR} $@

0 commit comments

Comments
 (0)