Reasons and Solutions for Ports Occupied

When running the software or project, the following problems occur:

panic: blademaster: listen tcp: 0.0.0.0:8080: listen tcp 0.0.0.0:8080: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

Windows system

The first case: occupied by other programs

1. First determine who is occupying the port.

1) Use Run to open cmd , directly enter netstat -ano, press Enter, and the rightmost one corresponds to PID=1328.

 Note: It is not recommended to use this command, there are too many ports to see

2) Use Run to open cmd , directly enter the following command, and press Enter. Check the PID corresponding to the occupied port .

netstat -aon | find "8080" or netstat -aon | grep "8080" # is to view the occupancy of a single port of 8080

******************************************************************************************************

netstat -aon | findstr "80" or netstat -aon | findstr :80 # is to view a series of ports including 80, for example 800,8080

2. To view the process corresponding to the PID, enter tasklist|findstr "9880" to view the process occupying the port

tasklist|findstr  "9880"

It can be seen from the above that the "vmware-hostd.exe" program occupies this port

 1) Kill the process according to the process number

taskkill -f -pid 9880 或 taskkill /f /t /im vmware-hostd.exe

2) Find the corresponding process in the task manager and end the process directly

Case 2: Listed as a reserved port by the system

It indicates that the port is occupied, but the occupied process cannot be found.
The reason is that Windows reserves some ports that happen to be in the sequence of ports reserved by the system.

Use the following command to view

netsh interface ipv4 show excludedportrange protocol=tcp

Possible reasons why Windows reserves these ports:

  • Blocked by Microsoft for finding virus activity
  • After installing windows update, the list of reserved ports has changed
  • Enable the Hyper-V feature

There are three solutions:

  1. switch to another port
  2. Turn off the Hyper-V feature (it may still be occupied after it is turned off)
  3. Set these ports as Administered port exclusions

netsh int ipv4 add excludedportrange protocol=tcp startport=8000 numberofports=300

After executing this command, restart and query the reserved ports again, you will find that there will be a * at the end of the port list, and these ports will not be used by Hyper-V at this time.

Linux system

1. View port usage

netstat -tln //check all

netstat -tln | grep 80 //Only check the usage of port 80

netstat -aptn //View all open port numbers under the current user

netstat -nupl //View all port number information using udp protocol in the system

netstat -ntpl //View the port number information using the tcp protocol in the system

2. Check which program the port belongs to? Which process occupies the port

lsof -i :80

3. Kill the process that occupies the port

kill -9 process id

Guess you like

Origin blog.csdn.net/fbbqt/article/details/126928487