I cannot connect to an OpenVPN server from a Windows client with the following error in the openvpn.log:
TCP/UDP: Socket bind failed on local address [AF_INET]127.0.0.1:22194: Cannot assign requested address
Exiting due to fatal error
To solve this problem, I have to reboot the computer or restart the Service Host: Network Service, which is very inconvenient.
If the problem occurs when you try to connect to multiple OpenVPN servers at the same time, check that multiple TAP/WinTun virtual network adapters are available in Windows.
In this case, an error will appear in openvpn.log and/or OpenVPN GUI:
All TAP-Windows/WinTun adapters on this system are currently in use
If you have more than one network adapter in Windows, check to see which process/program is using the outbound port that is specified in the details of the error. You can use netstat or PowerShell to find and kill a process that is listening on a specific port:
- TCP port:
Get-Process -Id (Get-NetTCPConnection -LocalPort 22194).OwningProcess
- UDP port:
Get-Process -Id (Get-NetUDPEndpoint -LocalPort 22194).OwningProcess
If no one is listening on the specified port, the computer might have Hyper-V services installed or WSL2 running.
This is because Windows reserves a certain dynamic range of TCP ports for Hyper-V/WSL. You can display this port range with the command:
netsh int ipv4 show excludedportrange tcp
Protocol tcp Port Exclusion Ranges
Start Port End Port
---------- --------
5985 5985
47001 47001
You will get an error if this range overlaps with the outgoing port range of the OpenVPN client: TCP/UDP: Socket bind failed on local address
. Change the outgoing port range in the OpenVPN client settings:
- Right-click on the OpenVPN GUI tray icon;
- Select Settings -> Advanced -> Management interface, and change the Port Offset value so that it is not in the reserved range;
- Save the changes.
After that, you will be able to connect to your OpenVPN server.
lport 10001