Podemos desativar a política de INPUT para bloquear tudo e permitir apenas portas específicas
# allow established sessions to receive traffic
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# allow your application port
iptables -I INPUT -p tcp --dport 42605 -j ACCEPT
# allow SSH
iptables -I INPUT -p tcp --dport 22 -j ACCEPT
# Allow Ping
iptables -A INPUT -p icmp --icmp-type 0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# allow localhost
iptables -A INPUT -i lo -j ACCEPT
# block everything else
iptables -A INPUT -j DROP
Another question, would this be the right way to test, or maybe I should use "netstat" command to see which port has connection established with the other ip?
Sim, você pode verificar netstat -antop | grep app_port
e também pode usar strace:
strace -f -e trace=network -s 10000 PROCESS ARGUMENTS
Para monitorar um processo existente com um pid conhecido:
strace -p $( pgrep application_name) -f -e trace=network -s 10000