Operating System - HP-UX
1835960 Members
2748 Online
110088 Solutions
New Discussion

Re: -- How can I free a busy port ? --

 
SOLVED
Go to solution
OLIVA_1
Regular Advisor

-- How can I free a busy port ? --

Hello,

How can I free a busy port ?
I would like free the port 4200, how can I do ?

netstat -anf inet | grep 4200
tcp 0 0 57.7.6.213.52702 57.7.6.213.4200 ESTABLISHED
tcp 0 0 57.7.6.213.52654 57.7.6.213.4200 FIN_WAIT_2
tcp 0 0 57.7.6.213.51627 57.7.6.213.4200 FIN_WAIT_2
tcp 0 0 57.7.6.213.49433 57.7.6.213.4200 FIN_WAIT_2
tcp 0 0 57.7.6.213.4200 *.* LISTEN
tcp 0 0 57.7.6.213.4200 57.7.6.213.49433 CLOSE_WAIT
tcp 0 0 57.7.6.213.4200 57.7.6.213.51627 CLOSE_WAIT
tcp 0 0 57.7.6.213.4200 57.7.6.213.52654 CLOSE_WAIT
tcp 0 0 57.7.6.213.4200 57.7.6.213.52702 ESTABLISHED


Thanks,
4 REPLIES 4
Mark Grant
Honored Contributor

Re: -- How can I free a busy port ? --

Ideally, you'll find out which application is listening on that port and stop it. Other than that it's quite difficult achieve I think though not impossible with some smart C that is too smart for my C
Never preceed any demonstration with anything more predictive than "watch this"
Zigor Buruaga
Esteemed Contributor

Re: -- How can I free a busy port ? --

Hi,

Try stopping the program that use that port. If you don't know which is the program you can use "lsof" to find it.

HTH
Kind regards,
Zigor
Massimo Bianchi
Honored Contributor

Re: -- How can I free a busy port ? --

kill a socket

The unorthodox method of using tcp_discon or tcp_discon_by_addr allows terminating of connections in the connections table without the need for a reboot. However, my advice is to use it only as a last resort.

To use the ndd -set /dev/tcp tcp_discon, you need the pointer to the TCP instance data. You can retrieve this via the ndd command tcp_status.

So, the scenario to find the TCP instance data and then use tcp_discon to remove the instance is as follows:

# ndd -get /dev/tcp tcp_status
TCP dest snxt suna swnd cwnd rnxt rack rwnd rto mss [lport,fport] state

0183b8b4 015.043.233.086 533cb8ce 533cb8ce 00008000 00003000 533bc583 533bc583 00000000 02812 04096 [c00a,cea9] TCP_CLOSE_WAIT

So, if you wanted to remove this connection:
# ndd -set /dev/tcp tcp_discon 0x0183b8b4

If you want to use the tcp_discon_by_addr, you use a 24 byte string that contains the hex representation of the quadruple.

For example, if the connection that I want to delete is:

Local IP: 192.1.2.3 (0xc0010203)
Local Port: 1024 (0x0400)
Remote IP : 192.4.5.6 (0xc0040506)
Remote Port: 2049 (0x0801)

The "hex" string you pass to tcp_discon_by_addr is:

# ndd -set /dev/tcp tcp_discon_by_addr "c00102030400c00405060801"

NOTE: the preceding 0x that typically indicates a Hex number is NOT part of the string passed.

Hope this helps. Regards.
T G Manikandan
Honored Contributor
Solution

Re: -- How can I free a busy port ? --

get lsof and then do a

#lsof -i tcp:4200

check for the application processes which use it and then you can stop them