iptables - rule to block all other incoming traffic except ssh

I currently have the following rules to allow connections to my SSH server on port 2233:

iptables -A INPUT -p tcp --dport 2233 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 2233 -m conntrack --ctstate ESTABLISHED -j ACCEPT

However, I now need to write a rule that blocks all other incoming traffic apart from the incoming traffic to the SSH on port 2233. I also need to enable logging for all other blocked traffic to be labelled as "BLOCKED TRAFFIC >"

Any help would be greatly appreciated. Thanks!

3

1 Answer

Just append this:

iptables -A INPUT -j LOG --log-prefix "BLOCKED TRAFFIC > " --log-level 4
iptables -A INPUT -j DROP

Packets not matched by previous ACCEPTs (or DROPs) will be processed and so get LOGged and then DROPped...

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like