Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a game server running on my CentOS box that binds to port 28960, now when I restarted the game server it stated that it can't bind the port because its in use, but its obviously because the server was restarted, but the port was not closed? How do I check to see if the program is listening, and if its not, then how would I clear the port, so I can start the server back up on port 28960?

share|improve this question

2 Answers 2

I think you may be running into the 2*MSL problem. Here's how you tell:

$ netstat -na | grep 28960.*TIME_WAIT

If you get anything back from that, it means the kernel's network stack is waiting for twice the maximum segment lifetime (MSL) for stray packets to get around to making an appearance before allowing that port to be re-bound. The TIME_WAIT state is a good thing.

Servers that are intended to be restarted in normal operation disable TIME_WAIT handling by setting the SO_REUSEADDR socket option. If you look into the docs for your game server, it may be that there is an option that lets you enable this behavior.

If not, and you can't get the source to modify the game server, your only option is to wait for the TIME_WAIT states to expire, which typically takes between 30 and 120 seconds.

Here is a script I call showwait which is helpful with this sort of thing:

#!/bin/sh
while [ true ]
do
    netstat -na | grep WAIT
    sleep 1
done

You just run it and wait for it to stop putting out lines every second. Then you Ctrl-C it and move on with whatever you needed to do that required that there be no wait states.

This script isn't suitable for use on a busy server, where there are wait states going on all the time, but when you're just waiting for a server with nothing else going on to achieve quiescence, it's perfect.

share|improve this answer
    
Right. But this should not take too much time to clear up. –  vonbrand Jan 26 '13 at 2:20
1  
@vonbrand: As I said, typically 30-120 seconds. I don't see anything from our anonymous OP that tells us he actually waited that long. In one of the comments on your post he said it "never" clears up, but that's obviously bogus. –  Warren Young Jan 26 '13 at 2:26

You could try lsof(8) (check the manual page, it is quite extensive; but just piping its output to grep 28960 should give some idea what is going on). In any case, port 28960 is unassigned by IANA. so nothing should be using it.

share|improve this answer
    
Yeah, 28960 is the default port used for Call of Duty 4, the game server I was trying to start up, but when I first started it, it binded to 28960, then on restart, it never stopped being binded, causing the software to think its already binded. –  user31186 Jan 25 '13 at 22:33
    
cod4_lnxd 6610 root 24u IPv4 827763 0t0 UDP *:28960 Found it =] Now how would I find out how to close it if its not showing up on my tasks? –  user31186 Jan 25 '13 at 22:39
    
@user31186, when the process exits it releases the ports it is using. So there can't be any "leftover bindings". Very strange. –  vonbrand Jan 25 '13 at 22:45
    
@user31186, kill 6610 would get rid of that process which holds that port. kill -s KILL 6610 if it doesn't want to go. –  Stéphane Chazelas Jan 25 '13 at 22:46
    
@user31186, that line matches but isn't for the port you are checking. If that is the only match, the port is free. Does nmap(8) see something there? –  vonbrand Jan 25 '13 at 22:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.