Linux iptables: Scenario 1

Source: Internet
Author: User

Linux iptables: Scenario 1

"Linux iptables: Rule principles and basics" and "Linux iptables: Rule composition" describe the basics of iptables and the composition of iptables rules. This article uses actual operations to demonstrate iptables application scenarios.

Firewall setting policy

--------------------------------------------------------------------------------

Firewall Configuration policies are generally divided into two types: one is "pass", and the other is "Block:

By default, all data packets are not allowed to pass. Rules are defined for allowed data packets.

The blocking policy means that all data packets are allowed to pass by default, and rules are defined for the data packets to be rejected.

Generally, server firewall settings adopt the first policy with higher security. The scenario described in this article also uses the "pass" policy.

Scenario Definition

--------------------------------------------------------------------------------

Assume that this article implements the rules defined in the following scenarios:

1. open ports 80, 22, and 10-21 of the Local Machine to all addresses;

2. Enable ICMP Packet Access for All addresses;

3. Access from other unpermitted ports is prohibited.

Iptables rule implementation

--------------------------------------------------------------------------------

To implement the command operations defined above:

Clear all default rules first

Iptables-F

Open Port

Iptables-I INPUT-p tcp -- dport 80-j ACCEPT

Iptables-I INPUT-p tcp -- dport 22-j ACCEPT

Open ICMP

Iptables-I INPUT-p icmp-j ACCEPT

Disable other ports

Iptables-a input-j REJECT

View rules

Iptables-L-n

Operation Result:

Key Points of iptables rule Definition

--------------------------------------------------------------------------------

Note the following points during the above operations:

1. Be sure to allow access from port 22. Otherwise, SSH will be disconnected immediately when iptables-a input-j REJECT is INPUT, and remote operations cannot be performed;

2. iptables-a input-j REJECT must be appended to the end of the rule using command A, and cannot be inserted using the I command, so that the rejected operation will take effect at the end;

3. You can use the Start port: End port to specify a port in a continuous range.

-------------------------------------- Split line --------------------------------------

Disable the default firewall in CentOS 7.0 and enable the iptables firewall.

Iptables examples

Linux Firewall iptables

Basic use of iptables backup, recovery, and firewall scripts

Detailed description of firewall iptables usage rules in Linux

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

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.