How can i reestablish a Tunnel if my localhost goes down?

i have 2 machines, Remotehost and localhost, on my localhost im running autossh to keep the tunnel alive in case of network problems.

autossh -M 20000 -L 3300: -R 3000: [email protected] -p 80

but what if i need to reboot the localhost? how do i auto reconnect the tunnel then?

2 Answers 2


Put the command to establish the tunnel in some script which is executed on boot. You could use /etc/rc.local, you could write your own init script in /etc/init or /etc/init.d, or more elegantly, you could write a script in /etc/network/if-up.d. The last option executes the script after the network interface comes up.

  • Calling it on /etc/network/if-up.d will not make it be called again and again every time interface get down and up again?
    – TNT
    Jan 31, 2018 at 19:57

Another simple option is to add @reboot autossh ... & to /etc/cron.d/autossh

  • 2
    This will look as: @reboot autossh -f -nNT -R 3269:host-providing:3269 firewalled-host &
    – nicoX
    Oct 7, 2013 at 9:03
  • 2
    no need to add "&" at the end, -f already place the command in background Apr 7, 2016 at 13:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .