How to open a port in centos?

coldplay.xixi
Release: 2020-06-20 13:09:12
Original
13755 people have browsed it

How to open a port in centos?

How to open a port in centos?

How to open a port in centos:

1. iptables (centos 6 and before)

1. Turn on/off/restart the firewall

Turn on the firewall (it will take effect permanently after restarting):chkconfig iptables on

Turn off the firewall (it will take effect permanently after restarting):chkconfig iptables off

Turn on the firewall (effective immediately, invalid after restart): service iptables start

Turn off the firewall (effective immediately, invalid after restart): service iptables stop

Restart the firewall: service iptables restartd

2. Check the open ports

/etc/init.d/iptables status
Copy after login

3. Open a certain port (take 8080 as an example)

(1) Open the port

iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
Copy after login

(2) Save and restart the firewall

/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart
Copy after login

4. Open the port between 49152~65534

iptables -A INPUT -p tcp --dport 49152:65534 -j ACCEPT
Copy after login

Similarly, Here you need to save the settings and restart the firewall.

5. Other opening methods

We can also open the port by modifying the /etc/sysconfig/iptables file, as follows

vi /etc/sysconfig/iptables
Copy after login

and then in Add a line to the file

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT
Copy after login

Parameter description:

–A The parameter is regarded as adding a rule

–p specifies what protocol it is, our commonly used tcp protocol, of course There are also udp, for example, DNS

-dport of port 53 is the target port. When data enters the server from the outside, it is the target port

-sport. When data goes out of the server, it is the data source port.

–j means to specify ACCEPT - to receive or DROP not to receive

2. firewalld (centos7)

Centos7 has firewalld installed by default, if it is not installed , can be installed using yum install firewalld firewalld-config.

1. Start the firewall

systemctl start firewalld
Copy after login

2.Disable the firewall

systemctl stop firewalld
Copy after login

3.Set the startup

systemctl enable firewalld
Copy after login

4.Stop and disable the startup

sytemctl disable firewalld
Copy after login

5. Restart the firewall

firewall-cmd --reload
Copy after login

6. Check the status

systemctl status firewalld或者 firewall-cmd --state
Copy after login

7. Check the version

firewall-cmd --version
Copy after login

8. Check the help

firewall-cmd --help
Copy after login

9. Check the area information

firewall-cmd --get-active-zones
Copy after login

10. Check the area information to which the specified interface belongs

firewall-cmd --get-zone-of-interface=eth0
Copy after login

11. Reject all packets

firewall-cmd --panic-on
Copy after login

12. Cancel the rejection status

firewall-cmd --panic-off
Copy after login

13 .Check whether it is rejected

firewall-cmd --query-panic
Copy after login

14.Add the interface to the zone (the default interfaces are all in public)

firewall-cmd --zone=public --add-interface=eth0(永久生效再加上 --permanent 然后reload防火墙)
Copy after login

15.Set the default interface zone

firewall-cmd --set-default-zone=public(立即生效,无需重启)
Copy after login

16.Update the firewall rules

firewall-cmd --reload或firewall-cmd --complete-reload(两者的区别就是第一个无需断开连接,就是firewalld特性之一动态
添加规则,第二个需要断开连接,类似重启服务)
Copy after login

17. View all open ports in the specified area

firewall-cmd --zone=public --list-ports
Copy after login

18. Open ports in the specified area (remember to restart the firewall)

firewall-cmd --zone=public --add-port=80/tcp(永久生效再加上 --permanent)
Copy after login

Recommended tutorial: "centos Tutorial

The above is the detailed content of How to open a port in centos?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!