0

How to close certain TCP/UDP ports (incoming) for ALL networks except listed through IPTABLES.

I have a small set of NETWORKS I'd like to leave THE ports to be open. But want to close for all other networks.

Thank you!

bakytn
  • 1,097
  • 4
  • 15
  • 27

2 Answers2

0

Simply put an ACCEPT rule before you DROP/REJECT. For example

iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j DROP

will allow connection to TCP port 80 from 192.168.1.0/24 network while dropping all other connections to the port.

Daniele Santi
  • 2,479
  • 1
  • 25
  • 22
0

Set accept rules for all of the traffic that you want to allow through and then have a deny rule for everything else.

iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited

Allows traffic to port 80 and rejects everything else.

dmah
  • 516
  • 3
  • 5