SDB:Printing via SMB (Samba) Share or Windows Share

Şuraya atla: kullan, ara


Version: 9.0

Situation

You want to print to a printer that is connected to an SMB host or a printer that can be addressed over the network via an SMB host.

Background Information

An SMB host is a host that can be addressed by means of the SMB protocol. Normally, this is a Windows host. However, it can also be a Linux host running the "Samba" service. To address the printer by means of the SMB protocol, the SMB host must have a "share" for this printer.

The printer share is identified by unique "names" in the network:

  • Host name of the SMB host (always needed)
  • Name of the shares (always needed)
  • Name of the "workgroup" (not always needed)

Additionally, a user name and a password may be required to access the printer share.

These names, which are required by the SMB protocol, are managed by the NetBIOS name service, which must be clearly distinguished from the usual DNS name service in TCP/IP networks. Although the SMB protocol is based on the TCP/IP protocol, the SMB protocol uses NetBIOS instead of DNS as name service. The NetBIOS host name can be different from the DNS host name, but usually the NetBIOS host name and the DNS host name are identical. However, the DNS domain does not make any sense in the NetBIOS name space. Accordingly, the fully qualified DNS host name consisting of the DNS host name and DNS domain does not make any sense in the NetBIOS name space.

When a printer is addressed by a Linux host by means of the SMB protocol, this is merely for data transfer. The SMB host does not convert the print data from the applications (e.g., PostScript) to printer-specific data. Therefore, the filtering must take place on the Linux host, which requires a complete print system on the Linux host. A queue with filtering must be set up on the Linux host. After the data is filtered, the queue sends the printer-specific data to the SMB share. The SMB share receives the printer-specific data and forwards it to the printer associated with the share.

Procedure

Required Packages:

  • The package "samba-client" is needed for sending data (printer data) to an SMB share.
  • Additionally, a complete print system (CUPS or LPRng and lpdfilter) is needed.

Determining the NetBIOS Names:

The command "nmbstatus" lists the workgroups available in the network and the respective NetBIOS host names, for example:

user@host> nmbstatus
Found 123 hosts. Collecting additional information. Please wait.
...
WORKGROUP    TUX-NET
MEMBERS      GEEKO     TUX
...

Determining the Available Shares:

The command "smbclient -L NetBIOS-hostname -N" lists available shares on the SMB host with the specified NetBIOS host names, for example:

 user@host> smbclient -L GEEKO -N
 ...
 Sharename      Type      Comment
 ---------      ----      -------
 LPT1           Printer
 ...
 

If necessary, add "-U username%password" to list shares that require a user name and a password for access:

smbclient -L GEEKO -U USER%PASSWORD -N

Testing the Printer:

The following command sends one carriage-return character "\r" to the printer via the SMB share. Nothing is printed, but the printer may eject an empty page.

echo -en "\r" | smbclient "//NetBIOS-hostname/share" -c "print -" -N

Insert the respective NetBIOS host name and the share. If necessary, a workgroup and a user name and password can be added to the smbclient command:

smbclient "//NetBIOS-hostname/share" "password" -c "print -" -N -U "username" -W "workgroup"

If the printer is able to print ASCII text directly (without filtering), the echo command can be replaced with the command

echo -en "\rHello\r\f"

to print the word "Hello".

The entire command sequence could appear as follows:

echo -en "\rHello\r\f" | smbclient "//NetBIOS-hostname/share" "password" -c "print -" -N -U "username" -W "workgroup"

Insert the correct NetBIOS host name and share. If necessary, insert the password, user name, and workgroup.

The Correct DeviceURI for CUPS:

In CUPS, the DeviceURI in /etc/cups/printers.conf determines how the data should be sent to the printer (or to the SMB share). The DeviceURI must be as specified in "man smbspool":

 · smb://server/printer
 · smb://workgroup/server/printer
 · smb://username:password@server/printer
 · smb://username:password@workgroup/server/printer

"server" refers to the NetBIOS host name and "printer" refers to the share. The values for "server" and "printer" (and for "username", "password", and "workgroup", if necessary) must correspond to those used in the above command for the NetBIOS host name and share (and for the password, user name, and workgroup, if necessary).

Configuration with YaST in SUSE LINUX 9.0:

The configuration in YaST causes problems, especially if a workgroup is entered.

The safest way is to enter the values for

  • Server (NetBIOS host name)
  • Printer (share)

and, if necessary, for

  • Workgroup
  • User name
  • Password

in the YaST dialog in same way as used in the above smbclient command, provided that the smbclient command worked correctly.

Then continue without testing the SMB access. In the final stage, print the YaST test page to check if all components (i.e., the SMB access and the filtering) work correctly.

Explanation of the current problems in YaST:

  1. Confusion of NetBIOS names and DNS names or IP address:

In the above entry, YaST does not set the NetBIOS host name as "Server". Rather, it wrongly uses the DNS host name and the DNS domain when starting the automatic detection. The NetBIOS host name usually corresponds to the DNS host name, but the DNS domain does not make any sense for SMB.

  1. A faulty test script for testing the SMB access when using a workgroup:

In this case, an error message such as the following appears in YaST:

There was a problem.
Your network access is not properly configured ...
... Check the host name of the print server ...
even though all entries are correct.

The test script /usr/lib/YaST2/bin/test_remote_smb can easily be corrected by replacing the lines

[ -z "$WORKGROUP" ] || HOST="$WORKGROUP/$HOST"
echo -en "\r" | smbclient "//$HOST/$QUEUE" "$PASSWORD" ...

with the following lines:

echo -e "\nTesting $QUEUE on $WORKGROUP $HOST:"
echo -en "\r" | smbclient "//$HOST/$QUEUE" "$PASSWORD" -c "print -" -N -U "$USER" -W "$WORKGROUP"

<keyword>print,printer,yast,yast2,smb,samba,share,workgroup,windows</keyword>