LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 11-26-2013, 12:10 PM   #1
verlyn13
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 linuxquestions.org 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.

Thanks!
 
Old 11-26-2013, 01:43 PM   #2
baldur_1
Member
 
Registered: Sep 2010
Posts: 275

Rep: Reputation: 28
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
/dev/random
Member
 
Registered: Aug 2012
Location: Ontario, Canada
Distribution: Slackware 14.2, LFS-current, NetBSD 6.1.3, OpenIndiana
Posts: 319

Rep: Reputation: 112Reputation: 112
Code:
//<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
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:31 AM.

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