Hi, I made this for my use-case, but feel free to use it :)
This is currently only handling the NAT side of things, not PAT!
The from-to port options is just a placeholder it will use the first port specified.
route_port 80 80 tcp $vpn_ip $server_ip
Download and make executable
$ wget https://gist.githubusercontent.com/Sherex/78f6d8d8ed4223f8995d1d01f790a11b/raw/c0a87d74ed412e9934bab1e1cfde3aee5957bff7/ifscript.sh -O /etc/wireguard/ifscript.sh
$ chmod +x /etc/wireguard/ifscript.sh
Edit ifscript.sh
to suit your needs, I recommend double checking these variables at the top of the file:
Variable | Example value | Description |
---|---|---|
int_interface | "eth0" | Make sure this matches the interface, packets should be directed from! (common interfaces are "eth0" and "ens18") |
vpn_ip | "10.50.0.1" | This should be the IP your server the packets will be sent from after the forward |
server_ip | "10.50.0.249" | This should be the IP the server that should receive the packets |
Note: This can easily be configured to route traffic out from the
wg0
interface and to a server on the same network. Just setvpn_ip
to the IP of the interface on the local network andserver_ip
to the server that should receive the packets.
And swap the values of the variablesint_interface
andinterface
Change the lines in your /etc/wireguard/wg0.conf
to:
...
PostUp = /etc/wireguard/ifscript.sh up %i
PostDown = /etc/wireguard/ifscript.sh down %i
...
Run this:
$ sysctl -w net.ipv4.ip_forward=1
And last, but just as important, in the file /etc/sysctl.conf
uncomment the line
net.ipv4.ip_forward = 1
Then run this to reload sysctl configuration:
$ sysctl -p
As I don't have access to the external facing router on my network ( Renting is fun :) ), I set this up.
A VPS routes traffic from specified ports (80 and 443
) to a local VM behind NAT.
Then that VM routes the traffic to another VM on it's local network.
Internet -> VPS [wireguard tunnel -> network-VM] --> docker-VM