Maintaining a server one of the important steps is to manage the opening and closing of ports to avoid the ports that external malicious attacks take advantage of because the service is running all the time.
The first is the ability to view the iptables situation:
sudo iptables-l
Each rule is listed, and the rule labeled accept is that the communication indicated by this rule is successful, and the rule marked with a drop refers to the traffic represented by the block. It is important to note that in a system run, a rule is matched from start to finish, so the last rule is drop, indicating the end, and no drop in the middle, or the subsequent accept will not work.
To add a rule:
# iptables-a input-p tcp-i eth0--dport ssh-j ACCEPT
-A is appended,-p TCP represents the TCP protocol,-I eth0 represents the NIC,--dport ssh represents the port ssh (that is,),-j accept says this rule is accept. If we want to open port 9001, we'll switch ssh to 9001.
To delete a rule:
# iptables-d INPUT 3
3 refers to the third rule, that is, the table listed above with Iptables-l, the first line is the first rule.
Our last one is drop, so we want to block the communication:
# iptables-a Input-j DROP
Linux Firewall iptables utility settings