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...
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!
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...