Skip to content

Instantly share code, notes, and snippets.

@siavashs
Created September 5, 2019 14:05
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 siavashs/e7e2bd4c248b2f649af276a303aefc5d to your computer and use it in GitHub Desktop.
Save siavashs/e7e2bd4c248b2f649af276a303aefc5d to your computer and use it in GitHub Desktop.
Script for adding NAT rules for xhyve VMs to subnets behind OpenVPN
#!/bin/sh
subnets="10.1/16"
rules="/tmp/nat.rules"
echo "Clearing nat table..."
sudo pfctl -a com.apple/tun -F nat
echo "Generaring nat rules..."
echo > $rules
for sub in $subnets; do
if=`netstat -nr | grep "$sub" | awk -F ' ' '{ print $6 }'`
echo "nat on ${if} proto {tcp, udp, icmp} from 192.168.64.0/24 to $sub -> ${if}" >> $rules
done
echo "Applying nat rules..."
sudo pfctl -a com.apple/tun -f $rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment