Example of opening port 80 in a firewall in Linux

Source: Internet
Author: User

Linux If the firewall is just installed when we commonly used port is not added, that is, can not access, then how to add the common port to the firewall through the state, the following we take 80 port as an example.

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:

The code is as follows Copy Code

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

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/On/restart the firewall

  code such as Under copy code

/etc/init.d/iptables stop  
 
#start open  

#restart restart


After adding the firewall rules as follows:

The code is as follows Copy Code


# Firewall Configuration written by system-config-firewall 
# Manual Customization of the This file was not RECOMMENDED. 
*FILTER&NBSP
: 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 ACCE pt 
-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, some friends like to do it

/tbody>
  code such as Under copy code

vi/etc/sysconfig/iptables

-a input-m State –state new-m tcp-p TCP –dport 80-j ACCEPT (allow port 80 via firewall)  
-a input-m State –state new-m tcp-p TCP –dport 3306-j ACCEPT (Allow port 3306 via firewall)


In this way, the two lines of error are returned when the firewall is restarted.

[Root@localhost ~]#/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 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.

The code is as follows Copy Code

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

Example of opening port 80 in a firewall in 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.