端口占用

发布时间 2023-03-28 23:21:56作者: _rainyday

Problem background:

When test rmi-client to server,the latter's default port was occupied,
even if we use netstat -ano|fidnstr 1099to seek whick application has occupyied it,We get null.

Reason

Hyper-v

because i installed wsl-v2last night, when it get worse.
because wsl-v2use Hyper-v.Windows dispense some port to it,make these ports becoming reservations.So we can not find it in netstat -ano.

Resolve

  1. Find the dynamic port range
netsh int ipv4 show dynamicport tcp

image.png
it including some ports that is used as reservation of Hyper-V

  1. Find the reserved ports
netsh interface ipv4 show excludedportrange protocol=tcp

image.png
Number 1099 is in it range.So we must avoid it.

  1. Update dynamicly reserved port number(adminsitrator mode)
netsh int ipv4 set dynamic tcp start=49152 num=16384
  • Note:

A command can be used to remove some ports from the reserved port list

netsh int ipv4 add excludedportrange protocol=tcp startport=1430 numberofports=1

OR

turn off Hyper-v,your WSL-v2 still working
every time launch Docker ,wsl must use service docker start……