2

New version

So, I'll make a list of the things that I have in order to be clearer.

  • PC on windows 10 running a Plex media server and Kitty
  • VPS by OVH running on Debian 9 stretch

what I want :

  • want to access my server from anywhere out of the local network

how :

  • by using the vps as a tunnel to my Plex server

Problem :

  • dynamic ip Double Nat from isp side 4G / LTE router with a subscription
  • no port forwarding possible

issue :

  • when ip change "daily" on the PC (windows 10) the connection to the vps through kitty would crash

manual solution to the issue :

  • find the PID of the process that hold the port open and kill it

what I need :

  • to make that automatically or have another solution to the issue

Pictures to help you understand

After ip change in the log of Kitty

Manual way of resolving the issue

Q&A

Pimp Juice IT : thanks ^^ anyhow the no-ip tool also seemed to me quite fitted. But since the isp has double NAT and that basically i would have to run one No-ip soft on their second "router" behind mine. Which is impossible you would agree ^^. Really like my issue is really simple, indeed but annoying because it seems like the way out of this is simple. But can't get the right way :/

ps : yeah don't worry the old version is a big draft of what i wanted it to be ^^ in the new one you have all taht you need to help me i guess :/ ^^

Old version

I have a VPS from OVH which I use to tunnel my media server on PLEX from my PC to the VPS. All good and working, except…

My IP is dynamic and double NAT-ed. My external IP changes and renews often, at least once a day. Therefore my connection to the VPS through Kitty (a fork of PuTTY) breaks. That I solved with automated reconnection after a connection abort. Anyhow when that is done the port tunneling that I specified in KiTTY would fail, why because the previous connection wasn’t properly closed.

For the server side it's Debian 9 Stretch.

I found the solution which is that I find the PID of the very connection and kill it manually. There is my issue, I would like to automate that with a script. Here I call for your help by hoping anybody could be giving a hand.

Ps: my skills in scripting are as low as it could seem so be as clear as possible thanks.


Answers to some comments

Scott – when my IP address changes it would crash the connection. Right then it would reconnect thanks to KiTTY. I would in the command line just type in netstat -lnp, it would show me all the connection alive. I would find the one linked with the specified port (in this case 32400) and the PID that's associated, then kill the very PID with kill. Last time the PID was 12007 for example.

Kamil Maciorowski – I tried this (referring to this answer to another question):

permanently by editing the /etc/sysctl.conf file, add:

net.ipv4.tcp_keepalive_time=300

and

If only you can reconfigure sshd on the server, this is in my opinion the most elegant way. Let the sshd_config contain lines like:

ClientAliveCountMax 3
ClientAliveInterval 15

but neither of those work for me when I simulated a crash of my connection it will reconnect and the port would still be occupied.

Also the solution under

Back to the client

would seem like working for me only if I would be able to make it fit to my situation.

"but neither of those work for me when I simulated a crash of my connection it will reconnect and the port would still be occupied" – Did you restart sshd? Did you attempt to reconnect right away? With these settings you need to wait up to one minute for the port becoming free. – Kamil Maciorowski

yes, I did restart the SSHD with the following command :

/etc/init.d/ssh restart

and to be safe because I don't know it that restart sshd

service sshd restart

the reconnection is automated and instant I'm now looking for a way to delay this process if you know how just tell me thanks so you know the :

net.ipv4.tcp_keepalive_time=300

I set to 10 sec rather than 300 is that still alright.

Also I didn't quite get your second comment about loading two sessions at once fixing it with the second one my goal is to just restart the actual session process which is automated just now need the port to be set free so I can re open it with the new bond.

Clarification: in my comment above there is a generic way to prevent locking oneself out of server. If you broke sshd_config severely enough, you wouldn't be able to ssh anew. That's why you should always test it with a new connection, while the old one still allows you to revert changes no matter what. Note in general it's possible to have a syntactically valid sshd_config and still not be able to connect; so restarting sshd without any error doesn't necessarily mean it's going to work. – Kamil Maciorowski

So in the end like what are my solutions for this process to be automated and the port to be freed after a shorter period of time and how to delay the reconnection in kitty with a script or something else ? again thanks man for you time I appreciate

"the reconnection is automated and instant I'm now looking for a way to delay this process" – you mean KiTTY tries to reconnect without any delay, right? In Linux on the client side your problem can easily be solved by autossh or looping ssh -o ExitOnForwardFailure=yes … (see this answer). I think ssh under Cygwin should support this option. If you insist on a server-side script, I guess it can be done; but the script must not kill the tunnel if it's not the old tunnel. I have no time now to provide such a cumbersome solution; maybe in 12 hours. – Kamil Maciorowski

Okay thanks I'll see you in 12h anyway until then I'll try all the other solution I'll let you know how it goes thanks again man.

0 Answers0