linux - Warning: remote port forwarding failed for listen port 'xxxx'

06
2014-04
  • eric f

    How do I find the process that is listening on port 'xxxx' and kill it?

    I have RemoteForward 2022 remote.host:22 in my .ssh/config file.

    Whenever I ssh into a remote server: ssh staging-environment I am getting this error: Warning: remote port forwarding failed for listen port 2022

    I need this port open for port forwarding.

    How do I find the process that is listening on port 2022 and kill it?

    UPDATE:

    Output of netstat -tulpn

    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
    tcp        0      0 0.0.0.0:81                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:83                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:84                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:85                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:86                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 127.0.0.1:2022              0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 127.0.0.1:2023              0.0.0.0:*                   LISTEN      -
    
  • Answers
  • Matthew Williams

    You can use a couple methods to do this. netstat is a command line tool which should do what you want. A command line example would be something like:

    # netstat -tulpn

    This will lest ports on your system and which application is listening to it.

    Hope this helps

  • MariusMatutiae

    The correct command to see who is using port 2022 is

      sudo ss -ntp
    

    First, you should not use nestat, which is by now obsolete (if you are on Linux, as I believe you are, but if you are on Unix just forget this); second, you should run the command as sudo, otherwise you will not have the authority to display the processes using the port; third, you should definitely not use the flag u, because this means looking at UDP ports, while you are getting an error on ssh, which is most definitely using TCP, not UDP.

  • eric f

    The way I am currently getting around this error is to log into my server and ps -ef | grep ssh and kill all of the sessions spawned by my user.

  • Sayajin

    Just a quick one-liner will do it

    for pid in `netstat -tunpl | awk '{print $4, $7}' | grep ':2022' | awk '{print $2}' | cut -d '/' -f1`; do kill -9 $pid; done
    

  • Related Question

    Failed to open my port for upload purpose \ UTorrent
  • EyalEyal

    when doing the download\upload test in UTorrent program it claims my port is not open (Default 17690).

    After I plugged my machine directly to the modem (suspect of port forwarding not working), after removing the antivirus I have, and after adding to my firewall inbounds rule regarding to that port, I still fail on the test.

    I tried different port (49152). when doing in CMD the command netstat -a -n I get for this port two lines:

    TCP 0.0.0.0:49152 0.0.0.0 Listening

    UDP [::]:49152 :

    Can you suggest what should be my next examination tests? is there a good application that for a given port can detect which component blocking it?


  • Related Answers
  • uSlackr

    Torrent may be using upnp to tell the router to open the port. Is your router set up to allow this? You may have to enable upnp on the router or forward the port manually