Question:
How to block a specific network port in Linux?
Answer:
Use iptables commands.
E.g. to block port 21 & 22:
iptables -A OUTPUT -p tcp --dport 21 -j REJECT iptables -A OUTPUT -p tcp --dport 22 -j REJECT
To block a port permanently
- save iptables to a file,
iptables-save > /etc/sysconfig/iptables
- add this line to /etc/rc.local
iptables-restore < /etc/sysconfig/iptables