Linux on the VPS configured Iptables firewall method

Source: Internet
Author: User

SSH are not logged up, go up very difficult to check the log, found that several IP access anomaly, should be a plug-in crawler, before the figure simple iptables disabled, can only open again, the main orders are as follows:

The code is as follows Copy Code

# View Status
Service Iptables Status

# View Rules
Iptables-l-N

# clear Default Rule
Iptables-f
Iptables-x
Iptables-z

# # # # #建立新的规则 ######
# Allow local loopback 127.0.0.1
Iptables-a input-i lo-p all-j ACCEPT

# Allow all connections that have been established
Iptables-a input-p all-m State--state established,related-j ACCEPT

# Allow all outward-initiated connections
Iptables-a output-j ACCEPT

# Refuse to Ping
Iptables-a input-p icmp-m ICMP--icmp-type 8-j REJECT

# Allow SSH service port (must be open, otherwise it will not 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 connections that are not allowed
Iptables-a input-j REJECT
Iptables-a forward-j REJECT

# Disable IP
Iptables-i input-s 124.115.0.199-j DROP
# The command for the IP segment is
Iptables-i input-s 124.115.0.0/16-j DROP
# The command to seal the whole paragraph is
Iptables-i input-s 194.42.0.0/8-j DROP
# The order to seal a few paragraphs is
Iptables-i input-s 61.37.80.0/24-j DROP
Iptables-i input-s 61.37.81.0/24-j Dropdport for the purpose, sport indicate the source, output represents the machine out, INPUT means access to the local

And then there's the Save and boot CentOS

  code is as follows copy code

Service Iptables Save # Saves the
service iptables restart # reboot
Chkconfig iptables on # Confirmation service will start automatically with the power-on

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.