brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: testparm with a hostname and IP shows which Samba shares that client can reach

Shares
~/tips/tip-samba-testparm-host-access

testparm -s /path/to/smb.conf laptop 192.0.2.25

Checks smb.conf and reports whether one given client may use each share.

I’d rather find out that a Samba rule is wrong before somebody calls to say the share is gone. The hosts allow and hosts deny lines in smb.conf are short and easy to get subtly wrong. testparm can check them for a specific client without anyone connecting.

testparm -s /path/to/smb.conf laptop 192.0.2.25

The man page describes testparm as a check of an smb.conf for internal correctness. If you add a host name and a host IP after the file name, it also goes through the service entries and reports whether that host has access to each one. The -s option only skips the “press Enter” prompt, which makes it usable in scripts. On an error it exits with 1, otherwise 0.

Here is a small rule to try it on:

[global]
   hosts allow = 192.0.2.
   hosts deny = ALL

The trailing dot is the documented way to allow a whole network, and ALL in hosts deny denies everything that the allow list does not name. Where the two lists conflict, the allow list wins. Change the IP in the command to one outside that range and compare the report.

Two caveats from the documentation. First, a clean testparm run is not a promise that the shares will actually work, only that smbd can read the file. Second, the address 127.0.0.1 is always allowed unless a hosts deny line names it, so the server itself will not show you a problem. Access also still needs a valid user and password on top of the host rule.

Further reading: testparm man page, smb.conf: hosts allow

Going deeper: Guide: your Unraid cache is full and Docker stopped, how to find out why and fix it

More Shares tips smbclient -L server -U user All Shares tips (2) All topics

Link