If the iptables firewall is not configured properly, we will not be able to access the server on our own. Let's take a look at our own vps in a hurry today, and we won't be able to log on through ssh, so it is very difficult to query logs, several ip address access exceptions were found, which should be a crawler of a plug-in. Previously, the simple iptables graph was disabled and can only be enabled again. The main command is as follows:
The Code is as follows: |
Copy code |
# Viewing Status $ Service iptables status
# View rules $ Iptables-L-n # Clearing default rules $ Iptables-F $ Iptables-X $ Iptables-Z ##### Create a new rule ###### # Allow local loopback 127.0.0.1 $ Iptables-a input-I lo-p all-j ACCEPT # Allow all established connections $ Iptables-a input-p all-m state -- state ESTABLISHED, RELATED-j ACCEPT # Allow all external connections $ Iptables-a output-j ACCEPT # Reject ping $ Iptables-a input-p icmp-m icmp -- icmp-type 8-j REJECT # Allow the SSH service port (you must open it, or you will not be able to use ssh) $ Iptables-a input-p tcp -- dport 22-j ACCEPT # Allow Web Service ports $ Iptables-a input-p tcp -- dport 80-j ACCEPT # Deny all other unpermitted connections $ Iptables-a input-j REJECT $ Iptables-a forward-j REJECT # Disabling ip addresses $ Iptables-I INPUT-s 124.115.0.199-j DROP # The command for sealing IP segments is $ Iptables-I INPUT-s 124.115.0.0/16-j DROP # The command for sealing the entire segment is $ Iptables-I INPUT-s 194.42.0.0/8-j DROP # The command for sealing several segments is $ Iptables-I INPUT-s 61.37.80.0/24-j DROP $ Iptables-I INPUT-s 61.37.81.0/24-j DROP |
Dport indicates the target, sport indicates the source, output indicates the local output, and input indicates the local access
Then, save and start centos.
The Code is as follows: |
Copy code |
# Save $ Service iptables save # Restart $ Service iptables restart # Confirm that the service will be automatically started upon startup $ Chkconfig iptables on
|
Summary
If we modify the ssh port, we must also change the connection port in ssh. Otherwise, the server will be okay but you will not be able to access the port. At the same time, try not to use the default ssh port.