Score:0

iptables - rule to block all other incoming traffic except ssh

cn flag

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!

David avatar
cn flag
What version of Ubuntu?
Nigel Wash avatar
cn flag
@David Ubuntu 20.04
Doug Smythies avatar
gn flag
If there is something wrong with the answer I provided to your previous question about this, then please say so there, and I'll edit the answer accordingly, if I am able. Don't start a new question. That answer took considerable time.
Score:1
us flag

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.