How to open the port under linux and check whether it is successfully opened

foreword

When using linux, we often need to check whether the port is open. Here is how to check it.

1. Open port process

1.1 View firewall status

firewall-cmd  --state

insert image description here
The state here is that the firewall is not closed, if it is running, it is in the running state.

1.2. Open ports

firewall-cmd --zone=public --add-port=6123/tcp --permanent

The open port here is port 6123, and you only need to change it to other ports to open other ports.

1.3. Reload

firewall-cmd --reload

1.4 Check if the port is open

netstat -aptn |grep 6123

insert image description here
After the port is opened, execute this command on the local machine, and you can see which program opened the port. For example, here is the port 24973, which is the java process.
Or other machines can execute the telnet command to check whether it is open.
For example, if I telnet this machine from other machines that communicate with each other in the network, I will get the following prompt, which means the opening is successful.

telnet 192.168.184.129 6123

insert image description here

Summarize

Open port means that the port needs to be opened only when the firewall is open. If the firewall is closed, there is no need to open the port. If you need to open or close the firewall, execute the following command

systemctl start firewalld.service
systemctl stop firewalld.service

If you need to boot, turn on and off the firewall and execute the following command

systemctl disable firewalld.service 开机关闭防火墙					
systemctl enable firewalld.service 开机启动防火墙

Guess you like

Origin blog.csdn.net/qq_34526237/article/details/130814398