The aim of this script is to only allow traffic over the VPN, except for localhost<->localhost and incoming SSH traffic. But when I run the script over SSH I am disconnected and forced to restart the vm. What is wrong with my script?
#!/bin/bash
iptables -F
#Allow over VPN
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A OUTPUT -o tun+ -j ACCEPT
#Localhost
iptables -A INPUT -s 127.0.0.1/8 -j ACCEPT
iptables -A OUTPUT -d 127.0.0.1/8 -j ACCEPT
#VPN
iptables -A INPUT -s 123.123.123.123 -j ACCEPT
iptables -A OUTPUT -d 123.123.123.123 -j ACCEPT
#SSH
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
#Default Deny
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP
-p tcp
and was created via anINPUT
rule. Try it yourself (replace your output rule with an established, related rule). – goldilocks Jun 09 '14 at 12:05-p tcp
making any difference in this sense, and look at the subsequent explanation for UDP on that page (it's the same). The point is that the server replies without knowing whether iptables will allow it or not, and when iptables receives that reply from the server on the local system, it has now seen traffic in both directions (even though the client has not yet), considers the connection established, and lets the reply out. The "technicality" here hinges on the firewall being in the middle of the two parties. – goldilocks Jun 09 '14 at 12:28