How does Centos use iptables to disable access from certain IP addresses?

Source: Internet
Author: User
Tags centos iptables

When we have our own linux Services, a lot of operations require a little linux Foundation. It is not as simple as using people's virtual hosts in the past... Uncle often met some wonderful people. In order not to allow their access, he had to prohibit access from some IP addresses... What should I do in linux? In fact, the method is very simple! After logging on to root through ssh

Run the following command to disable access from an IP address:

Iptables-I INPUT-s ***. ***-j DROP
To unban access from an IP address, you must run the following command:

Iptables-d input-s ***. ***-j DROP
The difference between the two commands is that "-I" represents Insert (add), and "-D" represents Delete (Delete)

You can use these two commands to simply disable and unban access rules for an IP address!

Run the following command:

Iptables-list
You can view the IP rule table of the current linux server

To clear the IP rule table on the current server, run the following command:

Iptables-flush
To ban an IP segment, run the following command:

Iptables-I INPUT-s 121.0.0.0/8-j DROP
Run the following command:

Iptables-L
Check whether the rule has taken effect.

Finally, you can save and restart iptables.

/Etc/rc. d/init. d/iptables save
Service iptables restart

Appendix: other common commands

Edit The iptables file

Vi/etc/sysconfig/iptables

Disable/enable/restart firewall

/Etc/init. d/iptables stop
 
# Start
 
# Restart

Verify that all rules have taken effect:

Iptables-L

Save and restart iptables

/Etc/rc. d/init. d/iptables save
Service iptables restart

Related Article

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.