diff --git a/setup_openvpn.sh b/setup_openvpn.sh index 4eb5c57..373e01a 100755 --- a/setup_openvpn.sh +++ b/setup_openvpn.sh @@ -113,6 +113,23 @@ sysctl --system echo "Configuring firewall..." ufw allow 1194/udp ufw allow OpenSSH + +# Set up NAT for VPN clients +echo "Setting up NAT for VPN clients..." +# Get the primary network interface +PRIMARY_NIC=$(ip route | grep default | awk '{print $5}') +echo "Primary network interface: $PRIMARY_NIC" + +# Add NAT rules +iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o $PRIMARY_NIC -j MASQUERADE +iptables -A FORWARD -s 10.8.0.0/24 -m state --state NEW -j ACCEPT +iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT + +# Make NAT rules persistent +echo "Making NAT rules persistent..." +apt-get install -y iptables-persistent +echo "y" | netfilter-persistent save + echo "y" | ufw enable # Start OpenVPN service