TLWIR 49: RELIABLY Printing From GNU/Linux to a Windows 7 Printer

by Rex Djere on November 22, 2012 · 4 comments

in TLWIR

Post image for TLWIR 49: RELIABLY Printing From GNU/Linux to a Windows 7 Printer

Summary
I try to use GNU/Linux solutions whenever I can. However, one exception to this rule is the printing process in my home. I have one printer, and it is connected to my Windows 7 machine. As GNU/Linux becomes more popular in homes and businesses, it is becoming more common to see mixed GNU/Linux-Windows environments. Printing from GNU/Linux to Windows 7 using Samba did NOT work for me reliably, but I have found a method that works 100% of the time. In The Linux Week in Review 49, I’ll explain how to set up a 100% dependable GNU/Linux-to-Windows 7 printing network. The video at the end of TLWIR 49 demonstrates the entire setup process from beginning to end.

Overview
There are three basic steps to setting up GNU/Linux-to-Windows 7 printing:

  • 1. Make your Windows 7 computer a fixed target instead of a moving one. (***Update***: a very astute reader pointed out to me a more flexible alternative to setting up the Windows 7 machine at a static IP address. I tested it, and it works great! I’ll explain the alternative in section 1a).
  • 1a. Leave your Windows 7 PC and router set up to use DHCP, but reserve a permanent IP address for the Win 7 PC in the router’s DHCP settings.
  • 2. Set up your Windows 7 machine for printing.
  • 3. Set up your GNU/Linux machine for printing.

1. Making Your Windows 7 Machine a Fixed Target
(If you already know how to set up Windows 7 to use a static IP address, you can skip ahead to section 2.)
Your home LAN probably uses DHCP to assign IP addresses to clients on the network. The Dynamic Host Configuration Protocol is used to dynamically configure network clients and assign them IP addresses, as shown in Figure 1 below.

Figure 1

Figure 1 (Image created using LibreOffice Draw)

This is great for dynamically configuring your network when you are constantly turning devices on and off. However, I have found that a DHCP-configured Windows 7 computer is not very reliable when you print from a GNU/Linux computer to a printer connected to that Windows 7 PC. When I tried this setup using Samba, one of the most popular methods of talking to Windows machines from GNU/Linux, I could print one day, only to have it fail the next day. So what method worked reliably for me? It turns out that the first step was to set up the Windows 7 PC with a static IP address instead of a dynamically allocated one. Making the Windows 7 PC a fixed target instead of a moving one made my GNU/Linux-to-Windows printing much more reliable.

The instructions that I am about to provide assume that you have a network similar to the diagram in Figure 1 above. You’ll have to modify the instructions to match your exact configuration. You may have to use different IP addresses, depending on the manufacturer of your router. Let’s assume that your router acts as your network’s DHCP server. Let’s also assume that your network has the same IP addresses as Figure 1. The basic goal is to get your Windows 7 PC to be statically assigned an address such as 192.168.1.2. The rest of your network will continue to operate via DHCP. In our sample case, the DHCP devices will be bumped from the 192.168.1.2 to 192.168.1.5 address space to the 192.168.1.3 to 192.168.1.6 address space. Think of it as shifting all of your neighbors over one house to make room for the new house that you are building. You will stay in your new house all of the time, but your 4 neighbors will randomly switch houses.

The first thing that you’ll do is to log on to your router. I would also turn off all of the DHCP client devices to prevent network confusion as you change network settings. You’ll set the router’s DHCP up to start assigning IP addresses one IP address higher than it currently does. For example, if it currently starts at 192.168.1.2, you’ll change it to start at 192.168.1.3. 192.168.1.2 will now be available for exclusive use by your Windows 7 machine.

The next thing that you’ll do is to set up your Windows 7 machine to statically use 192.168.1.2. To do this, you’ll go to Control Panel, and navigate to a menu box similar to Figure 2 below. I won’t go through all of the steps to navigate there here, but I will demonstrate it in the video at the end of this article. Once the settings are complete, you should reboot your Windows 7 computer, and you can turn your DHCP client devices back on.

Figure 2: Windows 7 Static IP Setup

Finally, you’ll perform a test to see if the process worked. You’ll check your Windows 7 computer’s IP address is to make sure that it is correct. To do so, you’ll go to Start, and type cmd in the search programs and files box. Open cmd.exe. This will bring up a command line. Type ipconfig and hit Enter. You should get a result similar to Figure 3 below. You will probably have to scroll to see your IP address (you want the ipv4 address).

Figure 3: Verifying Static IP address Setup in Windows 7

Pages: 1 2 3 4 5

{ 4 comments }

Tim Chase November 23, 2012 at 1:01 pm

Rather than tell Windows to use a static IP address, I’d leave the Windows machine using DHCP and then configure your router to hand out a static IP address to your Windows box based on its MAC (hardware) address. You can find the MAC in the output of the “ipconfig” command in the line reading “Physical Address” where it should look something like “XX-XX-XX-XX-XX-XX”. This allows your Windows PC to move uneventfully to other networks and still get the right internal IP address when it reconnects to your home network. It also prevents your router from accidentally handing out the Windows box’s IP address to other DHCP clients.

Rex Djere November 23, 2012 at 3:05 pm

@Tim Chase, thank you very much for the astute comment. I’ve updated the article to reflect your recommendation.

SW November 23, 2012 at 3:30 pm

If you don’t want to use nmap, you could also use netcat (nc) for this. Chances are good it will already be installed.

nc -zv
You will see this if it succeeded:
Connection to port [tcp/http] succeeded!
and this if it failed:
nc: connect to port (tcp) failed: Connection refused

SW November 23, 2012 at 3:31 pm

You can ignore my first comment as the site didn’t like angle brackets. Here’s the correct one.

If you don’t want to use nmap, you could also use netcat (nc) for this. Chances are good it will already be installed.

nc -zv (host) (port)
You will see this if it succeeded:
Connection to (host) (port) port [tcp/http] succeeded!
and this if it failed:
nc: connect to (host) (port) port (tcp) failed: Connection refused

Previous post:

Next post: