This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Windows Sockets Error Codes

  • 6 contributors

Most Windows Sockets 2 functions do not return the specific cause of an error when the function returns. For information, see the Handling Winsock Errors topic.

The WSAGetLastError function returns the last error that occurred for the calling thread. When a particular Windows Sockets function indicates an error has occurred, this function should be called immediately to retrieve the extended error code for the failing function call. These error codes and a short text description associated with an error code are defined in the Winerror.h header file. The FormatMessage function can be used to obtain the message string for the returned error.

For information on how to handle error codes when porting socket applications to Winsock, see Error Codes - errno, h_errno and WSAGetLastError .

The following list describes the possible error codes returned by the WSAGetLastError function. Errors are listed in numerical order with the error macro name. Some error codes defined in the Winsock2.h header file are not returned from any function.

Requirements

Error Codes - errno, h_errno and WSAGetLastError

Handling Winsock Errors

FormatMessage

WSAGetLastError

Was this page helpful?

Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback .

Submit and view feedback for

Additional resources

Cannot assign requested address [SOLVED]

April 30, 2024

The "Cannot Assign Requested Address" error is quiet common in the network community and can be seen in various network-related and application specific contexts. Here are some of the common areas where this error is seen more often:

  • Nginx : When Nginx tries to bind to an IP address not present on the server, or if the port is already in use.
  • Apache : Similar to Nginx, trying to bind to an unavailable IP or a busy port.
  • Redis : Occurs when Redis is configured to bind to a specific IP that isn’t available.
  • MySQL : If MySQL is set up to listen on an IP not assigned to the server.
  • SSH : Attempting to bind to an IP address for listening or forwarding ports that isn’t available.
  • FTP Servers : Similar issues when they are set to bind to specific IPs or ports.
  • BIND : The DNS server attempting to bind to an IP address that does not exist on the local machine.
  • Postfix : When trying to bind to a non-existent IP address for receiving or sending emails .
  • OpenVPN : Trying to use an IP address for the VPN server that isn’t configured on the server.
  • Docker : When a Docker container tries to bind to an IP not available on the host machine.
  • Kubernetes : Similar issues when pods/services are configured with specific IPs.
  • Local development servers (like those started by web frameworks such as Django or Flask ) trying to bind to an IP address that the development machine does not have configured.
  • Game servers (like Minecraft, Counter-Strike) that are set to bind to a specific IP address or port which might be restricted or already in use.
  • Applications that try to bind to a port for incoming connections which might already be in use or blocked by a firewall.

In this tutorial we will try to cover most of these areas and cover the cause of getting " Cannot Assign Requested Address " error and how to solve the same in individual application:

Troubleshooting "cannot assign requested address" Error

1. validate configuration.

The "cannot assign requested address" error often occurs if application is configured to bind to an IP address that isn't assigned to any network interface on the server. You need to check the configuration file based on your application:

  • Nginx : Typically found at /etc/nginx/nginx.conf and /etc/nginx/conf.d/*.conf for additional server block configurations. Look out for listen directive for IP and port settings.
  • Apache : Commonly located at /etc/httpd/conf/httpd.conf for CentOS/RHEL or /etc/apache2/apache2.conf and /etc/apache2/ports.conf for Debian/Ubuntu systems. Look out for Listen for IP and port configurations.
  • Redis : Usually /etc/redis/redis.conf . Look out for bind and port .
  • MySQL : Typically /etc/my.cnf , /etc/mysql/my.cnf , or contained within /etc/mysql/mysql.conf.d/ . Look out for bind-address and port .
  • SSH : Check in /etc/ssh/sshd_config and look out for ListenAddress and Port .
  • FTP Servers : Depends on the software; for vsftpd it's /etc/vsftpd.conf . Look out for listen and listen_port .
  • BIND : Main configuration file is /etc/named.conf or /etc/bind/named.conf . Look out for listen-on .
  • Postfix : Main configuration file is /etc/postfix/main.cf . Look out for inet_interfaces and smtp_bind_address .
  • OpenVPN : Configuration file usually found in /etc/openvpn/server.conf . Look out for local for IP address binding.

Consider Nginx as an example, open the Nginx configuration file (usually located at /etc/nginx/nginx.conf or under /etc/nginx/sites-available/ ) and verify the listen directive:

Make sure the IP address in the listen directive is correct and available on your server.

Check if the IP address (e.g., 192.168.1.100 ) is assigned to the server:

This command lists all IPs assigned to your server. If 192.168.1.100 is not listed, that's likely the cause of your error. If the IP address is not on your machine, either assign that IP to the server through your network settings or change the IP in the Nginx configuration to one that is available on your server.

If the listen directive in your Nginx configuration does not specify an IP address and is simply set to listen on a port across all interfaces, like this:

Restart Nginx to ensure all settings are correctly applied:

Similarly you can check your application's Listen directive to make sure it is listening on proper interface address.

2. Check for Port conflict

It is possible that the port which your application is using is already in use by some other application service. You can use tools like netstat or ss command to check for port conflicts.

For example using netstat command :

If this gives an output then it would mean that the port is already in use. Similarly you can also use ss command :

If the port is already in use then you can either stop the service which is using your application port or alternatively you can configure your application to run on a different port number.

The configuration file details are provided in previous section for different services, after making the changes you can restart your application service.

3. Troubleshoot SELinux Issues

If you suspect that SELinux is causing issues (like preventing application service from binding to a port), you can check the audit logs to see the SELinux denials:

If there are no hints in the log file then you can also plan to change the mode of SELinux temporarily (until the next reboot) using:

When SELinux is in permissive mode, it continues to log violations to its policies as it would in enforcing mode, but it does not enforce the policies—meaning it allows actions that would otherwise be blocked.

After executing the above commands the changes will be applied immediately and a reboot is not required. You can e-verify your application status to see if this fixes "cannot assign requested address" error. Once you've replicated the issue in permissive mode, you can check the SELinux logs to see what would have been blocked. These logs are typically found in /var/log/audit/audit.log . You can use tools like audit2why to analyze these logs:

This command will show you the SELinux denials that occurred, along with explanations of why each action was denied under normal enforcing mode. This information is crucial for understanding what policies need to be adjusted.

To change the SELinux mode permanently, you will need to edit the SELinux configuration file:

In this file, change the SELINUX= line to either enforcing , permissive , or disabled . For example:

After making this change, you need to reboot your system for the changes to take effect. You can also read selinux changes to be persistent for more information.

Deepak Prasad

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to [email protected]

Thank You for your support!!

Leave a Comment Cancel reply

Save my name and email in this browser for the next time I comment.

Notify me via e-mail if anyone answers my comment.

cannot assign requested address windows

We try to offer easy-to-follow guides and tips on various topics such as Linux, Cloud Computing, Programming Languages, Ethical Hacking and much more.

Recent Comments

Popular posts, 7 tools to detect memory leaks with examples, 100+ linux commands cheat sheet & examples, tutorial: beginners guide on linux memory management, top 15 tools to monitor disk io performance with examples, overview on different disk types and disk interface types, 6 ssh authentication methods to secure connection (sshd_config), how to check security updates list & perform linux patch management rhel 6/7/8, 8 ways to prevent brute force ssh attacks in linux (centos/rhel 7).

Privacy Policy

HTML Sitemap

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

ssh tunnel - bind: Cannot assign requested address

Trying to create a socks (-D) ssh tunnel - Linux box to Linux box (both centos):

sshd running on remote side ok.

From local machine we do / see this:

(where 8.8.8.8 is really my server's IP and 'user' is my real username)

I am logged into the remote side in this terminal-window. I can verify that the local port was unused prior to this command, and then used by an ssh process, after the command, via:

So, unlike most googled-responses with this error, the problem would not seem to be the loopback interface assignment. If I try to use this tunnel with a mail client, the local-side permits the attempt (no 'proxy-failed' error), but no data / reply is returned.

On the remote side, I do have "PermitTunnel yes" in my sshd_config (though 'yes' should be the default, anyway).

Ideas or Clues?

Here is the relevant debug-output

Other clue: If I run a Virtual Box on the client running Windows, open a tunnel with putty in that box, that tunnel, to the same remote server, works.

Stranger Still" If I use Putty (for linux) running directly on the Linux Client, it does NOT work, even if the settings are an exact duplicate of the putty settings which DO WORK in Putty running on Windows in a Virtual Box on the same Client Machine?? There is something fishy ... still trying experiments to figure out what it is.

JosephK's user avatar

  • What if you try and force it to use ipv4? (just as an initial troubleshooting test). E.g. ssh -4 -D 1080 [email protected] –  Friedrich 'Fred' Clausen Nov 1, 2012 at 10:54
  • Can you try a higher port number, 4000? –  Baldrick Nov 1, 2012 at 10:57
  • Thanks for inputs. I got it to work with: ssh -4 -D 8081 [email protected] –  JosephK Nov 1, 2012 at 15:51

The close the loop here. The answer, in this case, was to force the ssh client to use ipv4. E.g.

Friedrich 'Fred' Clausen's user avatar

  • So I would think, except that I can select 'force ip4' in putty (running on Linux) without success. Also IPV6 is disabled on this machine, so theoretically should not have been at play. The completely inconsistent results I still get trying different permutations of this thing leave me scratching my head. In any case, your answer helped me get it working, and perhaps has uncovered something odd about how this version of CentOS or Linux Kernel or some-such is operating - Thanks. –  JosephK Nov 6, 2012 at 5:57
  • 1 Thanks a lot, the -4 was also the solution for Ubuntu 11.04. –  Sander Dec 24, 2012 at 21:03
  • 6 Instead of having to specify -4 every time, assuming all ssh connections are to be made with IPv4 only, add "AddressFamily inet" to your ssh_config file -- per user in ${HOME}/.ssh/ssh_config, or system wide for all users in /etc/ssh/ssh_config –  J G Miller Mar 13, 2017 at 13:04
  • 6 What was the clue that made you think to try -4 ? –  Paul Price Apr 28, 2018 at 0:11
  • 2 Refer to electricmonk.nl/log/2014/09/24/… . The clue is it listens on ipv6: "debug1: Local forwarding listening on ::1 port 8080." –  Haili Sun Oct 29, 2021 at 5:26

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged linux ssh tunnel ..

  • The Overflow Blog
  • Reshaping the future of API platforms
  • Between hyper-focus and burnout: Developing with ADHD
  • Featured on Meta
  • Our Partnership with OpenAI
  • Imgur image URL migration: Coming soon to a Stack Exchange site near you!

Hot Network Questions

  • Hypothesis testing: Difference of means (pre-treatment)
  • Schedule monotony constraints
  • How accurate is the model 42179 Planet Earth and Moon in Orbit?
  • Is it a bad idea to design a purposefully inconsistent magic system?
  • Text Based Game about Synthesizing Fuel from Scratch?
  • On Pareto functions
  • What can you use in your soil to kill bugs before planting vegetables?
  • Is it bad to branch off data traces into two separate connectors?
  • How does Forbiddance interact with the door to a demiplane created by the spell Demiplane?
  • Is consciousness causally superfluous?
  • A word for not just optional but usually not done
  • Is there any explanation or discussion regarding the change in the Bard class from its AD&D1ed orignal implementation?
  • How to find what is wearing out my SSDs
  • Why don't we consider the initial phase in the superposition to form a stationary wave?
  • How did the bugs get all over the place?
  • Looked at a different rolling (3d6, 3d6, average) for D&D characters in AnyDice and the result didn't come out as expected. What am I missing?
  • Is my DM taking too long to level us up?
  • Efficient C Tokenizer/Lexer in C++
  • Is a tactical nuclear strike against a military target different on a legal standpoint than a tactical nuclear strike against a civilian target?
  • Where is the mistake in the argument in favor of the (erroneous) claim "every Dedekind cut is a rational cut"?
  • Defining an output format that doesn't break Ctrl+Shift+I
  • A short fiction about an American poetess who supposedly foiled, thanks to posthumous poems, the Martian invasion described by H. G. Wells
  • Is there a minimum midi-chlorian count needed to live?
  • Conjecture about union-closed families of sets - attempt 3

cannot assign requested address windows

How I fixed Python OSError: [Errno 99] Cannot assign requested address

When binding a socket, you see an error message like

In my case, the issue was that I was trying to bind the specific IP address  192.168.1.100 but the computer running the script did not have said IP address configured on any interface.

so I needed to change the bind IP address to either  0.0.0.0 to listen to ANY IP address or I needed to change  192.168.1.100 to the IP address of the host computer I am running the script on.

Docker container [Errno 99] Cannot assign requested address

Note that for Docker containers, either you need to run them in network_mode: host to use the host’s network systemd, or you need to bind to the container’s IP address. You can not bind to the host’s IP address from the contaienr unless using  network_mode: host ! But you can forward the ports from the host, binding to a specific IP address.

If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow

  • 3D printing (46)
  • Algorithms (6)
  • Allgemein (91)
  • Android (4)
  • Arduino (7)
  • Audio/Video (29)
  • Bioinformatics (23)
  • Calculators (28)
  • cloud-init (1)
  • CoreOS (16)
  • Docker (137)
  • Kubernetes (11)
  • Portainer (3)
  • Cryptography (11)
  • Data science (11)
  • Documentation (1)
  • Economics (1)
  • Compliance (8)
  • Components (31)
  • Arduino (89)
  • ESP8266/ESP32 (165)
  • FreeRTOS (14)
  • MicroPython (15)
  • PlatformIO (157)
  • Raspberry Pi (60)
  • Teensy (10)
  • Home-Assistant (10)
  • LinuxCNC (6)
  • LumenPnP (3)
  • Medical devices (6)
  • Optoelectronics (1)
  • Teardown (1)
  • CadQuery (12)
  • ImageMagick (2)
  • InvenTree (12)
  • Wordpress (35)
  • Generators (4)
  • Leaflet (1)
  • OpenStreetMap (4)
  • Geoinformatics (5)
  • Hardware (7)
  • Alpine Linux (30)
  • systemd (16)
  • Machine learning (2)
  • Mathematics (10)
  • FreePBX (13)
  • MikroTik (59)
  • OpenWRT (14)
  • Synology (1)
  • Tactical RMM (1)
  • Headscale (15)
  • OpenVPN (2)
  • Wireguard (24)
  • ZeroTier (9)
  • Nextcloud (12)
  • OpenCASCADE (33)
  • Patents (1)
  • Performance (4)
  • Physics (7)
  • GCC errors (51)
  • Haskell (8)
  • Angular (36)
  • NodeJS (58)
  • Octave (13)
  • Cartopy (15)
  • OpenPyXL (7)
  • pandas (55)
  • Paramiko (4)
  • skyfield (6)
  • Typescript (24)
  • Subversion (2)
  • Security (5)
  • Statistics (8)
  • ElasticSearch (34)
  • MongoDB (9)
  • Jupyter (6)
  • OpenCV (10)
  • Pyppeteer (13)
  • Traefik (17)
  • Virtualization (18)
  • TechOverflow (2)
  • PowerShell (4)

Privacy Overview

Docker Community Forums

Share and learn in the Docker community.

  • Primary Action
  • Another Action

Cannot swarm init: cannot assign requested address

Expected behavior.

$ docker swarm init --listen-addr 192.168.2.28:2377 Swarm initialized …

Actual behavior

$ docker swarm init --listen-addr 192.168.2.28:2377 Error response from daemon: listen tcp 192.168.2.28:2377: bind: cannot assign requested address

Information

Attempting to follow the swarm tutorial.

Diagnostic ID: 4DA8D1D8-B659-4C77-B6E0-7CF74540D35F

Docker for Mac: version: mac-v1.12.0-beta16.2 OS X: version 10.10.5 (build: 14F1808) logs: /tmp/20160624-162929.tar.gz failure: No error was detected [OK] docker-cli [OK] app [OK] menubar [OK] virtualization [OK] system [OK] osxfs [OK] db [OK] slirp [OK] moby-console [OK] logs [OK] vmnetd [OK] env [OK] moby [OK] driver.amd64-linux

Port 2377 is available. The 192.168.2.28 address is my local ethernet card address. en3: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV> ether 38:c9:86:2f:f8:8f inet6 fe80::3ac9:86ff:fe2f:f88f%en3 prefixlen 64 scopeid 0x9 inet 192.168.2.28 netmask 0xffffff00 broadcast 192.168.2.255 nd6 options=1 media: autoselect (1000baseT <full-duplex,flow-control,energy-efficient-ethernet>) status: active

Steps to reproduce the behavior

As above, simply run the command.

I also tried this on another of my Mac machines, with the same result.

Does your use-case actually require a custom listen address? docker swarm init should work just fine.

The native Docker for Mac is not actually a native app that runs on your host’s kernel, to know about your network.

The Docker engine is running in an Alpine Linux distribution on top of an xhyve Virtual Machine on Mac OS X or on a Hyper-V VM on Windows, and that VM is managed by the Docker application.

You basically provide docker with a host interface which from its perspective doesn’t exist.

The docker command runs natively on the mac, it should be able to see the network. The docker command may start things inside a container, but the docker command itself is not in a container, so it should be able to see my network and do the needful things. This is one of the things the new docker for mac should solve, should it not?

The docker command runs natively on the mac

This is a very true statement.

What you run on your Mac is actually just a docker client command, which, indeed, is native.

On the other hand the actual Docker Engine daemon, which receives commands from the docker client, runs on linux kernel inside a VM on Mac. See the quote from my previous message. That’s actually taken out of the release message.

Just run docker info on your Mac and see the “Operating System” section.

Here’s a good example that you can try yourself:

  • Run ifconfig on you Mac
  • Run ubuntu container with --net=host , which would expose the host’s networking stack inside a container
  • Run ifconfig inside container

What you’ll see is two different sets of interfaces.

There is no such thing as native Docker Engine. Docker Engine only runs on linux kernel. So, unless you are on Linux host, you will have this issue.

I’m having this same basic issue. My iMac has the IP address 192.168.1.11 and if I …

docker swarm init --listen-addr 192.168.1.11:2377 No --secret provided. Generated random secret: 1c79m0rzsar2ng8gcuf8wz97d

Error response from daemon: listen tcp 192.168.1.11:2377: bind: cannot assign requested address

One of the responses above suggests running init without listen-addr which gives …

docker swarm init No --secret provided. Generated random secret: eufek6klwo61assrbsht8d8rw

Swarm initialized: current node (76hub80cls66ad1piyqj2quin) is now a manager.

To add a worker to this swarm, run the following command: docker swarm join --secret eufek6klwo61assrbsht8d8rw –ca-hash sha256:0d20ace10223db92413d8199b36d488475b7bf9ca0d60303433c4272bb6b055d 192.168.65.2:2377

The problem is that it is using the IP address 192.168.65.2 which is not reachable from another machine (my laptop).

I am also facing the same issue. When I try to use my mac ip address as listen address. I am getting error ‘bind: cannot assign requested address’

My Docker version : Version: 17.06.0-ce API version: 1.30 (minimum version 1.12) Go version: go1.8.3 Git commit: 02c1d87 Built: Fri Jun 23 21:51:55 2017 OS/Arch: linux/amd64 Experimental: true

I got it working using socat containers to forward swarm ports from VM network to host posted example compose file here Error response from daemon: listen tcp: bind: cannot assign requested address · Issue #1146 · moby/swarmkit · GitHub

I am facing the same issue, my IP address is 192.168.0.223 and If I run the ‘docker swarm init’ then it provide me the ip address that is not the same to the machine ip, and when I used the command ‘docker swarm init --listen-addr 192.168.0.223:2377 --advertise-addr 192.168.0.223:2377’ it said: can’t assign the requested address

please Explain, if you have the solution

Of couse it will not work like this with Docker Desktop, as it always runs the docker engine in a vm and therefor the host ip does not apply in this scenario. You can not assign an ip as listen address that does not exist in the vm.

I suggest to leave --listen-addr alone (which defaults to 0.0.0.0:2377) and probalby set --advertise-addr to your host ip:2377 instead. I have no Idea if Docker Desktop actually forwards that port from your host to the vm, but if it’s working, then this should be the way.

Seems I was wrong regarding --advertise-addr , as it only seem to specify which ip to use if multiple ips exist. I am afraid this one also needs to be known to the vm and as such stil can’t be the host ip:

Thanks for your reply. It works only if I provide the docker desktop ip address which is 172.17.0.1 in listen-addr and my machine ip to advertise-add but it doesn’t route the traffic.

I was wrong regarding --advertise-addr : unlike --listen-addr , it does not need to exist inside the utility vm and should use the {host-ip:2377}.

The --listen-addr should remain the default value.

Setup like docker swarm init --advertise-addr {DD host ip}:2377 , the swarm endpoint should accept connections on all(!) interfaces of the utility vm, and advertise the host’s ip to be used for swarm communication.

Next thing that needs to be established is: does the host os bind the vm port 2377/tcp + 7946/udp + 7946/udp + 4789/udp? It woll not work without those ports beeing forwarded from the host to utility vm. As I only have access to Docker Desktop for Windows, I can only say that from a first look it doesn’t appear like these ports are actually forwarded from the host to the utility vm.

There is a socat docker image for forwarding host ports to the services inside the virtual machine. https://hub.docker.com/r/alpine/socat

Use Case: Expose a tcp socket for accessing docker API on macOS The Docker for Mac native macOS application provides use of docker engine without the need for vagrant or other virtualized linux operating system. Docker for Mac does not provide the same docker daemon configuration options as other versions of docker-engine. macOS-socat uses socat to establish a tcp socket bound to localhost which makes available the Docker for Mac API.

It is about the Docker API, but you can also use it for Docker Swarm. I remember a similar question from the past which I can’t link now, but I played with Docker Swarm on macOS then.

As far as I know Docker Desktop forwards ports only that you explicitly forwarded with the -p option of docker run or the equivalent Docker Compose parameters in the YAML file.

Docker works because the unix socket is forwarded into the VM and the Kubernetes API server port works, but you can enable Kubernetes from the Docker Desktop UI. There is no option to enable Docker Swarm. It could be a good feature requirest if you think it would be useful.

blog post image

Andrew Lock | .NET Escapades Andrew Lock

  • ASP.NET Core

Why isn't my ASP.NET Core app in Docker working?

In this post I describe a problem I ran into the other day that had me stumped briefly—why doesn't my ASP.NET Core app running in Docker respond when I try and navigate to it? The problem was related to how ASP.NET Core binds to ports by default.

Background: testing ASP.NET Core on CentOS

I ran into my problem the other day while responding to an issue report related to CentOS. In order to diagnose the issue, I needed to run an ASP.NET Core application on CentOS. Unfortunately, while ASP.NET Core supports CentOS , they don't provide Docker images with it preinstalled. Currently, they provide Linux Docker images based on:

Additionally, while you can install CentOS in WSL , it's a lot more hassle than something like Ubuntu, which you can install directly from the Microsoft Store.

This left me with one obvious answer - build my own CentOS Docker image, and install ASP.NET Core in it "manually".

Creating the sample app with a Dockerfile.

I started by creating a sample web application using Visual Studio. I could have used the CLI to create the app, but I decided to use Visual Studio as I knew it would give me the option to auto-generate the Dockerfile as well. This would save a few minutes.

I chose ASP.NET Core Web API, used minimal APIs, disabled https, enabled Docker support (Linux) and generated the solution:

Creating a sample application using Visual Studio

This generates a Debian-based dockerfile by default (the mcr.microsoft.com/dotnet/aspnetcore:6.0 images are Debian based unless you select different tags), which looks like this:

This Dockerfile uses the best practice of multi-staged builds to ensure your runtime images are as small as possible. It shows 4 distinct phases

  • mcr.microsoft.com/dotnet/aspnetcore:6.0 AS base . This stage defines the base image that will be used to run your application. It contains the minimal dependencies to run your application.
  • mcr.microsoft.com/dotnet/sdk:6.0 AS build . This stage defines the docker image that will be used to build your application. It includes the full .NET SDK, as well as various other dependencies . This stage actually builds your application.
  • FROM build AS publish . This stage is used to publish your application.
  • base AS final . The final stage is what you would actually deploy to production. It is based on the base image, but with the publish assets copied in.
Multi-stage builds are always best-practice when you're deploying to Docker, but this one is more complex than it needs to be in general. It has additional stages to make it quicker for Visual Studio to develop inside Docker images too, using "fast mode" . If you're only deploying to Docker, not developing in Docker, then you can simplify this file.

Creating a CentOS-based ASP.NET Core image

For my testing, I only needed to run the application on CentOS, I didn't need to build on CentOS, so that meant I could leave the build stage as it was, building on Debian. It was only the first stage, base , that I would need to switch to a CentOS-based image.

I started by finding the instructions for how to install ASP.NET Core on CentOS . Each Linux distro is a little bit different, with some versions using package managers, others using Snap packages etc. For CentOS we can use the yum package manager .

Installing ASP.NET Core is thankfully, very simple. You need only to add the Microsoft package repository and install using YUM. Starting from the CentOS version 7 Docker image, we can build out ASP.NET Core Docker image:

With that change to the base image, we can now build and run our sample ASP.NET Core app on CentOS using a command like the following:

Which, when you run it and navigate to http://localhost:8000/weatherforecast, looks something like this:

Image of not found

Debugging why the app isn't responding

I hadn't expected that result. I thought that it would be a simple case of installing ASP.NET Core, and the app would just work. My first thought was that I had introduced a bug somewhere that was causing the app to fail to start, but the logs printed to the console suggested the app was listening:

Additionally, I could see that the app was also listening on the correct port, port 5000. In my Docker command I specified that Docker should map port 5000 inside the container to port 8000 outside the container, so that also looked correct.

I double checked the documentation at this point, to make sure I had the 8000:5000 the correct way around, and yes, the format is host:container

This all seemed rather odd. Presumably , the application wasn't receiving the request at all, but just to be sure, I bumped up the logging to Debug level and tried again:

Sure enough, the logs were more verbose, but there was no indication of a request making it through

So at this point I had two possible scenarios

  • The app isn't working at all
  • The app isn't correctly exposed outside of the container

To test the first case I decided to exec into the container and curl the endpoint while it was running. This would tell me whether the app was running correctly inside the container, at the port I expected. I could have used the cli to do this using docker exec ... , but for simplicity I used Docker Desktop to open a command prompt inside the container , and to curl the endpoint:

Calling curl http://localhost:5000/weatherforecast inside the docker container

Sure enough, curl -ing the endpoint inside the container (using the container port, 5000 ) returned the data I expected. So the app was working and it was responding on the correct port. That narrowed down the possible failures modes.

At this point I was running out of options. Luckily, a word in the application logs suddenly caught my eye and pointed me in the right direction. Loopback .

ASP.NET Core URLs: loopback vs. IP Address

One of the most popular posts on my blog (two years after I wrote it) is "5 ways to set the URLs for an ASP.NET Core app" . In that post I describe some of the ways you can control which URL ASP.NET Core binds to on startup, but the relevant section right now is titled "What URLs can you use?" . This section mentions that there are essentially 3 types of URLs that you can bind:

  • The "loopback" hostname for IPv4 and IPv6 (e.g. http://localhost:5000 ), in the format: {scheme}://{loopbackAddress}:{port}
  • A specific IP address available on your machine (e.g. http://192.168.8.31:5005 ), in the format {scheme}://{IPAddress}:{port}
  • "Any" IP address for a given port (e.g. http://*:6264 ), in the format {scheme}://*:{port}

The "loopback" address is the network address that refers to "the current machine". So if you access http://localhost:5000 , you're trying to access port 5000 on the current machine. This is typically what you want when you're developing, and this is the default URL that ASP.NET Core apps bind to. So when you run an ASP.NET Core app locally, and navigate to http://localhost:5000 in your browser, everything works, because everything is all coming from the same network interface, on the same machine.

However, when you're inside a Docker container requests aren't coming from the same network interface . Essentially, you can think of the Docker container as a separate machine. Binding to localhost inside the Docker container will mean your app is never exposed outside of the container, rendering it rather useless.

The way to fix this is to ensure your app binds to any IP Address, using the {scheme}://*:{port} syntax.

As noted in my previous post , you don't have to use * in this pattern, you can use anything that's not an IP address or localhost , so you can use http://*:5000 , http://+:5000 , or http://example.com:5000 etc. All of these behave identically.

By binding the ASP.NET Core application to any IP address, the request "makes it through" from the host, so it can be handled by your app. We can set the URL at runtime when we run the Docker image, using for example

or we could bake it into the Dockerfile as shown below. The following is the complete final Dockerfile I used:

With this change we can re-build the Docker image, and run the app again with

and finally, we can call the endpoint from our browser:

Successfully calling the Ddocker endpoint from the host machine

So the important take away here is:

When you build your own ASP.NET Core Docker images, make sure to configure the app to bind to any IP address, not just localhost .

Of course, the official .NET Docker Images do that already , binding to port 80 by setting ASPNETCORE_URLS=http://+:80 .

In this post I described a situation in which I was trying to build a CentOS Docker image to run ASP.NET Core. I described how I created the image by following the ASP.NET Core installation instructions, but that my ASP.NET Core app wasn't responding to requests. I walked through my debugging process to try to get to the root cause of the problem, and realised that I was binding to the loopback address. This meant the application was accessible from inside the Docker container, but not from outside it. To resolve the issue, I made sure to bind my ASP.NET Core app to any IP address, not just localhost .

Popular Tags

cannot assign requested address windows

Stay up to the date with the latest posts!

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows Cannot assign requested address Error #122

@LordVersA

LordVersA commented Sep 29, 2022

@erebe

erebe commented Sep 29, 2022

Sorry, something went wrong.

LordVersA commented Sep 29, 2022 • edited

@LordVersA

No branches or pull requests

@erebe

Cannot Assign Requested Address

Cannot Assign Requested Address: Troubleshooting Minecraft Server Joining Issues

Photo of Samuel Agwah

Networking communications can come up with specific error messages, and “cannot assign requested address” is among these errors. This is common to Java-based client-server applications like Minecraft , a popular game in Java that communicates with the server and other machines using TCP and sockets.

This error is down to specific issues such as busy servers, troubleshooting issues, busy IP addresses, DNS problems, and local ports which do not have binds. We will walk you through how to identify and solve the problem.

What Does “Cannot Assign Requested Address” Mean?

Common causes of the “cannot assign requested address” error, how to fix the “cannot assign requested address” error, advanced troubleshooting for “cannot assign requested address” error.

“Cannot Assign Requested Address” means that operating systems reject PuTTY’s parameters when they are invalid for constructing a network connection. The error usually occurs without PuTTY attempting to make any connections or when an attempt is made to connect to an invalid port number.  

The error message might appear when IP addresses are incorrect, and ports need to be correctly forwarded, or when running an address, and the subdomain is pointing to a non-local IP for your device, i.e., not 192.168.x.x

…also read: How to Get Cave Only World in Minecraft [ver. 1.8 – 1.16 – 1.19]

Common causes of a “cannot assign requested address error” are incorrect mapping, busy IP address, DNS problems, and local ports which do not have binds. It can occur while using web and application servers such as WebLogic and Jetty.

Typically, the port is in use, or the requested local address cannot be assigned. The port might be busy because something has already started using it (another instance of the server), or another example left the port in the CLOSE_WAIT state.

In addition, The message “cannot assign requested address” suggests that the hostname/IP you try to bind does not resolve to a local network interface. 

Troubleshooting the common causes of the error can help in resolving the issue:

  • Examine your mapping order before starting up your server. 
  • Cross-check your port number if there is a mismatch or an incorrect number. 
  • Check if the ports are correctly forwarded.
  • Check the hostname linking your IP address.

An error like this indicates that the IP address is unreliable. It is also possible that there is a mismatch. To fix the error, do a correct mapping before starting your web server/application Server. When you start your Web server, it listens on a port. For example, jetty listens on 8080 8084 for HTTP and HTTPS traffic. 

These are responsible for binding a socket to a port and local address. Also, the hostname you give them (dev host or localhost) is what they use in Linux or Windows to resolve the domain name into an IP address. Thus an incorrect mapping in this order would bring out the error message.

The most important thing is not to confuse the “cannot assign requested address” error with an address already in use. Refrain from assuming the two processes are listening on the same port when you get this error. Try to recall the mapping by thinking of the hostname to IP address resolution issue, and cross check content of the “etc/host” files in both Windows and Linux. 

Photo of Samuel Agwah

Samuel Agwah

cannot assign requested address windows

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

3 Answers 3

In case anyone runs into the same problem:

did the trick.

  • is it the same when you are connecting to a remote cluster? –  nEO Jan 2, 2020 at 7:41
  • 1 If you're using the builder, using SparkSession.builder.config('spark.driver.host', '127.0.0.1').getOrCreate() also works! –  Doug May 8, 2020 at 1:54

Not sure why the Bishu's response got a negative vote -- this it right answer for Windows users....It worked for me.

Windows Steps

For folks not aware how to designate system variables in Windows, here's the steps:

  • In an open folder (with left-hand folder nav window open) locate " This PC "
  • Right-click on "This PC" and choose " Properties "
  • Within left nav menu, choose " Advanced system settings "
  • Within this new menu, choose the bottom item " Environment Variables... "
  • Within the 2nd window (on the bottom), choose " New... "
  • For " Variable " prompt, type: SPARK_LOCAL_IP
  • For " Value " prompt, type: localhost
  • Note: it might be 127.0.0.1 or some other value on your system-- you should really check what's listed in this file here C:\Windows\System32\Drivers\etc\hosts
  • Once done, leave this whole area
  • Note: only NEW cmd prompts will load/recognize the new system variable -- please load another cmd prompt

-- Hopes that helps

Doug E Fresh's user avatar

  • For all user, your variable can be set by command line too: setx /m SPARK_LOCAL_IP localhost or for current user only, remove flag /m : setx SPARK_LOCAL_IP localhost –  Io-oI Apr 19, 2020 at 21:56

Create an environment variable as below

Variable -> SPARK_LOCAL_IP Value -> localhost

Bishu's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged python hadoop ..

  • The Overflow Blog
  • Reshaping the future of API platforms
  • Between hyper-focus and burnout: Developing with ADHD
  • Featured on Meta
  • Our Partnership with OpenAI
  • Imgur image URL migration: Coming soon to a Stack Exchange site near you!

Hot Network Questions

  • Is it bad to branch off data traces into two separate connectors?
  • Can I use "Britons" in data reports?
  • What is the difference between a model and an interpretation in logic?
  • What is the least number of circles with radius r is required to cover a circumference of a circle with radius R?
  • How can I work with a senior researcher who is less knowledgeable than myself?
  • Is a tactical nuclear strike against a military target different on a legal standpoint than a tactical nuclear strike against a civilian target?
  • Retopology with vertex paint
  • Shortest battleship game, to find number of battleships
  • Why don't we consider the initial phase in the superposition to form a stationary wave?
  • What wires needed for my basement circuits?
  • Hypothesis testing: Difference of means (pre-treatment)
  • How does Russia exactly define Russian territory in its state policy?
  • Advice on designing an inconsistent magic system
  • Why does the EU find the foreign agent law in Georgia against their values?
  • Is there any explanation or discussion regarding the change in the Bard class from its AD&D1ed orignal implementation?
  • In OOP, what count as a "getter"
  • Is -is the feminine singular nominative endings of third-declension adjectives with three or two nominative singular forms?
  • A short fiction about an American poetess who supposedly foiled, thanks to posthumous poems, the Martian invasion described by H. G. Wells
  • Who was Nicolò Paganini that discovered the amicable pair 1184, 1210?
  • printf - store formatted string output in a variable
  • LED as a flyback for a 3V relay?
  • I keep blowing up irrigation solenoids
  • Windows War Strategy Game
  • What major advances in theoretical and computational chemistry have been made in recent decades?

cannot assign requested address windows

Troubleshooting

Unable to connect: Can’t assign requested address

Last updated: January 11, 2023

Note:  This article is for users with technical experience. For other users, please  contact the ExpressVPN Support Team for direct assistance .

Users who recently changed to ExpressVPN may see an error message in their diagnostics similar to this:

MANAGEMENT: Socket bind failed on local address [AF_INET]180.168.41.175:49314: Can't assign requested address

If you see this message, the problem may be that your host file is missing some important lines. To confirm:

  • Open  Terminal
  • In Terminal, type “ ping localhost “
  • You should see something like the below: 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.064 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.069 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.303 ms
  • To stop, hit  Control + C

If you see an IP address that is NOT 127.0.0.1, your host file is missing some important lines. To fix this:

  • Open  Terminal  via Spotlight Search (command + space, then type “terminal”)
  • In Terminal, enter  sudo nano /private/etc/hosts
  • Enter your admin password. You will not be able to see which characters you input so type carefully.
  • Your host file will be loaded onto Terminal. Use the arrow keys to navigate between lines in the file.
  • Enter the below three lines if you do not see them in your host file: 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost

flush dns

  • Press  Control + X to quit editing the host file
  • You will need to flush the existing DNS cache for the entries to be effective. See instructions on flushing the DNS cache .
  • Open ExpressVPN and connect to a server location

Need help? Contact the ExpressVPN Support Team via Live Chat for immediate assistance .

Back to top

Was this article helpful?

We're sorry to hear that. Let us know how we can improve.

What device do you need help with?

Examples: Android, Windows, Linksys router

A member of our Support Team will follow up on your issue.

Choose language

cannot assign requested address windows

IMAGES

  1. Network error Cannot assign requested address

    cannot assign requested address windows

  2. Understanding The 'Cannot Assign Requested Address' Error: Causes And

    cannot assign requested address windows

  3. Cannot Assign Requested Address: A Step-By-Step Guide

    cannot assign requested address windows

  4. Windows : Docker for Windows: cannot assign requested address

    cannot assign requested address windows

  5. Cannot Assign Requested Address: A Step-By-Step Guide

    cannot assign requested address windows

  6. HOW TO FIX ERROR 99 CANNOT ASSIGN REQUESTED ADDRESS NGINX

    cannot assign requested address windows

VIDEO

  1. Fix Access Denied When Modifying HOSTS File In Windows 11/10

  2. How to assign static IP address to network adapter in Windows 10/11 @webmasterbitmesra5096

  3. Computer में Disk Drive letter Change करें? #shorts #windows11

  4. You Need to Activate Windows before you Personalize your PC Problem Solved

  5. 【7月最新真GPT4开源项目FreeGPT】本地docker一键安装ChatGPT,无需账号无需API无需token部署简单,docker报错解决GPT回复error99报错解决 #Freegpt报错

  6. Remote Device or Resource Won't Accept the Connection fix

COMMENTS

  1. Cannot assign requested address using ServerSocket.socketBind

    "Cannot assign requested address" means that (in your case) it's probable that "localhost" does not map to a valid ip. - Nir Levy. Sep 19, 2012 at 10:18 ... it listens to a port and bind a socket to an address and port. In Windows and Linux the hostname is resolved to IP address from /etc/hosts This host to IP address mapping file can be ...

  2. Docker for Windows: cannot assign requested address

    If you want to test a multi-node swarm on your machine, you need to set up a separate set of VMs: > docker-machine create -d hyperv --hyperv-virtual-switch "Better New Virtual Switch" master. > docker-machine create -d hyperv --hyperv-virtual-switch "Better New Virtual Switch" worker1. > docker-machine create -d hyperv --hyperv-virtual-switch ...

  3. iperf returning "bind failed: cannot assign requested address" in

    I am trying to set up iperf on an old HP server running Windows XP Professional to test multicast, but whenever I issue the command iperf -s -u -B <ip address>, it returns: bind failed: Cannot assign requested address

  4. bind: cannot assign requested address

    In many cases, binding to 0.0.0.0 is the best course of action unless you have a specific reason to bind only to a specific address. But I assume that what you're doing isn't working, because you're trying to bind to the instance's public IP address, which you'll find (via ifconfig) your IP stack isn't aware of.. AWS instances are only natively aware of their private IP address, which is what ...

  5. Windows Sockets Error Codes (Winsock2.h)

    The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer. This can also result from connect , sendto , WSAConnect , WSAJoinLeaf , or WSASendTo when the remote address or port is not valid for a remote computer (for example, address or port 0).

  6. Cannot assign requested address [SOLVED]

    Web Servers: . Nginx: When Nginx tries to bind to an IP address not present on the server, or if the port is already in use.; Apache: Similar to Nginx, trying to bind to an unavailable IP or a busy port.; Database Servers: . Redis: Occurs when Redis is configured to bind to a specific IP that isn't available.; MySQL: If MySQL is set up to listen on an IP not assigned to the server.

  7. ssh tunnel

    [email protected]'s password: bind: Cannot assign requested address (where 8.8.8.8 is really my server's IP and 'user' is my real username) I am logged into the remote side in this terminal-window. I can verify that the local port was unused prior to this command, and then used by an ssh process, after the command, via: netstat -lnp | grep 1080

  8. How I fixed Python OSError: [Errno 99] Cannot assign requested address

    Docker container [Errno 99] Cannot assign requested address. Note that for Docker containers, either you need to run them in network_mode: host to use the host's network systemd, or you need to bind to the container's IP address. You can not bind to the host's IP address from the contaienr unless using network_mode: host!

  9. Docker Containers and localhost: Cannot Assign Requested Address

    Look out for your use of 'localhost' when using Docker and Docker Compose

  10. Cannot swarm init: cannot assign requested address

    I am facing the same issue, my IP address is 192.168..223 and If I run the 'docker swarm init' then it provide me the ip address that is not the same to the machine ip, and when I used the command 'docker swarm init --listen-addr 192.168..223:2377 --advertise-addr 192.168..223:2377' it said: can't assign the requested address

  11. Could not connect to Redis at 127.0.0.1:6379: Cannot assign requested

    2. I tried connect to redis server but I can't. $ redis-cli. Could not connect to Redis at 127.0.0.1:6379: Cannot assign requested address. $ telnet localhost 6379. Trying 127.0.0.1... telnet: Unable to connect to remote host: Cannot assign requested address. But redis is running, redis log: 8088:signal-handler (1560512157) Received SIGTERM ...

  12. iperf multicast server cannot start

    I'm trying to set up a multicast server on Windows 10, and I downloaded iperf 2.0.9 64-bit directly from iperf.fr. When I attempt to start a multicast server I run the following command and get back the error: Command: iperf -s -u -B 224.0.0.5 -i 10 Output: bind failed: Cannot assign requested address

  13. WSL2 cannot connect to localhost when the service is running on Windows

    Please fill out the below information: Your Windows build number: (Type ver at a Windows Command Prompt) Microsoft Windows [Version 10..19041.264] What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screenshots if that helps demonstrate the problem.)

  14. Why isn't my ASP.NET Core app in Docker working?

    I walked through my debugging process to try to get to the root cause of the problem, and realised that I was binding to the loopback address. This meant the application was accessible from inside the Docker container, but not from outside it. To resolve the issue, I made sure to bind my ASP.NET Core app to any IP address, not just localhost ...

  15. windows Cannot assign requested address Error #122

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window.

  16. Cannot Assign Requested Address: Troubleshooting Minecraft Server

    Common causes of a "cannot assign requested address error" are incorrect mapping, busy IP address, DNS problems, and local ports which do not have binds. It can occur while using web and application servers such as WebLogic and Jetty. Typically, the port is in use, or the requested local address cannot be assigned.

  17. python

    java.net.BindException: Cannot assign requested address: bind: Service 'sparkDriver' failed after 16 retries (on a random free port)! Consider explicitly setting the appropriate binding address for the service 'sparkDriver' (for example spark.driver.bindAddress for SparkDriver) to the correct binding address.

  18. Unable to Connect: Can't Assign Requested Address

    To stop, hit Control + C. If you see an IP address that is NOT 127.0.0.1, your host file is missing some important lines. To fix this: Open Terminal via Spotlight Search (command + space, then type "terminal") In Terminal, enter sudo nano /private/etc/hosts. Enter your admin password.

  19. Cannot assign requested address (localhost:xxxx)

    Now, my problem is, the post request to API-2 always returns Cannot assign requested address (localhost:XXXX). If I try without docker, it works fine. Also, a separate request to each of the API works fine (using POSTMAN) This problem occurs only if the API deployed in the docker. I was using docker-compose to create the containers.