LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Can you limit a specific samba share to certain IPs? (https://www.linuxquestions.org/questions/linux-server-73/can-you-limit-a-specific-samba-share-to-certain-ips-4175496421/)

anon091 02-27-2014 08:32 AM

Can you limit a specific samba share to certain IPs?
 
I know in smb.conf you can limit all samba shares to certain IPs with "hosts allow", but is there a way to do it for only a specific share too?

michaelk 02-27-2014 08:47 AM

Yes, as far as I know hosts allow is valid on a per share basis.

szboardstretcher 02-27-2014 08:51 AM

Just depends on where you put that 'hosts allow'

if you put it under global, then it will only allow those hosts 'globally'

if you put it under a share config, then it will only restrict ip's to that share

anon091 02-27-2014 09:03 AM

Oh ok, so it's valid under both, but if you do it at the share level, you must do it for all then.

So say i have three shares, but I only do an allow hosts under two of them, does that mean the one without allow hosts is then wide open, or closed off to everyone due to the lack of allow hosts?

szboardstretcher 02-27-2014 09:09 AM

So, searching for an example, I actually found an explanation for what you want: https://bbs.archlinux.org/viewtopic.php?id=108500

And here is the gist of it (other things removed for brevity, this is not a working example)
Code:

#smb.conf file
[global]
    workgroup = WHATEVER
    security = share
    include = /etc/samba/smbshared.conf

#smbshared.conf file
[Shared]
    path = /home/Shared
    hosts allow = 192.168.1.86

[Music]
    path = /home/Music

Explanation: Globally, there is no hosts_allow specified. So the default behavior is to allow all hosts. At the share level, 'shared' only allows 1.86 to connect to it and nothing else, but 'music' on the other hand inheritcs the global settings, which allows any ip to connect to it.

anon091 02-27-2014 10:38 AM

awesome, thanks sz!

Now if I can just figure out how to limit a specific share so it only shows/allows a certain total disk space, I'd be all set. Trying to tweak some existing servers but really not sure what's possible and what isn't yet. Really appreciate the help on this hosts allow thing.

szboardstretcher 02-27-2014 10:46 AM

No problemo.

Simple answer: Put each share on its own partition. Size the partition accordingly.

Advanced reminder: Make it LVM, so you can easily expand your disk when you run out of space.

anon091 02-27-2014 11:01 AM

I was afraid that was going to be the only answer. Was hoping there was a way to do it via samba config, since this is an existing server I'm hoping I don't need to reload.

szboardstretcher 02-27-2014 11:06 AM

Well the only other way I know how is by using quotas. Now, Samba doesn't directly know about these quotas, instead it is configured and handled in the user space by quotad. Its involved, and possibly complicated based on your linux level. But here is the first guide i found:

http://www.linuxhomenetworking.com/w...s#.Uw9wA9xb11s

Im not sure how up to date that is, so you should certainly look up the documentation regarding quotas for your specific distro!

TLDR,.. you can enable quotas on a disk and set up each samba mount to use a specific user that has a disk quota.

anon091 02-27-2014 11:29 AM

That might be a clever way to do it, force the mount to use a user that has a quote. I'll have to dig into it, but that's a pretty clever idea. thanks again!


All times are GMT -5. The time now is 08:51 AM.