Simple firewall settings for Linux

Source: Internet
Author: User

Common commands

Iptables-l-N view firewall rules;

Iptables-f to clear all rule chains in the preset table filter

Iptables-x Clear Preset table rules in user-defined chains in filter

/etc/rc.d/init.d/iptables save to write the changes to the/etc/sysconfig/iptables file.

Set rules

[Email protected] ~]# iptables-p INPUT DROP

[[email protected] ~]# iptables-p OUTPUT ACCEPT

[Email protected] ~]# iptables-p FORWARD DROP

( This means that when you go beyond the two chain rules (Input,forward) in the filter table in the Iptables, the packets that are not in the two rules are handled, and that is the drop (abort). It should be said that this configuration is very safe. We want to control the incoming packets.

and for Output chain, that is, out of the package we do not have to do too much restriction, but to take the accept, that is, not in the rules of the package how to do it, that is through.

can see The Input,forward two chain uses what packets are allowed to pass through, while the output chain is not allowed by what packets pass.

This setting is quite reasonable , of course, you can also drop three chains, but I think it is not necessary, and to write the rules will increase. But if you only want a few rules that are limited, such as just Web servers. It is recommended that all three chains are drop.

Open common ports:

Iptables-a input-p TCP--dport 22-j ACCEPT (SSH)

Iptables-a input-p TCP--dport 80-j ACCEPT (web)

Iptables-a input-p TCP--dport 110-j ACCEPT (mail)

Iptables-a input-p TCP--dport 25-j ACCEPT (mail)

Iptables-a input-p TCP--dport 21-j ACCEPT (FTP)

Iptables-a input-p TCP--dport 20-j ACCEPT (FTP)

Iptables-a input-p TCP--dport 53-j ACCEPT (DNS)

Iptables-a output-p icmp-j ACCEPT (OUTPUT set to drop)

Iptables-a input-p icmp-j ACCEPT (INPUT set to drop)

Iptables-a input-i lo-p all-j ACCEPT (if INPUT DROP)

Iptables-a output-o lo-p all-j ACCEPT (if OUTPUT DROP)

Simple firewall settings for Linux

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.