This does what you ask for, I assume you can connect via serial, or you will be effectively locking yourself out. Nobody can make incoming connections, not even you. I have set the FORWARD
chain to DROP
, change that to match your needs.
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT DROP [0:0]
-A INPUT -m conntrack --ctstate INVALID -j DROP
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s $ip -p tcp -m multiport --dports 22,80,443 -m conntrack --ctstate NEW -j ACCEPT
-A OUTPUT -m conntrack --ctstate INVALID -j DROP
-A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp -m multiport --dports 80,443 -m conntrack --ctstate NEW -j ACCEPT
-A INPUT -j DROP
-A OUTPUT -j DROP
COMMIT
Replace $ip
with the source IP you will be connecting from.
Of course, if you are working with zones, the configuration is totally different.