Many times I've had to put a Linux workstation into a field of Windows cattle, but it’s been difficult to make Linux work properly with Network Neighborhood.
There are, of course, methods to make this madness a bit less, well, maddening. In this Daily Drill Down, I’ll try show you the methods and lay some groundwork to aid you in speeding up your Linux playtime in the Network Neighborhood.
What I want to accomplish
By the end of this article, I hope you’ll have a better understanding of how smbmount and smbclient work and whether or not there’s a GUI client that supports these tools that’s right for you.
By accomplishing these things, you should find yourself more easily integrating with those around you. The smbmount and smbclient commands will enable you to view the machines within your network and read and write to their directories.
The smbmount command is actually a front end for smbmnt. The smbfs is the application that contains both the smbmount and smbumount commands. To the average user, smbmount and smbumount will behave exactly as mount and umount do—except that you'll be mounting SMB shares across a LAN.
Since its inception, smbmount has undergone a rewrite, so its syntax has actually changed.
The first thing I will assume is you have Samba installed properly on your machine with the smbmountsetuid root. To set this bit, you must su into root and run these commands:
chmod u+s /usr/sbin/smbmount
chmod u+s /usr/sbin/smbumount
Once the bit is set, you can run the command to mount your SMB shares.
Setting the above bit has many security risks. Please do not set this bit if you’re unsure about the security of your network. If you decide not to set this bit to s, then you must have root access and run the smbmount command as root.
The long way home
First off, we’re going to play around with mounting our SMB shares the long, difficult way (as difficult as typing a command can be), and eventually we’ll develop a method for making this process much less painful.
Once I've covered all the commands, I’ll visit a couple of GUI applications that can make your life even easier!
The smbmount command has the following structure:
smbmount service mountpoint [ -o options ]
but it can be run as simply as
smbmount //shared/drive /mount/point
As you can see, we’re already whittling away at many of the steps to make viewing the SMB neighborhood as easy as possible. Just wait—you'll be shocked at how easy it is!
Let's take a look at the smbmount command and see just what it has to offer. The smbmount command, like all good Linux commands, has a few options to pass to the command. The biggest difference in these options is they are passed as a comma-separated list of key=value pairs. The possible options are shown here:
- username=<arg>—This option specifies the username with which to connect. If this is not given, then the environment variable USER is used. This option can also take the form user%password or user/workgroup or user/workgroup%password to allow the password and workgroup to be specified as part of the username.
- password=<arg>—This specifies the SMB password. If not given, then smbmount will prompt for a password (unless the guest option is given).
- netbiosname=<arg>—This sets the source NetBIOS name. It defaults to the local hostname.
- uid=<arg>—This argument sets the user id that files will be mounted as. It may be specified as either a username or a numeric uid.
- gid=<arg>—This option sets the group id that files will be mounted as. It may be specified as either a groupname or a numeric gid.
- port=<arg>—This one sets the remote SMB port number. The default port number is 139.
- fmask=<arg>—This option sets the file mask. This determines the permissions that remote files have in the local filesystem. The default is based on the current umask.
- dmask=<arg>—This one sets the directory mask. It determines the permissions that remote directories have in the local filesystem. The default is based on the current umask.
- debug=<arg>—This argument sets the debug level. This is useful for tracking down SMB connection problems.
- ip=<arg>—This option sets the destination host or IP address.
- workgroup=<arg>—This sets the workgroup on the destination.
- sockopt=<arg>—This one sets the TCP socket options. See the smb.conf socket options option.
- scope=<arg>—This argument sets the NetBIOS scope.
- guest—This means don’t prompt for a password.
- ro—This means to mount as read-only.
- rw—This means to mount as read-write.
This is quite a lengthy list of arguments. There are, I'm sure, situations in which you’ll need to pass a few of the above to Samba. Say, for example, you need to get into a Windows machine on the network from another user’s Linux machine. To do this, you’ll need to pass both the username= and the password = arguments (of course, after the =, you’d need to supply your own username and password).
Another possible scenario: You want to allow a user to mount a Windows share with read access only (a share that would normally have both read and write privileges). To do this, you would mount your coworker’s machine, passing the ro argument. Granted, you could achieve this with the proper configuration in the smb.conf file; however, there are times when you might wish to allow someone access to a share to which you would not normally allow access. Because of this, it’s nice to have the flexibility inherent in Samba.
Okay, back to the command. Let's first set up a hypothetical network with which you can play. This network will be a 172.22.1.0 scheme. The machine you are on is 172.22.1.24. The machine we want to access is a production machine (named Help) that has the IP address of 172.22.1.33, and the share we wish to mount is called documentation. We’d like to mount this share to our home directory in a subdirectory called work (this directory has already been created). To mount this directory, you’ll need to run (as user and on your own machine) the command
smbmount //172.22.1.33/documentation ~/work
When you run this command, you’ll see output such as:
[jwallen@giles jwallen]$ smbmount //172.22.1.33/documentation ~/work
Added interface ip=172.22.1.24 bcast=172.22.1.255 nmask=255.255.255.0
session request to Help failed
When you enter your password (your network password, not your Linux logon password), you’ll see your bash prompt (if all goes well). Once you receive your bash prompt, you can check the success of the mount by issuing the ls command on the directory. So,
should report to you the directory/file listing from the machine to which you’re mounting.
Of course, this method has its problems. The first—and most obvious—is that you may be on a larger network that uses DHCP to dole out IP addresses. Because of DHCP, you won’t know the IP addresses of the machines you need to use. This is a problem in pretty much any situation. Even with the Microsoft Network Neighborhood, you cannot discern this information. There is, of course, a way around this obstacle. In order to get the IP address of a machine, you must follow this procedure:
- Find out the NetBIOS name of the machine.
- Ping the name.
- Note the IP reported for the name.
Finding out a NetBIOS name is usually as simple as asking the user or the network administer of the machine for the name. Usually when a machine is used for production (especially when it’s needed by multiple users), the name of the machine will be known to the users. If no one knows the name of the machine and you have physical access to it, you can go to the machine’s Control Panel, click the Networking icon, and choose the Identification tab. Under the Identification tab you’ll see a computer name—this is the name of the machine you want to access.
Once you have the name, it's a simple matter of pinging that name to determine the IP address. Keeping with our example, you know that the machine's name is Help, and the machine you’re using is on the same DHCP network. Run the command
ping -v Help
and you’ll receive the IP address of that machine. Write down that IP address so you can plug it into the smbmount command.
smbclient to the rescue
Of course, this won’t help you if you don't know what shares are available to you. The smbmount command requires the form //hostname/share and will return errors if you attempt to mount without a valid sharename. Now what do you do? You find the sharename! How do you find the sharename? Simple—with the help of Samba! In order to get the available sharenames from the Help machine, you’ll use Samba's smbclient command (which I’ll revisit later) as shown here:
smbclient -L Help
You can substitute the IP address of the machine named Help if you don’t know the NetBIOS name.
Here’s a snippet of output from the above command:
Domain=[TECH] OS=[Windows NT 4.0] Server=[NT LAN Manager 4.0]
Sharename Type Comment
————- —— ———-
NETLOGON Disk Logon server share
BizDev Disk Business Development
ProgramMan Disk Program Management
ADMIN$ Disk Remote Admin
Asset Disk Asset Management Database
Art Disk Art
Operations Disk Operations
IPC$ IPC Remote IPC
Above you see the shares available to your machine. Now you have all the information you need to mount a share to your Linux machine. Using the command
smbmount //help/Art ~/work
you will effectively mount the Art share (from Help) into the /home/USER/work directory. You can now use the Art share as if it were local to your own machine.
One issue currently haunts the smbmount protocol, however. At seemingly random times, you will attempt to view (or list or change into) your smbmounted directory and receive the following error:
ls: work: Input/output error
wherework is the directory you've created for mounting your Samba shares.
There is currently no workaround for this problem. The only way to solve this issue is to su to root and run the umount (or smbumount) command on the work directory, exit out of root, and then remount the directory as the regular user.
Less typing, more work
All of these commands are time-consuming at best and at worst, a headache to remember. There’s a very easy way to simplify these commands—aliases.
To add an alias for this command, you must first insert the IP address and a name for the machine into your /etc/hosts file. This new entry will look like this:
and will allow you to use the hostname help instead of having to type the IP addy. With this inserted, you must open your .bashrc file and add the following line:
alias work="smbmount //help/Art /home/USER/work"
With the above line in place, you will have to exit out of both X and console. Once you log on again, you’ll see that by issuing the command work from a bash prompt, you will effectively have issued the smbmount command you entered into the .bashrc file. It’s also possible to add the command into the /etc/rc.d/rc.local file; however, there are problems with this, and the command is rarely—if ever—successful.
The smbclient command is a multifunctional tool that acts (among other things) as an FTP-like client for Samba. This tool can be quite handy when all else fails. The biggest drawback is when you attempt to access a standard Windows 9x machine. Because the 9x technology was not created for networking, you won’t be able to FTP into that machine. There is, of course, software that will allow you to enable this technology on a 9x machine, but that's another topic for another time.
To use smbclient to read and write to directories from Windows machines, you’ll want to use the command in this way:
and you’ll receive such information as
Domain=[TECH] OS=[Windows NT 4.0] Server=[NT LAN Manager 4.0]
In this command, you must substitute your own information for SERVERNAME and SHARENAME.
One you've entered your password and hit [Enter], you’ll see the smb: \> prompt. At this prompt, you can do a number of groovy things. The primary functions within smbclient are shown in the following list:
What this treatment does is create a multi-functional network connection between a Linux box and a Windows box. With the ability to do most directory commands (ls, dir, cd, mkdir, etc.), the file exchange capability of FTP, and many basic bash commands, smbclient quickly becomes a telnet on steroids.
Of course, using smbclient has its drawbacks. With this application, there are no GUI models to use. When in smbclient mode, you’re stuck with a command-line structure, which many people will not be too thrilled about.
Thesmbclient application has a few other little quirks that might quickly become annoying enough to make you shy away from it. One of the more annoying is the lack of tab completion. Typically, in a Linux bash shell, if you type part of a command or filename and hit the [Tab] key, the shell will auto-complete the word for you. This feature saves a great deal of repetitive typing and guesswork. Once you've become accustomed to this feature, you won’t want to compute without its help. Within smbclient, you no longer have this feature. Instead of tab completion, the [Tab] key functions only as a [Tab] key. So when you try to use [Tab] for word completion, you'll end up with something like this:
.. D 0 Wed Jun 7 16:09:30 2000
ALMOSTE MSSGS D 0 Tue May 9 17:10:58 2000
ALMOSTE PICS D 0 Tue May 9 17:11:05 2000
almostEverest raw pics D 0 Fri May 19 11:19:16 2000
books D 0 Fri Jun 2 09:52:35 2000
everest D 0 Wed May 17 16:09:04 2000
Gartner for CD D 0 Tue Jun 13 10:30:39 2000
jeff'sbookfiles D 0 Wed May 31 17:01:32 2000
TPG content D 0 Tue Jun 20 11:24:47 2000
34726 blocks of size 2097152. 11754 blocks available
smb: \> cd TP
cd \TP\: ERRDOS - ERRbadpath (Directory invalid.)
The point of the above is to show you an attempt at using tab completion and its consequences. Within the mounted share (above) is a directory called TPG content. When trying to cd into that directory, I attempted tab completion, which came out like this:
resulting in the following error.
cd \TP\: ERRDOS - ERRbadpath (Directory invalid.)
Sure, it's not a critical error or a show-stopping problem. It's just annoying enough to convince you that using smbmount is a much better choice.
Printing with smbclient
Thesmbclient application also has a nice ability to access printers by connecting to a print share. Once connected (with the above command), you can use the following commands to print:
- print FILENAME—This command prints the file by submitting it to the remote print queue.
- printmode TYPE1 | TYPE2—This one instructs the print server what the format of the print job will be.
- queue—This command displays the queue for the print share to which you are connected.
- c—This is the argument sent to smbclient that tells it you are printing.
So, the following command will print the print_test.txt file to the print server share that resides on the Help server:
cat print_test.txt | smbclient //Help/print PASSWORD -c "print -"
Note that you must use your networking password in place of PASSWORD.
Debugging/diagnostics with smbclient
The following tools give smbclient the ability to help with debugging a Samba connection (anything in all caps is a user-defined variable):
- B IP_ADDRESS—This sets the broadcast address.
- d DEBUG_LEVEL—This sets how in-depth you want your debugging information to be.
- E—This sends messages to stderr instead of stdout.
- I IP_ADDRESS—This sets the IP address of the server to which you wish to connect.
- i SCOPE—This sets a NetBIOS scope identifier.
- l LOG_FILE—This sends the log messages to the user-defined file.
- N—This suppresses the password prompt.
- n NetBIOS_NAME—This allows you to override the NetBIOS name the daemon will use to advertise itself.
- O SOCKET_OPTIONS—This sets the TCP/IP socket options. This is often used only for performance tuning.
- p PORT_NUMBER—This sets the port number that the client will use to accept requests.
- R RESOLVE_ORDER—This sets the resolve order of the name servers.
- s CONFIGURATION_FILE—This declares the location of the Samba configuration file (smb.conf).
- t TERMINAL_CODE—This sets the terminal code for Asian languages.
- U USERNAME—This sets the username and can be used in conjunction with a password, for example, -U username%password.
- W WORKGROUP—This sets the workgroup name with which you want to connect.
The above list is pretty healthy and will get you through most issues with Samba.
GUI front ends
I’ve finally come to the section I'm quite anxious to discuss. Every once in a while, something very mysterious happens. As I began writing this article, I started thinking there really isn't a good application to offer the readers that’s as user friendly as Microsoft’s Network Neighborhood. That particular application is simple to use and reads the network as easily and efficiently as if it were an intrinsic part of the local machine. Until recently, Linux had no such application.
LinNeighborhood, written by Hans Schmid and Richard Stemmer, is one application that really made my day. This little application not only reads the entire network, it can automatically, and silently, mount these shares into directories created by the application! I'm not sure why it took so long for such an application to appear, but this little gem is making using Linux on a primarily MS network as simple as it gets.
Although LinNeighborhood is better experienced than explained, I'll give it a try. The foundation of the application rests on the smbmount command and does it—in true Windows fashion—with as little user interaction as possible. Once configured, this little beauty can be opened to show the available shares. With a right-click you can choose from a number of options. Among these right-click options is the ability to mount the share and then browse it with a file manager. It is simple and elegant.
The only possible difficulty in this application is the initial configuration. When you’re running on a typical MS network, you’ll need to configure only the following (under the Options | Preferences menu): On the Scan tab, configure Workgroup. Always scan as user (if you have a username and password, you'll need this). On the Programs tab, you may have to switch to a different smbmount version. On the Miscellaneous tab, select Memorize Mounted Shares/Remount On Next Startup. On the Post Mount tab, you may want to configure a different file manager.
The main screen for LinNeighborhood looks like Figure A.
|This is the main screen for LinNeighborhood.|
You'll notice that the main window contains three icons. The first two icons (small computers) represent two machine shares (both NT machines) mounted to Giles (the local machine). Beneath the top two icons is a third icon (a cute penguin head) that represents the entire network (even though it bears the name of the local machine).
One of the beauties of the application is that when you open the program, it will immediately connect to the entire network—and with a double-click on the other icons, it will mount the user-configured shares.
For more information on this application, take a look at Jack Wallen’s review of LinNeighborhood.
It's taken some time, but Linux is finally getting to the point where it can live with ease in the Windows world. Complicated network setup is quickly becoming a thing of the past. In this Daily Drill Down, we’ve tried to move you closer to your dream of working at a Windows-less workstation.
For more information on Samba, visit my Daily Drill Down on “Configuring Basic Samba.”
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.