Iptables firewall problems caused by ssh logon Failure in VPS

Source: Internet
Author: User
Tags ssh port

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.

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.