[Solved] nc: bind failed: Address already in use (2023)

networking tcp netcat


Solution 1


When you're attempting to use nc in this manner it's continuing to keep the TCP port open, waiting for the destination to acknowledge the receiving of the done request. This is highlighted in the TCP article on Wikipedia.


(either server or client) represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request. [According to RFC 793 a connection can stay in TIME-WAIT for a maximum of four minutes known as a MSL (maximum segment lifetime).]

You can see the effects of this when I use nc similarly:

$ nc -p 8140 -v -n 80

Looking at the state of port 8140:

$ netstat -anpt | grep 8140tcp 0 0 TIME_WAIT -

In fact on most Linux systems this TIME_WAIT is set to 60 seconds.

$ cat /proc/sys/net/ipv4/tcp_fin_timeout60

If you want to see the effect yourself you can use this snippet to watch when the port becomes released.

$ date; nc -p 8140 -v -n 80 -w 1; date; \ while netstat -anpt | grep 8140; do date; sleep 10; done; dateTue Mar 25 09:46:59 EDT 2014Connection to 80 port [tcp/*] succeeded!Tue Mar 25 09:47:00 EDT 2014tcp 0 0 TIME_WAIT -Tue Mar 25 09:47:00 EDT 2014tcp 0 0 TIME_WAIT -Tue Mar 25 09:47:10 EDT 2014tcp 0 0 TIME_WAIT -Tue Mar 25 09:47:20 EDT 2014tcp 0 0 TIME_WAIT -Tue Mar 25 09:47:30 EDT 2014tcp 0 0 TIME_WAIT -Tue Mar 25 09:47:40 EDT 2014tcp 0 0 TIME_WAIT -Tue Mar 25 09:47:50 EDT 2014Tue Mar 25 09:48:00 EDT 2014$

Method #1 - using nc

The releasing of the port 8140 takes some time to occur. You'll either need to wait until it's been fully released (putting some sleeps in between would be 1 easy way) or by using a different port.

If you just want to see if the port @ host is open or not you could just drop the -p 8140.

$ nc -zv -n 10.X.X.9 9090-9093


$ nc -zv -n 2024-50000 |& grep -v refuConnection to 5672 port [tcp/*] succeeded!Connection to 35766 port [tcp/*] succeeded!

NOTE: You might be tempted to try adding the -w option to nc, which instructs it to only wait a certain period of time. By default nc will wait forever. So your command would be something like this:

$ nc -p 8140 -zv -n 10.X.X.9 9090 -w 1

However in my testing on a CentOS 5.9 system using 1.84 it still continued to keep the port in use afterwards, so the best you'd be able to do is use -w 60 since that's the shortest amount of time until TIME_WAIT takes effect.

Method #2 - using nmap

If you want to use a more appropriate app for scanning a set of ports then I'd suggest using nmap instead.

$ sudo nmap -sS --source-port 8140 -p 9090-9093 10.X.X.9


$ sudo nmap -sS --source-port 8140 -p 80-85 homerStarting Nmap 6.40 ( http://nmap.org ) at 2014-03-24 21:22 EDTNmap scan report for homer ( is up (0.0059s latency).PORT STATE SERVICE80/tcp open http81/tcp closed hosts2-ns82/tcp closed xfer83/tcp closed mit-ml-dev84/tcp closed ctf85/tcp closed mit-ml-devMAC Address: 00:18:51:43:84:87 (SWsoft)Nmap done: 1 IP address (1 host up) scanned in 11.36 seconds

Here I've setup a filter using iptraf to prove the traffic is going out to these ports using the source port of 8140.

NOTE: Pay special attention to #1 in the diagram, that shows the source port 8140, while #2 shows a couple of my destination ports that I selected, mainly 80 & 83.

[Solved] nc: bind failed: Address already in use (1)


Solution 2

I guess it might as well be an answer so it is at least readable:

i=0 ; until { nc -p 8140 -av -n 10.X.X.9 909${i} && [ $((i=i+1)) -gt 4 ]} 2>&- do sleep 1 done

Truth is, @slm's got a point about nmap - for handling your network and pen-testing it's an indispensable tool and it's definitely worth your while to get familiar with it. But for testing connectivity between only two machines in a 5:1 port config, it might be a little much. Then again, maybe this is a perfect opportunity to learn to use it.

Anyway, if you haven't got it at your disposal, netcat is extremely flexible. And, perhaps more importantly, nc doesn't require su root to do 0 i/o ops as does nmap.

In the above answer I just use $i to substitute the last digit of your target port with 0 for your first round and $i's incremented value thereafter. Because, as I believe, nc should return you a true so long as it can bind your local port, the variable $i will only increment if 8140 is open and nc can use it to dial out.

$i is incremented in a test to ensure you don't go beyond the 9094 port range you've specified, at which time it will finally return true thereby satisfying until and terminating the loop.

Speaking of which, until you can bind the local 8140 -port your loop will sleep 1 second (as @slm recommends) before trying again.

I just drop stderr with 2>&- so you don't have to look at couldn't bind... messages spamming your terminal. As written though, this may never be necessary, as sleep is called each time $i is incremented as well - excepting the last when the loop breaks anyway - so the 1 second pause between iterations is maybe enough to drop the bound local port and open it again for use in the next iteration.

If I've somehow mistaken the nc return value and it returns false even if it can secure 8140 locally but the target port is closed, that is easily handled with a little more specific use of $? - just let me know.



Related videos on Youtube

[Solved] nc: bind failed: Address already in use (2)

03 : 18

(Video) Unix & Linux: nc: bind failed: Address already in use (2 Solutions!!)

[Solved] nc: bind failed: Address already in use (3)

03 : 40

java.net.BindException: Address already in use, JVM already in use,



[Solved] nc: bind failed: Address already in use (4)

06 : 25

Fix "java.net.BindException: Address already in use" Error inside Anypoint Studio/Eclipse

Jason Estevan


[Solved] nc: bind failed: Address already in use (5)

07 : 52

(Video) Exploit failed [bad-config] Rex BindFailed The address is already in use or unavailable

Fix "java.net.BindException: Address already in use" | bind exception in Java Socket Programming



[Solved] nc: bind failed: Address already in use (6)

03 : 24

Address already in use bind port Errno EADDRINUSE | How to fix it

Dota Smart Stats


[Solved] nc: bind failed: Address already in use (7)

Author by


Updated on September 18, 2022


  • [Solved] nc: bind failed: Address already in use (8)

    saurav 3 months

    I am trying to execute nc command from a script , my script is executing nc command on different ports of Destination using the same source port.


    nc -p 8140 -z -v -n 10.X.X.9 9090nc -p 8140 -z -v -n 10.X.X.9 9091nc -p 8140 -z -v -n 10.X.X.9 9092nc -p 8140 -z -v -n 10.X.X.9 9093and so on ...

    After the 1st nc execution , for the remaining of all the lines I am getting below mentioned error message.

    nc: bind failed: Address already in usenc: bind failed: Address already in usenc: bind failed: Address already in use

    Is there any way of avoiding this situation?

  • [Solved] nc: bind failed: Address already in use (9)

    (Video) netcat udp address already in use

    saurav over 8 years

    Actually I have to do the outbound testing of ports on the source to the destination.In my case source port is 8140 , so i have to test that with 8140 whether it is able to connect or not. Is there any other way in which outbound of source port and inbound of the destination port can be tested ?

  • [Solved] nc: bind failed: Address already in use (10)

    slm over 8 years

    Use nmap instead would be my advice. nc isn't really up to what you're doing IMO.

  • [Solved] nc: bind failed: Address already in use (11)

    mikeserv over 8 years

    @slm nc could be up to what he wants, you've just gotta know how to tell it what to do.

  • [Solved] nc: bind failed: Address already in use (12)

    saurav over 8 years

    Thanks slm for such a wonderful explanation , actually in my case as you mentioned correctly TIME_WAIT value is 60 , so for me right now 1st solution is not feasible because i have around 100+ source and destination ports , that means (100*100) mins wait , it is definitely not going to work in my case. Is there anyway to override TIME_WAIT value ? otherwise I have to go with the nmap solution.

  • [Solved] nc: bind failed: Address already in use (13)

    slm over 8 years

    Yes you can change the TIME_WAIT echo 2 > /proc/sys/net/ipv4/tcp_fin_timeout, would set it to 2 seconds. Use caution w/ this method though since you're altering the timeout for the entire box.

  • [Solved] nc: bind failed: Address already in use (14)

    saurav over 8 years

    Thanks mike for your answer, actually in my case i have around 100+ source and destination ports , that means (100*100) mins wait , it is definitely not going to work in my case. As I have checked the TIME_WAIT value , it is 60 secs , so it will wait for at least 60 secs before releasing the port.

  • [Solved] nc: bind failed: Address already in use (15)

    saurav over 8 years

    yeah correct , I have to just reset it only for the time when my script is executing later on i will reset it to the original value. - thanks

  • [Solved] nc: bind failed: Address already in use (16)

    mikeserv over 8 years

    (Video) Unix & Linux: Failed to bind to '': Address already in use

    Yeah, that wont work as is. Youll need to do some & backgrounding to do anything like this.

  • [Solved] nc: bind failed: Address already in use (17)

    mikeserv over 8 years

    @tech-idiot you should bind nc to the port you want to dial out with as a proxy service with -l , then direct requests to localhost ports to be proxied out through the one proxy process. Ill update my answer a little later.

  • [Solved] nc: bind failed: Address already in use (18)

    psusi about 8 years

    Actually I believe this is a bug in linux. While it is true that you can not reuse the same src/dst touple while the previous connection is in TIME_WAIT, by changing the destination port you have selected a different, and therefore non conflicting touple.


Why Is PNG file with Drop Shadow in Flutter Web App Grainy?

How to troubleshoot crashes detected by Google Play Store for Flutter app

Cupertino DateTime picker interfering with scroll behaviour

Why does awk -F work for most letters, but not for the letter "t"?

Flutter change focus color and icon color but not works

How to print and connect to printer using flutter desktop via usb?

Critical issues have been reported with the following SDK versions: com.google.android.gms:play-services-safetynet:17.0.0

Flutter Dart - get localized country name from country code

navigatorState is null when using pushNamed Navigation onGenerateRoutes of GetMaterialPage

Android Sdk manager not found- Flutter doctor error

Flutter Laravel Push Notification without using any third party like(firebase,onesignal..etc)

How to change the color of ElevatedButton when entering text in TextField

(Video) Unix & Linux: httpd error: Address already in use: AH00072 (5 Solutions!!)


What is failed binding address already in use? ›

The Error “address already in use” occurred because some process was already running on the same port. So we can resolve the issue just by killing the process. To stop the process, we need the process ID (PID), which we can fetch using the lsof command.

How do I resolve a port already in use Linux? ›

How to check if port is in use in
  1. Open a terminal application i.e. shell prompt.
  2. Run any one of the following command on Linux to see open ports: $ sudo lsof -i -P -n | grep LISTEN. $ sudo netstat -tulpn | grep LISTEN. $ sudo ss -tulpn | grep LISTEN. ...
  3. For the latest version of Linux use the ss command. For example, ss -tulw.
Mar 29, 2023

What is bind address already in use 98? ›

If bind() causes error 98 (EADDRINUSE) or 10048 (WSAEADDRINUSE), it means you are trying to bind to a local port that is already in use. This is usually caused by one of three reasons: Another program is already using that port. Your program is already running and you've attempted to start it a second time.

How do I fix port binding error? ›

The most common reason for Minecraft failed to bind to port error comes from the incorrect IP configuration. If you have entered something besides the “server-ip=” in the server. properties file, you will encounter the “failed to bind to port Minecraft server” error. You can fix the issue by changing the server.

Why is my server failing to bind to port? ›

The failed to bind to Port Minecraft server error occurs when a server attempts to use a service port (i.e 25565) that is already in use by another server. Since the majority of Minecraft hosting is Shared Hosting with shared IPs, the only way to make each server accessible is by giving it a unique port.

How do you stop the port which is already in use? ›

How to kill the process currently using a port on localhost in...
  1. Run command-line as an Administrator. Then run the below mention command. netstat -ano | findstr : port number. ...
  2. Then you execute this command after identify the PID. taskkill /PID typeyourPIDhere /F.

How do I fix port 8080 already in use? ›

  1. On MS Windows, select Start > All Programs > Accessories > System Tools >Resource Monitor.
  2. Expand the Network Tab.
  3. Move to the section for Listening Ports.
  4. Look in the Port column and scroll to find entry for port 8080.
  5. Select the given process and delete/kill the process.

How do I force unbind a port in Linux? ›

The only way to forcefully close a listening port is to kill the process that is listening on it. Use lsof , netstat , fuser – as root – to find out the process ID. Once the process exits (by itself or by being killed), the kernel will automatically clean up all sockets it had open.

How to install bind on Linux? ›

How to Install and Configure a Private BIND DNS Server on Ubuntu...
  1. Prerequisites.
  2. Install the latest updates.
  3. Install BIND 9 on the DNS server.
  4. Edit the named.conf.options file.
  5. Edit the named.conf.local file.
  6. Create a directory for your zone files.
  7. Create the forward zone file.
  8. Create the reverse zone file.
Mar 20, 2023

What does already in use bind 2 for 127.0 0.1 port 3000? ›

If the error message you're getting is Address already in use – bind(2) for “127.0. 0.1” port 3000 (Errno::EADDRINUSE) , the fix is pretty easy. It means you still have a server running, though it may be hanging or stuck in a loop.

How do I bind my IP address? ›

Step 1 Open the web browser and type the IP address of the router (default is 192.168. 0.1) into the address bar and then Press Enter. Step 2 Type the username and password in the login page, the default username and password both are admin. Step 3 Click on Firewall->Anti ARP Spoofing->IP-MAC Binding on the left side.

What port does bind use? ›

This configuration sets the BIND service to run on default UDP port 53 on the server's localhost and public IP address (172.16. 1.10). At the same time, it allows queries from any host to the BIND DNS server using the Cloudflare DNS 1.1.

Is port binding the same as port forwarding? ›

It absolutely is not the same thing. The code you supplied binds the port on the local machine. This action is independent of forwarding all traffic on a port to a specific client. You can bind a port on every client on your network but you can only forward the traffic on that port to a single client on the network.

What is a binding error? ›

The binding error occurs because the columns the view is expecting to find in its SELECT statement no longer exist.

Can you bind the same port twice? ›

Yes. Multiple listening TCP sockets, all bound to the same port, can co-exist, provided they are all bound to different local IP addresses. Clients can connect to whichever one they need to.

How do I reset my server port? ›

  1. Open the Integration Server Administrator if it is not already open.
  2. Go to Security > Ports.
  3. Click Reset to Default Access Settings.

How to unblock ports? ›

Opening Ports in Windows Firewall
  1. From the Start menu, click Control Panel, click System and Security, and then click Windows Firewall. ...
  2. Click Advanced Settings.
  3. Click Inbound Rules.
  4. Click New Rule in the Actions window.
  5. Click Rule Type of Port.
  6. Click Next.
  7. On the Protocol and Ports page click TCP.
Mar 21, 2023

Why is my port already in use? ›

If you get this error: 'Port 4200 is already in use. Use '–port' to specify a different port', you might have left your Angular development environment without closing the node. js webserver's port. Here's how you can close it without having to reboot your computer or change your application's port.

How do I know if a port is already in use? ›

In order to check which application is listening on a port, you can use the following command from the command line:
  1. For Microsoft Windows: netstat -ano | find "1234" | find "LISTEN" tasklist /fi "PID eq 1234"
  2. For Linux: netstat -anpe | grep "1234" | grep "LISTEN"
May 19, 2022

What does it mean when port is already in use? ›

So in general, If you get a “port 8080 was already in use” error, then it is certain that another application is already using that port. This is most likely due to bad configuration from your end, running the application multiple times, or not using proper startup and shutdown scripts.

How do I unblock port 8080? ›

Main steps to open ports:
  1. Locate your router's IP address.
  2. Head over to your router's settings.
  3. Enter your credentials (username and password).
  4. Look around for the Port Forwarding tab.
  5. Open your preferred port—for example, type 8080 to open port 8080.
  6. Save your settings.
Jan 14, 2021

What does port 8080 was already in use but it is not? ›

If you see the error "Port 8080 already in use" when starting the Tomcat server, it means that another process is already using port 8080 on your machine. To solve this problem, you can either stop the process that is using port 8080 or change the port number used by the Tomcat server.

How do I know if port 8080 is blocked? ›

Use the Windows netstat command to identify which applications are using port 8080:
  1. Hold down the Windows key and press the R key to open the Run dialog.
  2. Type “cmd” and click OK in the Run dialog.
  3. Verify the Command Prompt opens.
  4. Type “netstat -a -n -o | find "8080"". A list of processes using port 8080 are displayed.
7 days ago

How do I release a port in Linux? ›

The fuser command combined with the -k (kill) option will end all associated processes that are listening on a TCP or UDP port. Simply provide the port number and type (TCP or UDP) in the fuser command. You can use the lsof command to verify that processes are no longer running on the target port.

How do I unbind an IP address in Linux? ›

Add or remove data addresses.
  1. To add data addresses to the IPMP group, type the following command: # ifconfig ipmp-interface addif ip-address up.
  2. To remove an address from the IPMP group, type the following command: # ifconfig ipmp-interface removeif ip-address.

How do I unbind port forwarding? ›

  1. Launch a Web browser and typer "192.168. ...
  2. Click "Port Forwarding" under the Advanced section.
  3. Uncheck the "Enable" box next to each port forwarding rule you wish to disable.

What is bind address in Linux? ›

BIND is a nameserver service responsible for performing domain-name-to-IP conversion on Linux-based DNS servers. [root@servera ~] # yum install bind. The BIND package provides the named service. It reads the configuration from the /etc/named and /etc/named.

How to use bind command in Linux? ›

The bind command in Linux is a built-in command which comes with the Bash shell. This command is used to assign functions and macros to a key or a sequence of keys. Thus, this command allows us to create hotkeys instead of having to type in the entire command/function/macro name every time you need to use one.

Where is the bind config file? ›

The BIND nameserver named server uses the /etc/named. conf file for configuration. All zone files are placed in the /var/named/ directory.

Why is 127.0 0.1 refused to connect? ›

If DNS collects too many records or some of the records get corrupt, it may fail to function. Such an issue can result in localhost refusing to connect. The best way to ensure DNS is not preventing the localhost connection is to clear the DNS cache and delete all saved DNS lookup information.

What does bind 127.0 0.1 :: 1 mean? ›

If you bind a socket for receiving data to a specific address you can only receive data sent to this specific IP address. For example, if you bind to 127.0. 0.1 you will be able to receive data from your own system but not from some other system on the local network, because they cannot send data to your 127.0.

What is the difference between bind port and connect port? ›

bind() associates the socket with its local address [that's why server side binds, so that clients can use that address to connect to server.] connect() is used to connect to a remote [server] address, that's why is client side, connect [read as: connect to server] is used.

What does it mean to bind a router? ›

You can make the outbound traffic to a specified destination leave the router from a specified WAN port through Protocol Binding or Static Routing. Protocol Binding is used to define specific IP addresses or specific application service ports to go through a user-assigned WAN for external connections.

Why do we bind IP addresses? ›

MAC-binding prevents unauthorized access to your network, as only those with approved MAC addresses would be allowed entry. If you change your IP or MAC address, you will be unable to access the network. Measures such as these make your network more stable and secure.

How to bind IP address from DHCP? ›

  1. Enter system view.
  2. Enter DHCP address pool view. dhcp server ip-pool pool-name.
  3. Configure a static binding. static-bind ip-address ip-address [ mask-length | mask mask ] { client-identifier client-identifier | hardware-address hardware-address [ ethernet | token-ring ] } ...
  4. (Optional.)

What is a binding address? ›

The Address Binding refers to the mapping of computer instructions and data to physical memory locations. Both logical and physical addresses are used in computer memory. It assigns a physical memory region to a logical pointer by mapping a physical address to a logical address known as a virtual address.

What does it mean to bind an IP address? ›

The bind parameter specifies the IP address or name of the host to which the protocol handler is bound. bind=<name> Description. Set the value to the IP address or name of the host. If you specify an IP address, it can be in the IPv6 format; for example, 3ffe:307:8:0:260:97ff:fe40:efab.

What does it mean to bind address in socket? ›

When a socket has both an IP address and a port number it is said to be 'bound to a port', or 'bound to an address'. A bound socket can receive data because it has a complete address. The process of allocating a port number to a socket is called 'binding'.

What is error 10048 in function bind address already in use? ›

This error occurs when your OS cannot allocate new sockets. On Windows the default limitation is 5000 - 1024 open ports (5000 is the default max user port setting and the first 1024 ports are reserved). You can increase the default maximum socket value in the registry.

What does binding property mean? ›

noun:plural. properties that enable one molecule to bind to another.

Is your IP tied to your device? ›

The internet knows your IP address because it's assigned to your device and is required to browse the internet. Your IP address changes, though, every time you connect to a different Wi-Fi network or router.

What does it mean to bind a device to a network? ›

defined device binding as “a way of coupling two devices by explicitly or implicitly creating a software plus network connection between them.” [10]. Today, most common way of device binding is using wireless communication protocols such as Bluetooth, WiFi, NFC etc.

What does bind mean in networking? ›

BIND is an acronym for Berkeley Internet Name Domain. BIND is Domain Name System (DNS) software for computers or services connected to the internet. The system acts as a decentralised categoriser which associates names with various information.

How do you bind a socket to an address? ›

To bind a socket

Call the bind function, passing the created socket and sockaddr structure returned from the getaddrinfo function as parameters. Check for general errors. Once the bind function is called, the address information returned by the getaddrinfo function is no longer needed.

How do I unbind a socket to an address? ›

To "unbind the port", you'll want to Shutdown/Close the server socket. You should have a "server" socket that you made a call to . Bind(EndPoint) on, followed by a call to . Listen().
You can actually trim the method down to:
  1. Shutdown.
  2. Close.
  3. Remove from your list.
Jan 7, 2011

What does bind mean in DNS? ›

What is BIND? Berkeley Internet Name Domain (BIND) is the most popular Domain Name System (DNS) server in use today. It was developed in the 1980s at the University of Berkley and is currently in version 9. BIND is an open source system free to download and use, offered under the Mozilla Public License.

What is network error 10048? ›

In short, SQL server error 10048 occurs when the TCP port where SQL server must run is used by other processes.

What is error code 10048? ›

The return code 10048 is a Windows return codes that states: Only one usage of each socket address (protocol/network address/port) is normally permitted. The error ANR8208W states that the TCPport specified is already used by another application.

What does failed to bind only one usage of each socket address protocol network address port is normally permitted? ›

What does ""Only one usage of each socket address (protocol/network address/port) is normally permitted" mean? This error means all available ports on the machine are being exhausted. By default the OS only has around 4000 ports available that are not reserved by the system.


1. DevOps & SysAdmins: nginx - [emerg] bind() to failed (98: Address already in use)
(Roel Van de Paar)
2. bind failure, address in use: Unable to use a TCP port for both source and destination?
(Roel Van de Paar)
3. Android Chess 046: Fixing "Address already in use" caused by pressing LISTEN button twice
(Donald Sheng)
4. bfu untethered code exec + bind + usbmuxd + nc = fun
5. Unix & Linux: "bind: Address already in use" when creating bridge on Linux for Windows
(Roel Van de Paar)
6. java.net.BindException on app crashing and port already in use
(Roel Van de Paar)
Top Articles
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated: 27/09/2023

Views: 6214

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.