Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:192.168.2.101:3306 -R 3000:192.168.1.3:3000 disp@192.168.2.100 -p 80

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

share|improve this question
up vote 12 down vote accepted

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.

share|improve this answer

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

share|improve this answer
1  
This will look as: @reboot autossh -f -nNT -R 3269:host-providing:3269 firewalled-host & – nicoX Oct 7 '13 at 9:03
    
no need to add "&" at the end, -f already place the command in background – Pierre Maoui Apr 7 at 13:04

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.