Samba: HowTo Configure Stable Network Browsing on a SOHO LAN - Explanation
Introduction: This tutorial is about the simple home network with mixed Windows and Linux computers. AKA the small office home office SOHO LAN. The focus is on configuring stable browsing. This page contains background and explanation towards understanding how to stabilise network browsing. There is also a companion recipe page with practical code and configuration guides to implement browsing. If you don't need to understand, or if you already understand but can't quite remember the minutiae, go to the companion recipe page.
IP addressing: Workstations can have fixed IP addresses, coded in by you, or dynamic IP addresses, assigned by a DHCP server in your network. You can use either method. Fixed IP addressing IMHO gives superior performance and is easier to administer. Dynamic addressing predominates because its the do-nothing default and it's usually fine in the typical home environment. Administrators often use fixed IP addresses for some servers, e.g. print server, name server, heavy duty (business) file server.
DHCP is an acronym for Dynamic Host-Control Protocol. Contemporary routers contain DHCP servers.
HowTo Install a Fixed IP Address in Linux: You can set a fixed IP address on a Suse Linux host by editing the Network Card Settings found under Network Devices in YAST. Also ensure to set gateway to 192.168.0.1 in "routing" , and the "hostname" (e.g. charlie) and domain name (SOHOLAN) as well during Static Setup; while you're there you should also insert the IP addresses of the primary and secondary Name Servers supplied by your Internet Service Provider (ISP).
Pictorials for setting IP addresses in Suse are on the Recipe Page. Plate#2 is typical of fixed addressing and Plate#3 is typical of dynamic addressing.
HowTo Install a Fixed IP Address in Windows: You can set a fixed IP address on a windows host by R-click the "Local Area Connection" icon in "Network and Dial-up Connections" and under "properties" for TCPIP, fill in the panel attached to "Use the following IP address" for IP [e.g. 192.168.0.9], subnet [e.g. 255.255.255.0] and gateway/router IP [192.168.0.1]. Here you should also insert the IP addresses of the primary and secondary Name Servers supplied by your ISP.
Pictorials for setting IP addresses in Windows are on the Recipe Page. Plate#4A is typical of fixed addressing and Plate#4B is typical of dynamic addressing.
Samba Starting Point - The Samba Client: The Samba configuration file is located at /etc/samba/smb.conf. It contains a comprehensive suite of possible shares for users to tweak. It is not meant to be ready to go. Just as you must think about what you want to share in Windows, so too in Linux. If you leave them as is, you do expose the entire contents of your data at all levels: to other users of your workstation, to other workstations on the LAN and to the Internet generally, commencing when you power on. I prefer to delete these shares so I have some basic level of protection for stuff like my banking passwords and so on. You might prefer just to comment them off (e.g. switch them off using a GUI like Yast)]
For completeness and for new users, here is the default openSUSE ver 10.3 installed [global] paragraph in the file /etc/samba/smb.conf:
If you're like me you'll keep this in mind as a reference for when you muck up your [global] settings and want to restore them to the defaults. It's not exactly the same as the default [global] for 10.2 - but it's fine.
Here below is all you really need in smb.conf to browse on the network. Don't rush off and delete other entries - You just need to know that the default setup will be tweaked in this tutorial - but the config file must have at least these two lines if you want to browse:
One point I'm making here is that the proper starting point in smb.conf for a SOHO LAN is different from the default Suse smb.conf file.
Name Resolution option 1 - using Lmhosts - Summary: If the workstations on a SOHO LAN are fairly static and few in number then a very effective way to achieve stable name resolution is to assign a fixed IP address to every workstation and to list the IP Address/NetBIOS name pairs in the Windows and Linux lmhosts files. This is not widely known. It suffers somewhat from continuing to show switched-off machines in the network browser, which is why I say "few in number".
Name Resolution option 1 - using Lmhosts - Explanation: First thing - don't get confused - I'm going to talk about the hosts file and the lmhosts file - they're quite different. The "hosts" file fulfills the most basic level of name resolution in Linux. It operates during boot, before any of the more complex resolving functions. The hosts file contains a static list of IP addresses against hostnames. Windows has a functionally identical hosts file. In a Linux-only LAN with only fixed IP addressing, the hosts files do resolve names across the simple Linux LAN. But Windows uses NetBIOS over TCPIP (NBT). It needs to resolve NetBIOS names to TCPIP addresses, not hostnames to TCPIP addresses. The NetBIOS name is different from the hostname, but for simplicity and to avoid confusion the same name is usually used for both. In a Windows/Samba LAN using only fixed IP addressing, it is the "lmhosts" files with their pairs of IP addresses and netBIOS names that provide the name resolution. This may be used in the small, simple SOHO LAN (if purely fixed IP addressing is used). It is not generally appreciated that this is a low trouble, low maintenance way to go.
The Linux hosts file is at /etc/hosts and the lmhosts file usually at /etc/samba/lmhosts. The Windows hosts file is at %SystemRoot%\system32\drivers\etc\hosts and the lmhosts file is at %SystemRoot%\system32\drivers\etc\lmhosts.
Name Resolution option 2 - with the Local Master Browser (LMB): If dynamic IP addressing is used then the lmhosts files lose a lot of their appeal. Broadcast Name Resolution is the default for a dynamic IP environment. Putting Linux hosts into a Windows NBT [NetBios over TCPIP] environment with simple defaults quite frankly produces flaky, frustrating browsing results. Fortunately Samba allows a Linux host to be configured as Local Master Browser. Name resolution by LMB works for fixed IP and dynamic IP addressing. On bootup and at regular intervals the hosts in a workgroup elect a LMB to collate name/address pairs for the workgroup. Samba configuration allows YOU to designate one Linux host to be the Local Master Browser. A Linux LMB very effectively stabilises browsing and improves the user experience on the SOHO LAN. The Linux host chosen as LMB has this code in the [global] section of the smb.conf file:
The line "os level = 65" generally ensures other Windows or Linux hosts will not be elected LMB so it's not necessary to configure the other hosts to fail these elections. The valid range for os level is 0-255.
Name Resolution option 3 - with a WINS Server: WINS stands for Windows Internet Name Service. A wins server collates the name/address pairs of hosts that log on and log off the workgroup, and serves these to workgroup members for name resolution purposes. You can purchase the wins server software in e.g. Windows NT or 2000 Server. However since it's incorporated into Samba, with increased functionality, that's the better option. Installing a wins server is trivially easy. The result for browsing is just splendid. Wins server functionality extends well beyond using it to control workgroup browsing but I won't discuss that here. Its use for browsing is highly recommended in the Official Samba-3 HowTo & Reference Guide.
To install wins server you give one Linux host a fixed IP address, e.g. 192.168.0.2, and put this code into smb.conf:
Then point other hosts to the server's IP address. In linux hosts use:
You can set the pointer to the wins server in the network settings of windows hosts by opening "network & dial-up connections" in Control Panel and R-click --> properties of the LAN Icon. Then TCPIP --> properties --> advanced --> Wins --> Add wins server 192.168.0.2
You can see recipes and pictures for the wins server on the Recipes Page, third section..
Which method should You use? If you're using only fixed IP addressing you should use option one. If you're using only dynamic addressing (e.g. router + DHCP) or if you're using a mix of fixed and dynamic addressing, then both two and three are good, you choose (toss a coin).
I'm personally using LMB for my home network because as an inquisitive geek I'm always changing things - LMB setup is very flexible & forgiving. Even for the case where all IP's are fixed I ignore my own advice and use LMB instead of lmhosts.
Search Order - name resolve order: OK just to complete the picture you should tell Samba what order to search in to find a name/address pair. Put a search order line in the [global] of smb.conf, like this:
This example is designed for a workgroup with a wins server and the instructions are to search in this order: the data held by the wins server, if that fails use broadcast resolution, then check the lmhosts file, and last (host) go across to native Linux search options. You would of course rearrange the order to match the type of resolution you are using from options 1, 2 and 3.
Recipes: I've attached a page of recipes that puts these principles together. I think that separating the recipes from the explanations & preample makes this difficult topic less confusing.
Take it easy.
Swerdna: 08 February 2007