Você pode definir a política padrão do iptables para que ela aceite apenas a comunicação de certas portas (ou um intervalo de portas):
## Drop all incoming traffic on all ports
iptables -P INPUT DROP
## Allow connections from one port
## Do not include brackets when entering the following variables,
## [portnum] is just 80 not [80]
## [interface] == default network interface (such as eth0)
## [protocol] == the protocol you want, such as tcp, udp, and etc
## [portnum] == port number, such as 80, 443, and etc
iptables -A INPUT -i [interface] -p [protocol] --dport [portnumb] -J ACCEPT
## Allow a range of ports, such as ports 1001-1005
iptables -A INPUT -i [interface] -p [protocol] --dport [portnum]:[portnum] -J ACCEPT
Espero que isso ajude.