Created
September 5, 2019 14:05
-
-
Save siavashs/e7e2bd4c248b2f649af276a303aefc5d to your computer and use it in GitHub Desktop.
Script for adding NAT rules for xhyve VMs to subnets behind OpenVPN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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