HowTo Configure Stable Network Browsing on a Samba Windows/Ubuntu (& Kubuntu) SOHO LAN

Simply put, its an explanation of the common options for making network shares on Windows and Linux machines visible in the network browsers of both operating systems on the simple networks used in homes and small businesses (AKA a Windows/Linux workgroup on a SOHO LAN).

If you're a new user having trouble getting your first Ubuntu Samba network going, I suggest the Samba LAN Primer before this tutorial and perhaps return when you have basic Samba networking operational.

↑↑↑↑Options for network Name Resolution

The key to finding shared resources on a network is the list of network names of servers -vs- their IP addresses. If a client machine has this list it can resolve names to addresses and can proceed to find the servers and their resources. This is called Name Resolution. We discuss three primary types of Name Resolution here based on the Local Master Browser, the WINS Server and the lmhosts file.

Local Master Browser (LMB): the LMB is elected from amongst all the workstations on the common subnet. The factors in an election include a workstation's current role, its up-time, the computer's operating system and "OS level" setting. The Local Master keeps a "browse list" of all the SMB servers on the local subnet, together with names of all workgroups on the local subnet. This list is served to all client workstations. The IP addresses of Local master Browsers can be either static or dynamic. Clients obtain the addresses of servers from the Local Master.

WINS Server: a wins server collates the names and IP addresses of the workstations on the LAN, similar to a Local Master Browser, except the wins server is not elected. A wins server must be switched on permanently. It is created by the network Administrator. Each workstation on the LAN has the address of the wins server coded into its configuration and communicates it's arrival or departure to the wins server each time it joins or leaves the network. The IP address of a WINS Server is fixed. Clients obtain the addresses of servers from the wins server.

Lmhosts File: the lmhosts file is a text file that must be manually coded into each Linux and Windows workstation. The lmhosts file is a simple list of IP addresses and their corresponding network names (netBIOS names). Changes to the naming or IP addresses of servers on the LAN must be manually updated on each computer. All servers on the LAN must have fixed IP addresses. Servers cannot obtain their IP addresses dynamically. Clients can have either dynamic or fixed IP addresses. Clients obtain the addresses of servers from their individual lmhosts file.

Hosts File: The hosts file is a text file located at /etc/hosts. The hosts file fulfills the most basic level of name resolution in Linux. In the early days of the Internet it was the DNS service for Linux machines (but now the Net is too big for that). It operates during boot, before any of the more complex resolving functions. The hosts file contains a static list of IP addresses against Linux hostnames. These are not netBIOS names as understood for a Samba LAN. Windows has a functionally identical hosts file. You can set up a LAN based on the hosts file but I won't discuss that here because the hosts file has other functions that I prefer to keep separate from the resolution of netBIOS names for Samba.

↑↑↑↑Restoring & tweaking Kubuntu's / Ubuntu's default Samba configuration

Many people arrive here after trying unsuccessfully to configure Samba browsing on their Ubuntu installation and those attempts can sometimes radically alter the default configuration. In this section I'll show you how to restore the defaults and also how to optimise the default installation for a workgroup on a SOHO LAN.

The Samba configuration file, smb.conf, is a text file located at /etc/samba/smb.conf. Smb.conf is made up of stanzas separated by names in square brackets. Each stanza defines a shared resource, except for the first stanza which is labelled [global] and defines broad, common behaviour for all resources. I've linked in the default file for you to view, copy or print, so you can compare it with your smb.conf file or even replace it: link to default smb.conf. I've also included a sanitised copy where I've edited out all comment lines so you can get some easy focus on the content: link to sanitised default smb.conf. You can list your smb.conf file and check it against either of these versions of the default files by issuing this command in a console window:

  •   To list your smb.conf file: cat /etc/samba/smb.conf

As I said, smb.conf is a text file so you can alter it most simply by opening smb.conf in a text editor where you can edit the [global] stanza. If you want to completely restore it, copy the material on one of the two links and paste it in.

Issue one of the following console commands to edit Samba's configuration file with 'superuser' privileges:

  • • For Ubuntu users: gksu gedit /etc/samba/smb.conf
  • • For Kubuntu users    : kdesu kate /etc/samba/smb.conf

Here is an optimised replacement [global] stanza to use as a template when you edit/repair your smb.conf. It is tailored for best performance in a workgroup scenarios on a SOHO LAN and is the best starting point for creating stable network browsing:

[global]
workgroup = WORKGROUP_NAME
netbios name = NETBIOS_NAME
name resolve order = bcast host lmhosts wins
server string =
printing = cups
printcap name = cups
printcap cache time = 750
cups options = raw
use client driver = yes
map to guest = Bad User
usershare allow guests = Yes
usershare max shares = 100
usershare owner only = False

You must change WORKGROUP_NAME to your chosen common name. Frequently the names MSHOME and WORKGROUP will be used in a SOHO environment but any name you like will do, so long as it's common to all machines.

You also replace NETBIOS_NAME with the network name for your Ubuntu server, the name that will appear beside your computer icon in network browsers.

It's quite likely after making these changes and restarting the Samba daemons (or rebooting your network) that browsing will work OK. But the purpose of this tutorial is to examine all the options and you will now be in a position to do that.

↑↑↑↑About the Name Resolve Order

Each [global] paragraph sets the order in which the software attempts to resolve netBIOS names to IP addresses in the parameter called the name resolve order. In the example above it is:

name resolve order = bcast host lmhosts wins

That means that the software will look first to Broadcast Name Resolution, next to the host file at /etc/hosts, then the lmhosts file at /etc/samba/lmhosts and finally it will look for a WINS Server. It's very important to set the order of the terms in accordance with the name resolution mechanism/s you have in place. For example if you are relying on Broadcast Name Resolution you would have bcast up front. The Ubuntu devs have left the parameter out of the [global] stanza, which means that the default applies. Here's the default:

# default that acts in the absence of any defined order
name resolve order = lmhosts host wins bcast

The reason many if not most Ubuntu Samba users initially have difficulty seeing servers on their Samba LAN is that this order operates by default and the first three options are simply not configured initially for Samba. Only bcast is useful when Samba is initially installed, and since it is placed last, browsing with Ubuntu's default Samba installation can be very flaky.

If nothing else is done to the default Samba installation, it should at least have the name resolve order set with bcast first. Here are the obvious logical sequences for the name resolve order in the various configurations discussed in this tutorial:

  • • Local Master Browser: bcast host lmhosts wins
  • • WINS Server: wins bcast host lmhosts
  • • Lmhosts file: lmhosts bcast host wins

↑↑↑↑Name Resolution via a Local Master Browser

There's very little to making this happen. Select the machine you prefer for the Local Master Browser and add these three lines into the [global] stanza of the smb.conf file:

local master = yes
preferred master = yes
os level = 65

The preferred master statement ensures the machine will call an election when this machine comes on line and the os level of 65 ensures that it will win.

You can have only one preferred master on the one subnet. If you have more, then the "preferred masters" will constantly call elections against each other and tie up communications. The other Linux machines are normally set to obtain a favourable position during browsing elections by adding the following two lines into their [global] stanzas:

local master = yes
os level = 33

The os level of 33 ensures a win over Windows but not over a Linux "preferred master" with a level of 65.

No alterations are needed in Windows machines. In summary, the [global] template for the Preferred Master Browser is on the left below while the [global] template for the other Linux machines on the subnet are on the right:

# Template for a Preferred LMB
# Note: only one of these per subnet

# Template for a non-Preferred LMB
# All the other Linux machines on the subnet

[global]
workgroup = WORKGROUP_NAME
netbios name = NETBIOS_NAME
name resolve order = bcast host lmhosts wins
local master = yes
preferred master = yes
os level = 65
server string =
printing = cups
printcap name = cups
printcap cache time = 750
cups options = raw
use client driver = yes
map to guest = Bad User
usershare allow guests = Yes
usershare max shares = 100
usershare owner only = False
[global]
workgroup = WORKGROUP_NAME
netbios name = NETBIOS_NAME
name resolve order = bcast host lmhosts wins
local master = yes
os level = 33
server string =
printing = cups
printcap name = cups
printcap cache time = 750
cups options = raw
use client driver = yes
map to guest = Bad User
usershare allow guests = Yes
usershare max shares = 100
usershare owner only = False
 

↑↑↑↑Name Resolution via a WINS Server

Preliminary facts: WINS is an acronym for Windows Internet Name Service. Read about it here. There is only one WINS Server per subnet. You cannot make a standard Windows machine into a WINS Server. Microsoft has it's WINS servers inside its server range of software. Any Samba machine can be made into a WINS server (only one per LAN subnet). You can have a backup WINS Server on the LAN (not discussed here). All the other machines on the LAN must be configured as WINS clients.

Configure nsswitch.conf & install winbind: Do this for all the x-buntu wins servers and wins clients: The x-buntu family require the winbind package for a Wins server setup. You can install it via System --> Administration --> Synaptic package manager. You must also enable wins in the Name Services Switch, nsswitch.conf, located at /etc/nsswitch.conf. Open it for editing with a superuser version of gedit or kate (see dot points earlier) and locate this line:

hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4

and add the parameter wins in the correct sequence as illustrated, so the line looks like this:

hosts: files mdns4_minimal [NOTFOUND=return] wins dns mdns4

Configuring the Linux WINS Server: The WINS Server is always powered on so it can receive sign-on and sign-off messages from all the clients on the network. So it would be economical to combine the WINS Server function with other major server functions like print server and file server. That's for you to consider.

Configuration of a server has two aspects. First you add one line into the [global] stanza of the Samba configuration file. The line turns on the parameter called wins support. Second you move wins to the first position in the name resolve order parameter, as below:

wins support = yes
name resolve order = wins bcast host lmhosts

Remember to configure your wins server with a fixed IP address.

Configuring Linux WINS clients: Configuration of a client has two aspects. First you add one line into the [global] stanza of the Samba configuration file. The line tells the client machine the IP address of the server so they can communicate. Second you move wins to the first position in the name resolve order parameter, as below:

wins server = 192.168.0.33
name resolve order = wins bcast host lmhosts

Change the IP address to suit your situation. Only the server must have a fixed IP address; clients can have either fixed or dynamic IP addresses.You must not have both the lines wins server = IP address and wins support = yes in the same smb.conf file.

Templates for the WINS Server and the WINS clients: In summary, the [global] template for a WINS Server is on the left below while the [global] template for the other Linux machines (WINS clients) on the subnet are on the right:

# Template for a WINS Server
# Note: only one of these per subnet

# Template for the WINS clients
# All the other Linux machines on the subnet

[global]
workgroup = WORKGROUP_NAME
netbios name = NETBIOS_NAME
wins support = yes
name resolve order = wins bcast host lmhosts
server string =
printing = cups
printcap name = cups
printcap cache time = 750
cups options = raw
use client driver = yes
map to guest = Bad User
usershare allow guests = Yes
usershare max shares = 100
usershare owner only = False
[global]
workgroup = WORKGROUP_NAME
netbios name = NETBIOS_NAME
wins server = 192.168.0.33
name resolve order = wins bcast host lmhosts
server string =
printing = cups
printcap name = cups
printcap cache time = 750
cups options = raw
use client driver = yes
map to guest = Bad User
usershare allow guests = Yes
usershare max shares = 100
usershare owner only = False

Configuring Windows WINS clients: Windows machines are configured for a WINS server via the Control panel. First find the icon for the Local Area Connection. For Vista & Windows 7 GoTo Control Panel --> Network & Sharing Centre --> (left panel) Manage Network Connections and you'll see the icon for the Local Area Connection. In Windows 2000 & XP GoTo Control Panel --> Network and Dial-up Connections and you'll see the icon for the Local Area Connection.

Once you have the LAN icon in the panel do this: Right-click Network Icon (Local Area Connection) --> select Properties --> highlight Internet Protocol Version 4 (IPv4) --> Properties --> Advanced --> WINS --> Add --> enter the IP address of the WINS server --> Add --> OK --> OK etc.

That's the end of the configuration for setting a Windows client to communicate with a WINS Server.

↑↑↑↑Name Resolution via the lmhosts file

Preliminary facts: the lmhosts file exists in both Windows and Linux with the same function, to provide a simple list of network names of servers against their IP addtresses as an additional mechanism for name resolution. The same list goes into every client machine on the LAN. All servers must have fixed IP addresses. Clients can have either fixed or dynamic IP addresses. Any changes must be edited into the lmhosts files manually. Obviously Name Resolution by the lmhosts file is for small networks only because of the large administrative burden involved.

Configuring a Linux workstation: There are two facets. You must edit the list into the lmhosts file which is a text file located at /etc/hosts and you must set the name resolve order to reflect the importance of the lmhosts file, with lmhosts first.

# template for the [global] stanza of smb.conf
# if using the lmhosts file for name resolution

# template for an openSUSE lmhosts file
# place the file at /etc/samba/lmhosts

[global]
workgroup = WORKGROUP_NAME
netbios name = NETBIOS_NAME
wins support = yes
name resolve order = lmhosts bcast host wins
server string =
printing = cups
printcap name = cups
printcap cache time = 750
cups options = raw
use client driver = yes
map to guest = Bad User
usershare allow guests = Yes
usershare max shares = 100
usershare owner only = False
127.0.0.1            localhost
192.168.3.10         filestorage
192.168.3.34         printserver
192.168.3.62         musicserver
...
...
....
etc...

Note: the Windows version of lmhosts is identical except you leave out the line naming localhost, the first line.

Configuring a Windows workstation: Just as in Linux, Windows has an lmhosts file. The file is located at C:\windows\system32\drivers\etc\lmhosts. Here's a typical template, below right:

# template for a Windows lmhosts file
# C:\windows\system32\drivers\etc\lmhosts

192.168.3.10         filestorage
192.168.3.34         printserver
192.168.3.62         musicserver
...
...
....
etc...

This is just a template. Use real values and names in the table, taken from the servers on your subnet.

In addition to creating the lmhosts file, you must switch on the LMHOSTS Lookup facility. GoTo Control Panel --> Network and Sharing Centre --> Manage Network Connections --> Local Area Connection icon. Right-click the LAN icon --> select Properties --> Internet Protocol version 4 (IPv4) --> Properties --> Advanced. Under the WINS tab you find Enable LMHOSTS lookup. Make sure it is ticked/enabled --> OK --> OK --> OK to save and exit.

That's all folks.
Take it easy.
Swerdna: 05 July 2009