OpenWRT WINS with Samba: Difference between revisions

Line 39: Line 39:
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;


* Stop the Samba Service (this also stops the NMBD service): service samba4 stop
*Stop the Samba Service (this also stops the NMBD service): service samba4 stop
*Add an entry to the /var/lib/samba/wins.dat file using the following format (see wins.dat format explanation further down)
*Add an entry to the /var/lib/samba/wins.dat file using the following format (see wins.dat format explanation further down)
**"NAME#TYPE" TTL ADDRESS+ FLAGS
**"NAME#TYPE" TTL ADDRESS+ FLAGS
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
*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)
** "NAME#TYPE" TTL ADDRESS+ FLAGS (see wins.dat format explanation further down)
**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)


*Add the below to the OpenWRT Startup Scripts (via LuCI GUI: System, Startup, Local Startup Tab;
*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">
### Adds Static Mapping for WINS from /etc/samba/samba.static file to /tmp/lib/samba/wins.dat file


'''wins.dat Format Explanation'''
###### 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.
# /etc/init.d/samba4 stop
 
###### The samba directory and wins.dat file do not yet exist when these commands run during the startup process, so create them and make sure the permission are correct (the permissions should be correct, but explicitly make sure with the chmod command).
mkdir /tmp/lib/samba
touch /tmp/lib/samba/wins.dat
chmod 644 /tmp/lib/samba/wins.dat
 
###### Append Static Mappings (that the Microsoft term) for WINS in the samba.static file into the /tmp/lib/samba/wins.dat file that is dynamically updated by the SAMBA / NMBD Service, and also created if it doesn't already exist.  And as noted, wins.dat file will be deleted when the router is restarted).
cat /etc/samba/samba.static >> /tmp/lib/samba/wins.dat
 
###### /etc/init.d/samba4 start
</syntaxhighlight>'''wins.dat Format Explanation'''


*"NAME#TYPE" TTL ADDRESS+ FLAGS
*"NAME#TYPE" TTL ADDRESS+ FLAGS
Line 64: Line 79:
The above information was sourced from these websites;
The above information was sourced from these websites;


* https://www.linuxtopia.org/online_books/network_administration_guides/samba_reference_guide/17_NetworkBrowsing_23.html
*https://www.linuxtopia.org/online_books/network_administration_guides/samba_reference_guide/17_NetworkBrowsing_23.html
* https://www.techrepublic.com/article/how-netbios-name-resolution-really-works/
*https://www.techrepublic.com/article/how-netbios-name-resolution-really-works/
* https://flylib.com/books/en/2.221.1/windows_internet_name_service_wins_.html
*https://flylib.com/books/en/2.221.1/windows_internet_name_service_wins_.html
* https://www.samba.org/~ab/output/htmldocs/Samba3-HOWTO/NetworkBrowsing.html
*https://www.samba.org/~ab/output/htmldocs/Samba3-HOWTO/NetworkBrowsing.html