APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
->
-> Printing to a remote printer with a dynamic address


How can I print to a remote PC that does not have a static IP address?






This is a fairly common problem: you have a PC at home and you make some sort of connection over the internet to your server, but your application needs to print to your PC. That would be easier if your PC had a fixed, constant IP address, but your connection is dynamic so it changes.

By the way: this article assumes a Unix/Linux server. It doesn't talk about Windows apps, though often the solution is exactly the same concept.

There are many, many ways to solve this problem. So many, in fact. that I'll probably miss one or two in this write up. If I do miss something, do let me know: it may help someone else down the line.

Some of these methods involve configuring an LPD printer on your remote Windows machine. That's easy to do with Windows 2000 or XP and Windows LPD clients are easily found for other versions. A Google search for "Windows LPD Server" will turn up hundreds of options, free and low cost. The concept here is that you define an lpd printer on the server, and that its address will be looked up by name.. somewhere. Some of these even help you do that automatically, usually by way of something running on the server that their software can contact. Some things you might want to look at in this area include:



Other ways to do this are to use Windows SMB style printing. That will require Visionfs, Samba or FacetWin on the server and some help for those to "find" the connecting PC. Personally, I like the LPD solutions better, but in some situations the SMB way can be easy enough.

Some Solutions

  • Dynamic DNS services
    Register a domain name and subscribe to a dynamic dns service. There are dozens of them: Google search for "dynamic dns service" and pick what you like. A little client runs on your Windows machine and updates the service whenever your IP changes. When the server goes looking for "xyz.com", the dynamic dns service tells it what your address is now.


    This approach can work, though it also has its problems. The issue, especially with the free and inexpensive services, is that they may be slow or inaccurate in updating, which will kill you dead for printing.

  • Write your own DNS update client/server
    This really isn't hard to do in Perl. The idea is to have a little client on the Windows PC that probably runs at boot, figures out its IP address, and contacts a matching server app on your server to inform the system of your new address. Keep in mind that thw Windows side doesn't need to try to figure out its address (and may not even know it if it's going through a firewall); when it contacts the server, the server will be able to tell where it came from. You could even do this using a "port knocking" technique (see What is "port knocking"?) where you'd log the attempt to access some port and then scan the logs to pick up the address.


    See Dynamic DNS Services for examples of writing your own update scripts.

  • Use "local printing"
    Local printing comes from old dumb terminals that, with the proper escape codes, would then send all data received out another port until a "stop local print" code was received. See http://aplawrence.com/Unixart/terminals.html for more on that. Windows terminal emulators can often be set to respond to the same codes and send the data to your Windows printer.


    Your application may make this a reasonable choice, or it may be more difficult than you may like. Most terminal emulators (see What are some terminal emulators I can use from windows? and http://www.anzio.com/support/whitepapers/printguide.htm) support this.

  • Use a VPN connection
    Appliance VPN's are very inexpensive; for example see http://aplawrence.com/Reviews/rf550vpn.html. Most of these can happily work with the remote side using DHCP, and can also provide DHCP to the network (which may be only 1 machine if remote). With a VPN, your address will (or can be) fixed as far as the other side of the VPN is concerned: you are always 192.168.4.2 for example. See http://aplawrence.com/Basics/vpn.html if you don't understand that yet.

  • Manual methods
    If you have root access to the machine you are using, just do a "su" and edit /etc/hosts. You can get your address from "who -mux", from netstat -a and all sorts of other ways: see How do I find out what IP address a user logged in from?

    .
  • Scripting it automatically.
    Have something run from the user's .profile that finds out the address and updates /etc/hosts (or DNS).


    The problem here is that you need root access to update /etc/hosts. There are three ways to solve that:

    • You might use sudo: see http://aplawrence.com/Basics/sudo.html or (OSR5) "asroot" or (Unixware) "tfadmin and adminuser"
    • Make a setuid binary that runs the script.
    • Use a named pipe: the unprivileged client writes to the pipe, a root owned process reads from it.


    Some sample scripts for that are shown below.

    Sample Scripts

    # remotelpsetup, run at boot (run in background!)
    /etc/fuser -k /dev/remoteprinters
    /bin/rm -f /dev/remoteprinters
    /etc/mknod /dev/remoteprinters p
    while true
    do
    exec < /dev/remoteprinters
    /usr/local/bin/updateremotelp
    done
     
    


    # pickprinter, called from user's .profile
    set  `/bin/who -mxu`
    MYTTY=$2
    MYADD=$6
    MYALREADY=`grep $MYADD /etc/hosts| sed 's/      .*//'`
    if [ "$MYALREADY" ] 
    then
    MYADD=$MYALREADY
    fi
    test -z "$MYADD" && exit 0
    case $MYTTY in 
      ttyp[0-9]*) :;;
      *) exit 0;
    esac
    case $MYADD in 
     -) exit 0;;
     192.168.*) exit 0;;
     localhost) exit 0;;
     *) : ;; 
    esac
    while true
    do
    echo "Please select the printer you wish to use
    
    1. Tiffany
    2. Marilyn
    3. Amelia
    4. Susan
    Q. Quit
    "
    PRINTER=""
    read choice
    case $choice in
            1) PRINTER=TIFFANY;;
            2) PRINTER=MARILYN;;
            3) PRINTER=AMELIA;;
            4) PRINTER=SUSAN;;
            [qQ]) exit 0;;
    esac
    if test -z "$PRINTER"
    then
    :
    else
    echo "CookieM $PRINTER $MYADD" > /dev/remoteprinters
    echo "Printer $PRINTER set for $MYADD" 
    exit 0;
    fi
    done
     
    


    # updateremote
    read key printer address
    case $key in
     CookieM) : ;;
     *) exit 0;;
    esac
    /bin/grep -v $address /etc/hosts > /tmp/hosts.$$
    /bin/grep -v $printer //tmp/hosts.$$ > /tmp/hosts2.$$
    echo "$address\t$printer" >> /tmp/hosts2.$$
    cp /tmp/hosts2.$$ /etc/hosts
    /bin/rm /tmp/hosts.$$
     
    





    If this page was useful to you, please help others find it:  





    3 comments




    More Articles by - Find me on Google+



    Click here to add your comments
    - no registration needed!




    Sun Mar 18 16:34:16 2007: 2920   anonymous


    Thank you. Very useful.



    Tue Jul 15 05:29:47 2008: 4421   AnupKatariya


    Thank you for the knowledge you shared with All of us.




    Don't miss responses! Subscribe to Comments by RSS or by Email

    Click here to add your comments


    If you want a picture to show with your comment, go get a Gravatar

    Kerio Samepage


    Have you tried Searching this site?

    Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

    This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

    Publishing your articles here

    Jump to Comments



    Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

    I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

    Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

    We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

pavatar.jpg

This post tagged:

       - Code
       - Linux
       - MacOSX
       - Networking
       - Printing
       - Remote Access
       - SCO_OSR5
       - Unix















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals



Click and enter your name and phone number to call me about Kerio® products right now (Flash required)