diff --git a/wireguard/Dockerfile b/wireguard/Dockerfile index 35170d35e6e805c9547bc21ec631250ebdefb225..41a335ebc2b32cb61863e11a024aef6b52015110 100644 --- a/wireguard/Dockerfile +++ b/wireguard/Dockerfile @@ -9,7 +9,7 @@ RUN rm /sbin/iptables /sbin/ip6tables RUN ln -s /sbin/ip6tables-nft /sbin/ip6tables RUN ln -s /sbin/iptables-nft /sbin/iptables -ENV LOCAL_NETWORK="" +ENV LOCAL_NETWORKS="" COPY entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/wireguard/entrypoint.sh b/wireguard/entrypoint.sh index f2c922327752d1ffaacf84229371f21074b8d322..35dd4f1f84c94bb203af0d161436bd04818e1e7c 100755 --- a/wireguard/entrypoint.sh +++ b/wireguard/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh set -eu -if [ -n "$LOCAL_NETWORK" ]; then +if [ -n "$LOCAL_NETWORKS" ]; then gateway=$(ip route list match 0.0.0.0 | grep -v tun0 | cut -d ' ' -f 3) interface=$(ip route list match 0.0.0.0 | grep -v tun0 | cut -d ' ' -f 5) echo gateway="$gateway" @@ -14,6 +14,9 @@ chmod 0666 /dev/net/tun wg-quick up /wireguard.conf -if [ -n "$LOCAL_NETWORK" ]; then - ip r add "$LOCAL_NETWORK" via "${gateway}" dev "${interface}" +if [ -n "$LOCAL_NETWORKS" ]; then + IFS="," + for LOCAL_NETWORK in $LOCAL_NETWORKS; do + ip route add "$LOCAL_NETWORK" via "${gateway}" dev "${interface}" + done fi