Example of Linux opening port 80 in a firewall

Source: Internet
Author: User
Tags centos iptables firewall

I've been learning Linux lately. Build a LNMP environment. Everything is fine during the test. And then reboot Linux. Access to the Web site cannot be opened again. The final reason is that there are no rules to add port 80 to the firewall. The specific methods are as follows:

It is necessary to configure the Iptables firewall under CentOS. Let's learn how to configure! , the other version:

1. Open the Iptables profile:

The code is as follows Copy Code

Vi/etc/sysconfig/iptables

Through/etc/init.d/iptables status


The command query has open port 80 if there are no two ways to handle it:

1. Modify the Vi/etc/sysconfig/iptables command to add the firewall to open 80 ports

The code is as follows Copy Code

-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 80-j ACCEPT


2. Turn off/Turn on/reboot the firewall

The code is as follows Copy Code

/etc/init.d/iptables stop

#start Open

#restart reboot


After you have added the firewall rules as follows:

The code is as follows Copy Code


# Firewall configuration written by System-config-firewall
# Manual Customization of this file is not recommended.
*filter
: INPUT ACCEPT [0:0]
: FORWARD ACCEPT [0:0]
: OUTPUT ACCEPT [0:0]
-A input-m state–state established,related-j ACCEPT
-A input-p icmp-j ACCEPT
-A input-i lo-j ACCEPT
-A input-m state–state new-m tcp-p tcp–dport 22-j ACCEPT
-A input-m state–state new-m tcp-p tcp–dport 80-j ACCEPT
-A input-m state–state new-m tcp-p tcp–dport 3306-j ACCEPT
-A input-j Reject–reject-with icmp-host-prohibited
-A forward-j Reject–reject-with icmp-host-prohibited
COMMIT

/etc/init.d/iptables restart

Add that some friends like to do it

The code is as follows Copy Code

Vi/etc/sysconfig/iptables

-A input-m state–state new-m tcp-p tcp–dport 80-j (allow 80 ports through the firewall)
-A input-m state–state new-m tcp-p tcp–dport 3306-j (Allow 3306 ports through the firewall)


In this way, you can find that when you restart the firewall, you return both lines of error.

[Root@localhost ~]#/etc/init.d/iptables Restart
Iptables: Clear Firewall rules: [OK]
Iptables: Set the chain as policy accept:filter [OK]
Iptables: Uninstalling module: [OK]
Iptables: Applying firewall rules: bad argument ' –-state '
Error occurred at Line:11
Try ' iptables-restore-h ' or ' Iptables-restore--help ' for the more information.
Failed

Finding this method does not make sense, try another way to add a port by command.

The code is as follows Copy Code

[Root@centos httpd]#/sbin/iptables-i input-p tcp--dport 80-j ACCEPT

[Root@centos httpd]#/etc/rc.d/init.d/iptables Save

[Root@centos httpd]#/etc/init.d/iptables Restart

That's it, look at the effect.

  code is as follows copy code

[Root@centos httpd]#/etc/init.d/iptables status

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.