When installing nginx, mysql, tomcat and other services, we may encounter the problem that the ports we need to use are inexplicably occupied. Here is how to solve this problem. Speaking of ports, we have to mention firewalls. This article will also briefly introduce how to configure firewall development ports. Various methods to view port status in Linux The mapping relationship of all ports is in the /etc/services file. A brief introduction to Linux ports. Port numbers range from 0 to 65536. The uses of each numbered port are as follows: 0-1023: Well-known ports, bound to common services (FTP, SSH) 1024-49151: registered port, used to bind to some services 49152-65535: Dynamic or private ports, can be used for any network connection Ports are divided into TCP and UDP transmission protocols. Linux view port status command You can use the following command to check the port status. Click the command to adjust the usage details of each command: # View the port bound to this machine nmap 127.0.0.1 # Check port 3306 netstat -anlp | grep 3306 # Check interface 3306 lsof -i:3306 How to release occupied ports in Linux The solution steps are as follows: Find the process occupying the port Kill the process Use the following command: # Can be written as a command netstat -anp|grep 8080|awk '{print $7}'|awk -F '/' '{print $1}'|xargs kill -s 9 The meaning of each command is as follows: Step-by-step solution to release occupied ports Check whether the port is occupied For example, if you need to check whether port 8080 is occupied, you can use the following command Query the process occupying the port You can use the lsof command to view You can also use netstat and grep to view The last line of the command is the PID and name of the process occupying port 8080. Kill the process occupying the port You can use the kill command to directly kill the process found in the previous step. Linux firewall releases ports Linux firewall startup and shutdown The firewall introduced below is iptable, which is not applicable to firewalld. Turn on the firewall (permanent after restart): chkconfig iptables on Check the firewall status in Linux You can use the following command to view: /etc/init.d/iptables status # Or simply iptables status iptables -L # You can also directly view the configuration file vim /etc/sysconfig/iptables Open a port in Linux firewall For example, to open port 8080, use the following command: iptables -A INPUT -p tcp --dport 8080 -j ACCEPT # You also need to restart the service service iptables restart # You can also directly edit the configuration file vim /etc/sysconfig/iptables # Then add a line to the end of the file to open all ports between 8080 and 8181 iptables -A INPUT -p tcp --dport 8080:8181 -j ACCEPT in The The above is about Linux forced release of occupied ports and Linux firewall port opening method. For more articles about Linux ports, please click the related articles below You may also be interested in:
|
<<: Detailed examples of converting rows to columns and columns to rows in MySQL
>>: Several ways to generate unique IDs in JavaScript
First, create a tomcat folder. To facilitate the ...
I had nothing to do, so I bought the cheapest Ali...
1. Stop the database server first service mysqld ...
Recently, when running an old RN project, the fol...
1: Docker private warehouse installation 1. Downl...
1.1. Download: Download the zip package from the ...
I recently encountered a problem. The emoticons o...
Introduction: AD is the abbreviation of Active Di...
WeChat applet calculator example, for your refere...
Color contrast and harmony In contrasting conditi...
When building a website, HTML language may seem un...
After MySQL 5.7.18 is successfully installed, sin...
Introduction: This article mainly introduces how ...
In the past, it was quite troublesome to achieve ...
Table of contents 1. Rule 1: Object.Method() 1.1 ...