Difference between revisions of "OpenWRT WINS with Samba"

m
Line 35: Line 35:


======Static Mappings for WINS (Static Entries for Host Names and IP Addresses) - Not to be confused with LMHOSTS File======
======Static Mappings for WINS (Static Entries for Host Names and IP Addresses) - Not to be confused with LMHOSTS File======
As with everything in life (and OpenWRT), the solution isn't a simple 1, 2, 3 thing.  The first item worth mentioning is that configuring an LMHOSTS file on an OpenWRT router will only work with name resolution queries run from the OpenWRT router.  It will not be used when answering WINS queries from clients.
As with everything in life (and OpenWRT), the solution isn't a simple 1, 2, 3 thing.  The first item worth mentioning is that configuring an LMHOSTS file on an OpenWRT router will only work with name resolution queries run from the OpenWRT router.  The LMHOSTS file will not be used when answering WINS queries from clients.


Adding Static Mappings is easy using the below method (and also useless, because the settings will disappear when the router is restarted). It assumes Samba 4 is being used, but will also work with Samba 3 if minor changes are made to the commands;
Adding Static Mappings is easy using the below method (and also useless, because the settings will disappear when the router is restarted). It assumes Samba 4 is being used, but will also work with Samba 3 if minor changes are made to the commands;
Line 46: Line 46:
A better way to add Static Mappings that persist beyond router restarts is this;
A better way to add Static Mappings that persist beyond router restarts is this;


*Create and save a file with entries in the below format in /etc/samba/: nano /etc/samba/samba.static (it can be any name, but make sure it's the same configured in the below script)
*Create and save a file named samba.static with entries in the below format in the /etc/samba/ directory: nano /etc/samba/samba.static (it can be any name, but make sure it's the same configured in the below script) (use whatever file editor you want, VI, etc.)
**Put this line at the top of the file: VERSION 1 0
**Put this line at the top of the file: VERSION 1 0
**Enter subsequent entries on each line in this format: "NAME#TYPE" TTL ADDRESS+ FLAGS (see wins.dat format explanation further down)
**Enter subsequent entries on each line in this format: "NAME#TYPE" TTL ADDRESS+ FLAGS (see wins.dat format explanation further down)
Line 52: Line 52:
*Add the below commands to the OpenWRT Startup Scripts (via LuCI GUI: System, Startup, Local Startup Tab).  The comments can be eliminated and are only included to describe what each command does;
*Add the below commands to the OpenWRT Startup Scripts (via LuCI GUI: System, Startup, Local Startup Tab).  The comments can be eliminated and are only included to describe what each command does;
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
### Adds Static Mapping for WINS from /etc/samba/samba.static file to /tmp/lib/samba/wins.dat file
######## Adds Static Mapping for WINS from /etc/samba/samba.static file to /tmp/lib/samba/wins.dat file ########


###### There is no need to stop or start the Samba Service because the OpenWRT StartUp Script (rc.d) has a start position of 95 and the Samba4 Service has a start position of 98, so the SMB service isn't even started when this script runs.  The samba4 stop and start lines were put in to note this because according to Samba documentation, the samba service must be stopped to modify the wins.dat file with static entries.
###### There is no need to stop or start the Samba Service because the OpenWRT StartUp Script (rc.d) has a start position of 95 and the Samba4 Service has a start position of 98, so the SMB service isn't even started when this script runs.  The samba4 stop and start lines were put in to note this because according to Samba documentation, the samba service must be stopped to modify the wins.dat file with static entries.
Line 69: Line 69:


*"NAME#TYPE" TTL ADDRESS+ FLAGS
*"NAME#TYPE" TTL ADDRESS+ FLAGS
**NAME = NetBIOS name
**The quotes ( " " ) around NAME#TYPE are supposed to be there like that.  Yes, it looks weird, but that's the format.
**NAME = NetBIOS name of computer
**TYPE = NetBIOS Type (00 = Workstation or Domain Name, 01 = Messenger (Workstation), 20 = File Server, etc.)
**TYPE = NetBIOS Type (00 = Workstation or Domain Name, 01 = Messenger (Workstation), 20 = File Server, etc.)
**TTL = Time To Live in seconds, (Using a time of 0 (zero) ensures the entry will not be deleted by the Samba / NMBD service)
**TTL = Time To Live in seconds, (Using a time of 0 (zero) ensures the entry will not be deleted by the Samba / NMBD service)
**ADDRESS+ = One, possibly more addresses for the Computer / Entity
**ADDRESS+ = One, possibly more addresses for the Computer / Entity.  Only one is usually necessary for a computer or server, and testing wasn't done on this setting with multiple IP Addresses.
**FLAGS = NetBIOS Flags (from 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.
**FLAGS = NetBIOS Flags (...from one of the below credited websites: 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
***64R = Hybrid Node Registration AND Active Name AND a "registration record"
*Example: "BUBBA#00" 0 192.168.1.88 64R
*Example: "BUBBA#00" 0 192.168.1.88 64R


Line 84: Line 85:
*https://www.samba.org/~ab/output/htmldocs/Samba3-HOWTO/NetworkBrowsing.html
*https://www.samba.org/~ab/output/htmldocs/Samba3-HOWTO/NetworkBrowsing.html


'''Other Thoughts on Static Mappings for WINS'''


'''...and the diatribe written about the journey for the above solution (no need to read this for the Solution / How to configure Static Mappings for WINS;'''
While WINS might be old, it is still needed in many instances. For example, software that uses or was configured to use share names like "SERVER". How will that resolve to an IP Address?  Broadcast?  Yes, eventually. Unless Windows is configured to use DNS first (which it is by default) and there's a DNS server that resolves non-fully qualified host names to it's WAN IP Address by default (as BIND / NAMED does on OpenWRT and other versions of Linux installations).  In cases as just described, a name like "SERVER" that is expected to resolve to a local IP Address, is instead resolved to a useless and inaccurate WAN IP Address.  So WINS is still useful.  Even if it is being used as a backstop for other poorly configured software.  So be aware and understand what WINS can still be useful for.


The best tip came from here (scroll down to Static WINS Entries): https://www.samba.org/~ab/output/htmldocs/Samba3-HOWTO/NetworkBrowsing.html (scroll down to Static WINS Entries).  Tragically it was also buried in Google and Bing searches at an impossible to find depth.  One suggestion for that website might be to use Microsoft's term: "static mappings".  After all the entire WINS thing was created by Microsoft.  While WINS might be old, it is still needed in many instances.  For example, a vendor that uses share names like "SERVER".  How will that resolve to an IP Address?  Broadcast?  Sure...  Unless Windows is configured to use DNS first (which it is by default) and there's a DNS server that resolves non-fully qualified host names to it's WAN IP Address by default (as BIND / NAMED does on OpenWRT and other versions of Linux installations).  In cases like that, a name like "SERVER" that is expected to resolve to a local IP Address is resolved to a useless and inaccurate WAN IP Address.  So WINS is useful.  Just understand what it is useful for.
The best tip (although incomplete) came from here (scroll down to Static WINS Entries): https://www.samba.org/~ab/output/htmldocs/Samba3-HOWTO/NetworkBrowsing.html.  Tragically it was also buried in Google and Bing searches at an impossible to find depth.  One suggestion for that website might be to use Microsoft's term: "static mappings" so it can be closer to the top in search results.  After all the entire WINS thing was created by Microsoft.   
 
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)