Use iptables to block IP segments in Linux

Source: Internet
Author: User
124. *. * This ip segment is very disgusting, it is recommended to block # iptables-F # iptables-PINPUTACCEPT # iptables-POUTPUTACCEPT # iptables-PFORWARDACCEPT # iptables-AFORWARD-s124.115.0.0/24-jDROP # iptables on the server

124. 115. *. * This ip segment is very disgusting. we recommend that you block it on the server.





# Iptables-a forward-s DROP

# Iptables-I FORWARD-d DROP

Supplement ::

The command to block a single IP address is:

Iptables-I INPUT-s DROP

The command to block IP segments is:

Iptables-I INPUT-s DROP

Iptables-I INPUT-s DROP

Iptables-I INPUT-s DROP

The command to block the entire segment is:

Iptables-I INPUT-s DROP

The command for sealing several segments is:

Iptables-I INPUT-s DROP

Iptables-I INPUT-s DROP

There are three methods to start self-running on the server:

1. add it to/etc/rc. local.

2. iptables-save>;/etc/sysconfig/iptables can put your current iptables rules into/etc/sysconfig/iptables, which is automatically executed when the system starts iptables.

3. service iptables save can also put your current iptables rules in/etc/sysconfig/iptables. The system automatically runs iptables when it starts.

The last two are better. Generally, the iptables service is enabled before the network service, which is safer.

To unseal:

Iptables-d input-s IP address-j REJECT

Iptables-F cleared

I accidentally couldn't even connect myself -_-!!!

Iptables-I INPUT-p tcp -- dport 80-s

In the future, only port 80 will be blocked. No problem will occur!

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: 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.