I have forward remote nfs port in local machine through ssh tunnel(forwarding 2 ports), using autossh for make persistent connection:

root@remote.machine:~#autossh -v -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 2049:localhost:2049 user@local.machine
root@remote.machine:~#autossh -v -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 2059:localhost:2059 user@local.machine

Now i have in local.machine remote nfs ports listen to local.machine:

root@local.machine:~# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0*               LISTEN      27882/sshd: tunnel
tcp        0      0*               LISTEN      27881/sshd: tunnel

Configure my remote nfs mountpoint with this configuration in /etc/fstab:

localhost:/var/pub      /mnt/remote.machine nfs     tcp,rsize=8192,wsize=8192,rw,bg,intr,noatime,nosuid,noauto,vers=3,port=2049,mountport=2059      0   0

And mount it in /mnt/remote.machine/:

root@local.machine:~# mount /mnt/remote.machine
root@local.machine:~# mount -lt nfs
localhost:/var/pub on /mnt/remote.machine/ type nfs (rw,nosuid,noatime,tcp,rsize=8192,wsize=8192,bg,intr,vers=3,port=2049,mountport=2059,addr=

Well now remote nfs filesystem is accessible as a local directory...


When in remote.machine nfs service is stopped and/or ssh tunnel is broken, how test this condition from local.machine??? I'm using this system for automatize(with crond) backups from local.machine to remote.machine

I thought of run simple test:
root@local.machine:~# [ -d /mnt/remote.machine/remote/backups ] && ./run-backups.sh

But when I run it, command freeze while remote.machine back online!! and automation fails!!

If anyone has a better idea, for example using rsync or other, propose please. The condition is that the backup must be execute from local.machine to remote.machine(which has a dynamic ip) for safety reasons and permissions problems.

Edit: Mounting with options: retrans=1,timeo=1,soft,fg,retry=1,tcp,vers=3 or: retrans=1,timeo=1,soft,bg,retry=1,tcp,vers=3 The problem persist and freeze any filesystem command(example: ls, test -d) and after 2min:50sec print "Input/output error"


You need to add the soft mount option, otherwise the NFS client retries requests forever.

It will still take timeo * retrans for the attempt to timeout, which by default is 3min.

  • hi @mgorven, im using hard beacause im read on NFS man thits note: "NB: A so-called soft timeout can cause silent data corruption in certain cases. As such, use the soft option only when client responsiveness is more important than data integrity." And Data Integry is very important in my case because it's a backup operation – stefcud Feb 7 '13 at 18:59
  • @StefanoCudini Then any operations on the mountpoint will hang until the server comes back. It's your choice ;-) – mgorven Feb 7 '13 at 19:02
  • Using this options: soft,timeo=50,fg,retry=1,tcp,... freeze anyway, and after 2,5min print io error message, but remain freeze, and command, im try ls command but dont return error value! – stefcud Feb 7 '13 at 23:36

You can check before the backup process if the mountpoint is visible like

timeout 10 ls /mountpoint >& /dev/null && /backup/script

like this it won't hang it the mountpoint is stale.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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