Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-26-2013, 12:10 PM   #1
LQ Newbie
Registered: Nov 2013
Location: Montana, USA
Distribution: Manjaro
Posts: 1

Rep: Reputation: Disabled
How to automatic CIFS mount only on connection to home network

Hi all,

I am wondering if it is possible to have my system automatically mount a network share as CIFS when connected to my personal network at home, but to not attempt to mount when I am connected to any other network. Is there an fstab option for this?

I realize this might be a tall order, but what other types of solutions do experienced users do to automate this process of mounting from NAS devices when home and away? Is it OK to have to have the CIFS mount in fstab even though it will give an error every time the network share is not available?

This is my first post on and hope I didn't miss an easy solution to this somewhere in my searching. Everyone seems to just add the mount to their fstab without discussion of the consequences of it not being available sometimes.

Old 11-26-2013, 01:43 PM   #2
Registered: Sep 2010
Posts: 214

Rep: Reputation: 20
well, first of all i am not 100% but pretty sure that /etc/fstab is only run on boot but i honestly can't fully remember since it has been so long since i messed around with that. so if that is true and it doesnt, then you only need to run mount -a if it is designated correctly in /etc/fstab. mount -a will run the stuff in /etc/fstab.

if that is not correct then there are two possible options for you. you can either write a custom script that will auto mount for you. a reference would be here...

ubuntu auto mount

the os wouldnt matter which type, the process would be the same. otherwise i believe there is a program out there called autofs. check into one of those and go from there.
Old 11-26-2013, 02:01 PM   #3
Registered: Aug 2012
Location: Ontario, Canada
Distribution: Slackware 14.2, LFS-current, NetBSD 6.1.3, OpenIndiana
Posts: 309

Rep: Reputation: 104Reputation: 104
//<server>/<share> <mount point> cifs rw,_netdev,user=<username>,password=<password>,uid=<uid>,gid=<gid> 0 0

CIFS doesn't know about the _netdev option and will throw a warning about it, but you should leave it in.
This option ensures that the drives won't get mounted if you have no network or if you are on the wrong network.
Old 11-26-2013, 03:18 PM   #4
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,258

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
i have this in my /etc/rc.local:
if [ "`iwconfig | grep hyper`" ]
 /usr/bin/sshfs schneidz@hyper:/media/win/stuff /home/schneidz/hyper
its not elegant but it gets the job done.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setup automatic share network in my home linuxPCplus Linux - Networking 1 10-11-2012 01:18 AM
manual mount cifs works but srcipt mount cifs has mount error (13): Permission denied CADIT Linux - Newbie 6 11-20-2009 02:48 PM
Samba/Cifs Home Directory Mount Cottsay Linux - Software 1 06-07-2007 10:05 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration