Redhat CentOS Linux firewall configuration __linux

Source: Internet
Author: User
Tags iptables

#清空iptables规则

Iptables-f Iptables-x
Iptables-z
Iptables-t nat-f
Iptables-t Nat-x
Iptables-t nat-z
Iptables-p INPUT DROP
Iptables-p OUTPUT DROP
Iptables-p FORWARD DROP

#开放回环网卡lo
Iptables-a input-i lo-j ACCEPT
Iptables-a Output-o lo-j ACCEPT

#开放web80端口
Iptables-a input-p TCP--dport 80-j ACCEPT
Iptables-a output-p TCP--sport 80-j ACCEPT

Iptables-a input-p TCP--dport 8080-j ACCEPT
Iptables-a output-p TCP--sport 8080-j ACCEPT

Iptables-a input-p TCP--dport 8081-j ACCEPT
Iptables-a output-p TCP--sport 8081-j ACCEPT

Iptables-a input-p TCP--dport 8888-j ACCEPT
Iptables-a output-p TCP--sport 8888-j ACCEPT

#开放ping
Iptables-a input-p icmp-j ACCEPT
Iptables-a output-p icmp-j ACCEPT

#开放ssh
Iptables-a input-p TCP--dport 22-j ACCEPT
Iptables-a output-p TCP--sport 22-j ACCEPT

Iptables-a input-p TCP--dport 2222-j ACCEPT
Iptables-a output-p TCP--sport 2222-j ACCEPT

#开放某IP所有连接端口
Iptables-a input-s 127.0.0.1-p tcp-j ACCEPT
Iptables-a output-d 127.0.01-p tcp-j ACCEPT

Iptables-a input-m State--state established,related-j ACCEPT
Iptables-a output-m State--state established,related-j ACCEPT

Iptables-a input-m State--state invalid-j DROP
Iptables-a output-m State--state invalid-j DROP


#保存IPTABLES设置

Service Iptables Save

#重启IPTABLES服务

Service Iptables Restart

#设置开机启动IPTABLES
Chkconfig iptables on

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.