Difference between revisions of "OpenWRT WINS with Samba"

3,087 bytes added ,  13:55, 19 August 2021
m
Line 34: Line 34:
<nowiki>*</nowiki> This webpage notes that there are various ways to display all of the records: https://superuser.com/questions/1492010/finding-all-samba-shares-in-local-network
<nowiki>*</nowiki> This webpage notes that there are various ways to display all of the records: https://superuser.com/questions/1492010/finding-all-samba-shares-in-local-network


====== Static WINS Entries (not to be confused with LMHOSTS File) ======
======Static WINS Entries (not to be confused with LMHOSTS File)======
The best tip came from here (scroll down to Static WINS Entries): https://www.samba.org/~ab/output/htmldocs/Samba3-HOWTO/NetworkBrowsing.html
 
First things first: The LMHOSTS file is used ''only'' the local computer / server (IE, the OpenWRT / LinkSys device that is acting as the WINS / NMBD (The component of Samba that equates to WINS) Server).  The LMHOSTS File and its entries are ''not'' used in resolving names to IP Addresses for clients of the WINS Server.  That duty is held by two files: wins.dat and browse.dat.  And no one seems to want anyone to find those files (IE, I dare anyone to find documentation, besides here that notes the location of both of these files.
First things first: The LMHOSTS file is used ''only'' the local computer / server (IE, the OpenWRT / LinkSys device that is acting as the WINS / NMBD (The component of Samba that equates to WINS) Server).  The LMHOSTS File and its entries are ''not'' used in resolving names to IP Addresses for clients of the WINS Server.  That duty is held by two files: wins.dat and browse.dat.  And no one seems to want anyone to find those files (IE, I dare anyone to find documentation, besides here that notes the location of both of these files.


/tmp/lib/samba/wins.dat (AKA /var/lib/samba/wins.dat)
/tmp/lib/samba/wins.dat (AKA /var/lib/samba/wins.dat)
/tmp/lib/samba/wins.tdb (AKA /var/lib/samba/wins.tdb)


/tmp/cache/samba/browse.dat (AKA /var/cache/samba/browse.dat)
/tmp/cache/samba/browse.dat (AKA /var/cache/samba/browse.dat)
Line 47: Line 51:
The format of entries in the /var/lib/samba/wins.dat file are from here: https://www.linuxtopia.org/online_books/network_administration_guides/samba_reference_guide/17_NetworkBrowsing_23.html
The format of entries in the /var/lib/samba/wins.dat file are from here: https://www.linuxtopia.org/online_books/network_administration_guides/samba_reference_guide/17_NetworkBrowsing_23.html


* "NAME#TYPE" TTL ADDRESS+ FLAGS
*"NAME#TYPE" TTL ADDRESS+ FLAGS
** NAME = NetBIOS name
**NAME = NetBIOS name
** TYPE = NetBIOS type
**TYPE = NetBIOS Type (from https://www.techrepublic.com/article/how-netbios-name-resolution-really-works/, scroll down about half way and https://flylib.com/books/en/2.221.1/windows_internet_name_service_wins_.html): 00 = Workstation or Domain Name, 01 = Messenger (Workstation), 20 = File Server, etc.
** TTL = Time To Live (in seconds)
**TTL = Time To Live (in seconds), NOTE: Using a time of 0 (zero) makes the entry equivalent to a static entry.
** ADDRESS+ = One, possibly more addresses for the Computer / Entity
**ADDRESS+ = One, possibly more addresses for the Computer / Entity
** FLAGS = NetBIOS  
**FLAGS = NetBIOS Flags (from https://www.samba.org/~ab/output/htmldocs/Samba3-HOWTO/NetworkBrowsing.html): The NetBIOS flags may be interpreted as additive hexadecimal values: 00 - Broadcast node registration, 20 - Peer node registration, 40 - Meta node registration, 60 - Hybrid node registration, 02 - Permanent name, 04 - Active name, 80 - Group name. The 'R' indicates this is a registration record. Thus 66R means: Hybrid node active and permanent NetBIOS name. These values may be found in the <code>nameserv.h</code> header file from the Samba source code repository. These are the values for the NB flags.
***64R = Hybrid Node Registration AND Active Name AND registered
 
Wait!  What about the /tmp/lib/samba/wins.tdb file?  According to this (even though it refers to Samba 3, it applies to Samba 4): https://www.samba.org/samba/docs/old/Samba3-HOWTO/tdb.html, the wins.tdb file is used for "permanent storage" (IE static WINS entries).  Can it be edited (in a useful manner)?  No, because it is a binary file, not a text file.  How is information input into it?  Using the NET command? We'll see.
 
How about the TDBTOOL (It's like the MySQL Command, in that it opens it's own small interpreter environment)?  More information here: https://www.samba.org/samba/docs/3.2/man-html/tdbtool.8.html  Nope, that's a big rabbit hole that won't help.
 
Ahhh!  Here's the answer, with the best tip coming from this site: https://samba.samba.narkive.com/UPIyT5mM/samba-as-a-wins-server  But alone that isn't enough as the static entries need to be made so they can persist across router reboots.
 
* Stop the NMBD Service (Hint: the SMB service starts and stops the NMBD service in OpenWRT): service samba4 stop (assuming Samba 4 is being used, which it should be, but plain samba, AKA Samba 3 should work the same.)
* Add an entry to the /var/lib/samba/wins.dat file (...remembering that it will not persist across router reboots, see below to solve that issue)
* Start the NMBD Service: service samba4 start
* Add the below to the OpenWRT Startup Scripts (via LuCI GUI: System, Startup, Local Startup Tab;
<syntaxhighlight lang="text">
### Adds Static Mapping for WINS from /etc/samba/samba.static
### Don't forget to put static entries in the above noted file in the correct format


/etc/init.d/samba4 stop
# The file may not exist at this point during startup, so create it with TOUCH
touch /tmp/lib/samba/wins.dat
chmod 644 /tmp/lib/samba/wins.dat
cat /etc/samba/samba.static >> /tmp/lib/samba/wins.dat
/etc/init.d/samba4 start
</syntaxhighlight><br />
======Recommendation for Windows Hosts that are Multihomed (IE, have more than one network interface)======
======Recommendation for Windows Hosts that are Multihomed (IE, have more than one network interface)======
For some odd reason, if only one interface is configured with WINS server information, it reports the IP Address of all the network interfaces on the Windows machine to the WINS Server.  IE, all the other network interfaces can have a blank / empty entry for WINS server, but that one network interface configured with a WINS server will report ''all'' of the IP Addresses associated with all of the other network interface.  To prevent this, configure a different WINS server for each interface OR "Disable NetBIOS over TCP/IP" (oddly, this does not disable the ability of one to access shared folders, incoming or outgoing, on the network interface in question as it seems NetBEUI is the acronym that encompasses that functionality).  This even includes PPTP VPN Connections and probably OpenVPN connections too.
For some odd reason, if only one interface is configured with WINS server information, it reports the IP Address of all the network interfaces on the Windows machine to the WINS Server.  IE, all the other network interfaces can have a blank / empty entry for WINS server, but that one network interface configured with a WINS server will report ''all'' of the IP Addresses associated with all of the other network interface.  To prevent this, configure a different WINS server for each interface OR "Disable NetBIOS over TCP/IP" (oddly, this does not disable the ability of one to access shared folders, incoming or outgoing, on the network interface in question as it seems NetBEUI is the acronym that encompasses that functionality).  This even includes PPTP VPN Connections and probably OpenVPN connections too.