Configure iptables in CentOS to allow access from Port 80 of the Web server

Source: Internet
Author: User
We add port 80 as an example: [root @ centoshttpd] #/sbin/iptables-IINPUT-ptcp -- dport80-jACCEPT save [root @ centoshttpd] #/etc/rc. d/init. d/iptablessaveiptables: save the firewall rule to/etc/sysconfig. The following is an example of adding port 80:
[Root @ CentosHttpd] #/sbin/ Iptables-I INPUT-ptcp -- dport 80-j ACCEPT save
[Root @ centos httpd] #/etc/rc. d/init. d/iptables save
Iptables: save the firewall rules to/etc/sysconfig/iptables: [OK]
If the above steps are not complete, it may be that the iptables file uses include call.

Generally, this path is/etc/sysconfig/iptables.
Or use vi to open the file and modify it.

[Root @ centos httpd] # vi/etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Tue Feb 14 07: 32: 182012
* Filter
: Input accept [0: 0]
: Forward accept [0: 0]
: Output accept [7: 640]
-A input-p tcp-m tcp -- dport 10000-j ACCEPT
-A input-p tcp-m tcp -- dport 80-j ACCEPT
-A input-m state -- state RELATED, ESTABLISHED-j ACCEPT
-A input-p icmp-j ACCEPT
-A input-I lo-j ACCEPT
-A input-p tcp-m state -- state NEW-m tcp -- dport 22-jACCEPT
-A input-j REJECT -- reject-with icmp-host-prohibited
-A forward-j REJECT -- reject-with icmp-host-prohibited
COMMIT
# Completed on Tue Feb 14 07:32:18 2012

Restart the service
[Root @ centos httpd] # service iptables restart
Iptables: clear firewall rules: [OK]
Iptables: Set the chain to policy ACCEPT: filter [OK]
Iptables: uninstalling module: [OK]
Iptables: application firewall rules: [OK]

Check whether the port is effective:
[Root @ centos httpd] #/etc/init. d/iptables status
Table: filter
Chain INPUT (policy ACCEPT)
Num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 10000
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt: 80

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.