Recently I was learning Linux. Build a LNMP environment. Everything is fine during the test. Then restart Linux. Visiting the website again cannot be opened. The final reason is that there are no rules to join port 80 in the firewall. Here's how:
It is very necessary to configure the Iptables firewall under CentOS. Come to us to learn how to configure! , other versions:
1. Open the Iptables configuration file:
Code to copy code as follows
Vi/etc/sysconfig/iptables
by/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 a firewall open 80 port
Code to copy code as follows
-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 80-j ACCEPT
2. Turn off/On/restart the firewall
Code to copy code as follows
/etc/init.d/iptables stop
#start Open
#restart restart
After adding the firewall rules as follows:
Code to copy code as follows
# Firewall configuration written by System-config-firewall
# Manual Customization of this file are 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 (www.111cn.net)
-A forward-j Reject–reject-with icmp-host-prohibited
COMMIT
/etc/init.d/iptables restart
Add, some friends like to do it
Code to copy code as follows
Vi/etc/sysconfig/iptables
-A input-m state–state new-m tcp-p tcp–dport 80-j ACCEPT (allow 80 ports through the firewall)
-A input-m state–state new-m tcp-p tcp–dport 3306-j ACCEPT (Allow 3306 ports through the firewall)
In this way, the two lines of error are returned when the firewall is restarted.
[Email protected] ~]#/etc/init.d/iptables restart
Iptables: Clear Firewall rule: [OK]
Iptables: Set the chain to policy accept:filter [OK]
Iptables: Uninstalling module: [OK]
Iptables: Application firewall rules: Bad argument ' –-state '
Error occurred at Line:11
Try ' iptables-restore-h ' or ' Iptables-restore--help ' for more information.
Failed
Finding this method is not so easy, so try another way to add a port by command.
Code to copy code as follows
[[email protected] httpd]#/sbin/iptables-i input-p TCP--dport 80-j ACCEPT
[Email protected] httpd]#/etc/rc.d/init.d/iptables Save
[Email protected] httpd]#/etc/init.d/iptables restart
That's it, look at the effect.
Code to copy code as follows
[Email protected] httpd]#/etc/init.d/iptables status
From:http://www.111cn.net/sys/linux/58147.htm
Example of opening port 80 in a firewall in Linux