Skip to content

Instantly share code, notes, and snippets.

@drushadrusha
Last active March 3, 2023 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drushadrusha/25fb3dfeb9c464424835f321ba0ebf23 to your computer and use it in GitHub Desktop.
Save drushadrusha/25fb3dfeb9c464424835f321ba0ebf23 to your computer and use it in GitHub Desktop.
How to make Wireguard VPN input and output traffic on different interfaces.
## This will work with installation made by this script.
## https://github.com/angristan/wireguard-install
echo "100 wg" >> /etc/iproute2/rt_tables ## Create new routing table
ip rule add from 10.66.66.1/24 table wg ## Send all traffic from Wireguard network to wg routing table
ip route add default via 192.168.1.1 dev ens7 table wg ## Set default gateway for wg routing table
iptables -t nat -A POSTROUTING -o ens7 -s 10.66.66.1/24 -j MASQUERADE ## Make it working with Wireguard NAT
## Also you could try something like this.
ip -4 rule add pref 500 from 10.66.66.1/24 lookup 2 ## Make all trafic from Wireguard network go to table 2
ip -4 route add default via 192.168.1.1 table 2 ## Set default gateway on table 2
## Do not forget to make script to set this changes on your system startup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment