SMB/CIFS: smbclient, mount.cifs, rpcclient, smbget, smbtree, net (Samba), smbutil, mount_smbfs (4/5)
Part 4 covers smbget's logging/config options, smbtree (a tree of workgroups, servers and shares), nmblookup (NetBIOS name to IP over UDP 137) and Samba's net admin tool: targets, authentication, time, domain join and users/groups. These are the tools for discovering and administering SMB servers from Linux.
158.1 Why is it used?
- smbget: download over SMB; -d/-l/--configfile help debug it.
- smbtree: see which workgroups, servers and shares exist on the LAN.
- nmblookup: resolve a NetBIOS name to an IP, list a host's names, find the master browser (Windows equivalent: nbtstat).
- net (Samba): remote admin of SMB servers via rpc (MS-RPC), ads (Active Directory) and rap (old SMB1).
- Packages: samba-client + samba-common-tools on Linux, brew samba on macOS.
158.2 How NetBIOS name lookup works
- Lab: client 192.168.178.20, Samba server FILESRV (smbd + nmbd) on 192.168.178.10.
- nmblookup NAME broadcasts a name query on UDP 137; only the owner answers with a unicast positive response.
- nmblookup -A IP asks one IP directly for its node status: all its registered names.
- Name types: <00> workstation, <20> file server, <1d> local master browser, <1b> domain master browser.
- Step 1
1.Client 192.168.178.20 broadcasts: name query FILESRV<00> on UDP 137
- Step 2
2.Switch floods it to the whole 192.168.178.0/24 subnet
- Step 3
3.Only FILESRV replies (unicast): FILESRV<00> = 192.168.178.10
- Step 4
4.nmblookup -A 192.168.178.10: node status asked directly (no broadcast)
- Step 5
5.Reply: FILESRV<00><03><20>, LAB<00><1d><1e>
- Step 6
6.LAB<1d> = this box is the local master browser (smbtree uses it)
158.3 smbget: logging, config and help
- -d 0-10 debug level; level 3 shows config, interface and 'Server connect ok'.
- --configfile=FILE uses an alternate smb.conf (here workgroup OTHERWG, netbios name ALTCLIENT).
- -l DIR log folder: a missing folder gives a log file error; after mkdir, log.smbget is created.
- -? help, --usage, -V version (4.19.9), --debug-stdout, --option='a = b'.
smbget -d 3 -o n3.txt \ -U asha%LabPass158 \ smb://FILESRV/docs/notes.txtsmbget --configfile=/lab/alt.conf -d 1 \ -U asha%LabPass158 \ smb://FILESRV/public/readme.txtmkdir -p /tmp/slogssmbget -l /tmp/slogs -d 2 -q -o r3.txt \ -U asha%LabPass158 \ smb://FILESRV/public/readme.txt$ cat /lab/alt.conf[global] workgroup = OTHERWG netbios name = ALTCLIENT$ smbget --configfile=/lab/alt.conf -d 1 -U asha%LabPass158 smb://FILESRV/public/readme.txtUsing netbios name ALTCLIENT.Using workgroup OTHERWG.Using domain: OTHERWG, user: ashaDownloaded 23b in 0 seconds158.4 smbtree
- Browsing runs on old SMB1; the modern client does not use SMB1 by default, so plain smbtree -U printed nothing.
- smbtree -N crashed in this version (exit 139).
- --option='client min protocol=NT1' showed the full tree.
- -D only workgroups, -S workgroups + servers; -b (broadcast) from old docs is removed (unknown option).
- -d 3 shows it broadcasts __MSBROWSE__<0x1> to find the master browser, then connects to it.
smbtree -U asha%LabPass158smbtree -U asha%LabPass158 \ --option='client min protocol=NT1'smbtree -D -U asha%LabPass158 \ --option='client min protocol=NT1'$ smbtree -U asha%LabPass158 --option='client min protocol=NT1'LAB \\FILESRV N158 lab file server \\FILESRV\docs Team documents \\FILESRV\public Public files \\FILESRV\IPC$ IPC Service (N158 lab file server)$ smbtree -d 3 ... | grep -E 'Using|name_resolve|positive|Connecting to'Using netbios name CLIENT158.Using workgroup LAB.name_resolve_bcast: Attempting broadcast lookup for name __MSBROWSE__<0x1>Got a positive name query response from 192.168.178.10 ( 192.168.178.10 )Connecting to 192.168.178.10 at port 445Connecting to 192.168.178.10 at port 139158.5 nmblookup: query options
- nmblookup NAME gives the IP; an unknown name gives 'name query failed'.
- -A IP node status; -S NAME resolves then shows the status.
- -M -- - finds __MSBROWSE__; -M LAB (or 'LAB#1d') returns the workgroup's master browser; '*' finds all names.
- -B ADDR sends to a broadcast address; -U HOST unicasts; --recursion for WINS.
- Careful: in this version -R is name-resolve order, not recursion. -r binds UDP 137 (root), -T adds reverse DNS, -f shows reply flags.
nmblookup FILESRVnmblookup -A 192.168.178.10nmblookup -M -- -nmblookup -M LABnmblookup -B 192.168.178.255 FILESRVnmblookup -U 192.168.178.10 --recursion FILESRVnmblookup -r FILESRVnmblookup -T FILESRVnmblookup -f FILESRV$ nmblookup -M -- -192.168.178.10 __MSBROWSE__<01>$ nmblookup -M LAB192.168.178.10 LAB<1d>$ nmblookup '*'192.168.178.10 *<00>$ nmblookup -T FILESRVn158-srv.n158-lan, 192.168.178.10 FILESRV<00>$ nmblookup -f FILESRVFlags: Response Authoritative Truncated Recursion_Desired Broadcast192.168.178.10 FILESRV<00>| Option | Meaning |
|---|---|
| NAME / 'NAME#20' | IP of a name (broadcast); with a type |
| -A IP | Node status of an IP |
| -S NAME | Resolve + node status |
| -M NAME | Master browser (type 1d) |
| -B ADDR / -U HOST | Send to a broadcast address / unicast to a host |
| --recursion | Recursion desired (for WINS, with -U) |
| -r | Bind UDP 137 (needs root) |
| -T / -f | Reverse DNS name / reply flags |
| --name-resolve= | lmhosts, host, wins, bcast order |
158.6 net: how net rpc works
- Step 1
1.net connects to FILESRV TCP 445
- Step 2
2.SMB3 SESSION_SETUP as root
- Step 3
3.Open \samr on IPC$
- Step 4
4.EnumDomainUsers request
- Step 5
5.Server returns asha, root -> printed by net
158.7 net: target and behaviour options
- -S server, -I IP, -p 445|139, -w target domain; options can come before the command.
- --long shows type and description; in this version -l is log basename, not long (the next arg became a log folder: error, exit 235).
- With only -I, rpc share list failed silently (exit 235); adding -S FILESRV -p 139 worked.
- net rap uses old SMB1 RAP; with an SMB3 connection: smb1cli error (exit 255).
- Other: -f force, -i stdin, -T dry run, -t timeout, -r reboot after join.
net rpc share list --long -S FILESRV \ -U root%RootLab158net rpc share list -l -S FILESRV \ -U root%RootLab158net -S FILESRV -U asha%LabPass158 rpc infonet rpc share list -I 192.168.178.10 \ -S FILESRV -p 139 -U root%RootLab158net rap share -S FILESRV \ -U root%RootLab158$ net rpc share list -l -S FILESRV -U root%RootLab158[2026/11/09 07:21:53, 0] ../../lib/util/debug.c:1273(reopen_one_log) reopen_one_log: Unable to open new log file '-S/log.net': No such file or directory(exit 235)$ net rap share -S FILESRV -U root%RootLab158smb1cli_req_writev_submit: called for dialect[SMB3_11] server[FILESRV](exit 255)158.8 net: connection and authentication
- -n MYCLIENT sets the client NetBIOS name (server created log.myclient on a port 139 connection).
- -W sets the user domain; a standalone server maps it to its local SAM.
- -d 3 showed 'Connecting to 192.168.178.10 at port 445' and Domain Name: LAB.
- -k is deprecated; Kerberos needs a DNS name and a KDC.
- Wrong password and anonymous -N both gave LOGON_FAILURE (guest access off). Use -A FILE in scripts.
$ net rpc info -S FILESRV -U root%WrongPassCould not connect to server FILESRVThe username or password was not correct.Connection failed: NT_STATUS_LOGON_FAILURE$ net rpc info -N -S FILESRVCould not connect to server FILESRVConnection failed: NT_STATUS_LOGON_FAILURE158.9 net: time, join and machine trust
- net time -S shows server time (1 s ahead of the client); time system gives date-command format; time zone gives the GMT offset; time set changes the local clock (not run).
- No AD in the lab: ads info finds no LDAP server; rpc join: a standalone machine cannot join; ads join needs security = ads and a realm.
- testjoin (rpc and ads) both report the join is not valid.
- Real domain: ads join createcomputer=OU dnshostname=FQDN, changetrustpw rotates the trust password, ads leave.
$ net time system -S FILESRV110907232026.05$ net time zone -S FILESRV+0000$ net rpc testjoin -S FILESRVJoin to domain 'LAB' is not valid: NT_STATUS_CANT_ACCESS_DOMAIN_INFO$ net ads testjoin -I 192.168.178.10Join to domain is not valid: NT code 0xfffffff6158.10 net: users and groups
- As root: net rpc user lists asha, root; user add ravi and group add engineers worked, and the add user script created real Unix accounts.
- group addmem and user rename gave ACCESS_DENIED on a standalone server (need group mapping and extra privileges).
- Normal user asha: even user add is denied.
- user delete / group delete cleaned up; ads user found no AD; rap failed with the SMB1 error.
net rpc user -S FILESRV -U root%RootLab158net rpc user add ravi 'LabRavi158' \ -S FILESRV -U root%RootLab158net rpc group add engineers \ -C 'Lab engineers' \ -S FILESRV -U root%RootLab158net rpc user delete ravi \ -S FILESRV -U root%RootLab158net rpc group delete engineers \ -S FILESRV -U root%RootLab158[srv]$ grep -E '^(ravi|engineers):' /etc/passwd /etc/group/etc/passwd:ravi:x:1001:1001:Linux User,,,:/home/ravi:/sbin/nologin/etc/group:ravi:x:1001:/etc/group:engineers:x:1002:$ net rpc user delete ravi ...Deleted user 'ravi'.$ net ads user -I 192.168.178.10 -U root%RootLab158ads_connect: No logon servers are currently available to service the logon request.158.11 Comparison: net rpc vs ads vs rap
| Point | net rpc | net ads | net rap |
|---|---|---|---|
| Protocol | MS-RPC pipes (SAMR, SRVSVC) | LDAP + Kerberos | RAP over SMB1 |
| Works with | Any SMB server, NT4-style domains | Active Directory | Old SMB1 servers only |
| Lab result | Users, groups, shares, info OK | No logon servers (no AD) | smb1cli error on SMB3 |
158.12 Common mistakes
- Treating Samba net like Windows net (net use, net user are local Windows tools).
- Using -l for long output in net (it is the log folder; use --long).
- Using -R for recursion in nmblookup (it is name-resolve; use --recursion).
- Expecting smbtree output without SMB1 and a master browser.
- Putting passwords in -U in scripts instead of -A FILE.
158.13 Interview tips
- nmblookup NAME = broadcast name to IP; nmblookup -A IP = node status, all names.
- <1d> = local master browser, <20> = file server service.
- net rpc = MS-RPC (any SMB server), net ads = AD over LDAP/Kerberos, net rap = SMB1 legacy.
- NetBIOS name service uses UDP 137; SMB itself uses TCP 445 (139 for NetBIOS session).