GGshow reloaded GGshow reloaded

March 9, 2015

How to block a specific network port in Linux?

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

  1. save iptables to a file,
    iptables-save > /etc/sysconfig/iptables
  2. add this line to /etc/rc.local
    iptables-restore < /etc/sysconfig/iptables
Filed under: Linux,Web Servers — Tags: , , — GG @ 5:27 pm

© 2024 GGSHOW | Powered by WordPress