Samba provides an easy (well.. almost) way of sharing files and folders between Linux and Windows. In certain situations, it may be required that a certain system allows both write and read permissions to some folders. Now imagine a situation where the systems are in a large subnet: an unrestricted write access gives anyone on the subnet free access to your data (maybe sensitive too). Can something be done so that only certain IPs / hosts in the subnet get access to your system?
Well, it turns out, Samba developers have given it a good thought. First of all, edit /etc/hosts and add aliases in the following format:
Say you added 3 aliases for 3 different hosts (alias1, alias2, alias3). This step ensures you dont have to remember the actual IP of the hosts, and those can be referred to by their alias names. Now, edit /etc/samba/smb.conf, and add the following to the [global] section:
- hostname lookups = yes
- hosts allow = alias1 alias2 alias3
And its done.. Restart samba server for the changes to take effect:
- sudo systemctl restart smb.service
- sudo systemctl nmb.service
Now only the aliased IPs will get access to your samba share, while the rest of the subnet will be blocked out!