How to configure iptables firewall on VPS in linux

Source: Internet
Author: User

In linux, the iptables firewall is configured on VPS. Only apache in linux can use this function. This function is not specific in windows.

Ssh Login fails. It is difficult to check the logs and find that access from several ip addresses is abnormal. It should be a crawler of a plug-in. Previously, the simple iptables graph was disabled and can only be enabled again, the main Commands are 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 DROPdport indicates the target, sport indicates the source, output indicates the local output, and input indicates accessing the Local Machine

Then, save and start centos.

The Code is as follows: Copy code

Service iptables save # save
Service iptables restart # restart
Chkconfig iptables on # confirm that the service will be automatically started upon startup

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.