Linux firewall iptables utility settings

  
        

One of the important steps in maintaining a server is to manage the opening and closing of ports to avoid running out of services, and external malicious attacks exploit the ports occupied by those services.

The first step is to be able to view iptables:

sudo iptables -L

will list each rule. The rule labeled ACCEPT means that the communication indicated by this rule can be successful. The rule labeled DROP refers to blocking the communication represented. It should be noted that in the system operation, the rules will be matched from the beginning to the end, so the last rule is DROP, indicating the end, and there can be no DROP in the middle, otherwise the subsequent ACCEPT will not work.

Adding rules:

# iptables -A INPUT -p tcp -i eth0 --dport ssh -j ACCEPT

-A means append, -p tcp means tcp protocol, -i Eth0 indicates the network card, --dport ssh indicates the port ssh (that is, 22), and -j ACCEPT indicates that the rule is ACCEPT. If we want to open the 9001 port, we will replace ssh with 9001.

Delete rule:


# iptables -D INPUT 3

3 means the third The rule is the one listed above with iptables -L. The first line is the first rule.

Our last one is DROP, so block communication:


# iptables -A INPUT -j DROP
						
Copyright © Windows knowledge All Rights Reserved