LINK="#3366FF" VLINK="#A000A0">



[ Table Of Contents ][ Answer Guy Current Index ] greetings   1   2   3   4   5   6   7   8 [ Index of Past Answers ]


(?) The Answer Gang (!)


By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and the Gang, the Editors of Linux Gazette... and You!
Send questions (or interesting answers) to tag@lists.linuxgazette.net

There is no guarantee that your questions here will ever be answered. Readers at confidential sites must provide permission to publish. However, you can be published anonymously - just let us know!


(?) How to let the world find your Linux Server when using DHCP

From Jason Bailey

Answered By


Abstract

Many of us have broadband connecting our Linux machines to the Internet and would like to play around with our own webservers, but for a variety of reasons are unable to get a static address. This article should help you with publishing your Linux server's current IP address to an ISP's web server.


Introduction

I've wanted to have my own web server for many years. Partly because I'm a geek who has a need to do things just because I can. But more importantly, I've wanted to do it because many ISPs don't let you play with cool stuff like databases, perl, php, python, etc.
So what's the big deal? You say. Set up a Linux box and you are good to go. Well, it is that easy if you don 't care about sharing this website with anybody else. My ISP won't give me a static IP for my cable modem. So I thought, what if I could create a webpage on my ISP's web server which would point to my web server? The game was afoot! I began searching google.com and pestering the members of my LUG (Linux Users Group) for ideas.
One of the most helpful articles I found was written for Linux Gazette several years ago by Henry H Lu. I have followed a lot of his basic ideas, though I have reduced the number of files used and I've standardized on shell script as opposed to using both shell script and perl. Henry does have a nice example of how to make the FTP portion work with Geocities if you happen to be using them.


Automating FTP

The file transfer protocol client interaction can be a bit difficult to script if you are having to wait for prompts for username and password. One way around these prompts is to use the .netrc file. The layout for the file would be as follows:
machine www.MyISP.com login JoeUser password Top$ecret
Please note that you must change this file to read/write owner only when you create it. For more information about the .netrc file and its uses do a man netrc at you command prompt.


HTML File Template

I found that the easiest way to do this was create an HTML file which has a placeholder everywhere I want the IP address to go. I chose "~~~IP~~~" to be my placeholder since it stands out and I'd never have it appear anywhere else in my document. The following is an example of what you might use.

See attached up.html_source.txt


The Shell Script

I'll first show the script and then explain what each part does.

See attached dhcp-myip.sh.txt

First, we find the IP address using ifconfig on our WAN device (depending on your setup it may be eth0, ppp0, etc) and parse out all information we do not want. If you are not sure if you are using eth0, eth1, ppp0, ppp1, etc you can type ifconfig to see which devices you are currently running and look for the
one with a valid Internet IP address.
We save the IP address in the variable MyIP and in an ASCII file. Then we com pare a file that contains the current IP address and one that contains the IP address which we had the last
time the script ran. If these two
addresses are the same we are done. If they are different, we use take our up .html_source file and replace ~~~IP~~~ with our current IP and store the results in up.html. Next we FTP th e file to our ISP. Finally, we copy our current IP to "MyIP.then" for future referen ce.
Make sure you do a chmod +x to the script after you save it.


Repeating the Process

After you have tested out the script, you'll probably want to have it run eve ry five to fifteen minutes. You can easily to this by adding a cron job. It is important that you run the cron job as the user w ho has the files in his home directory and has the FTP server information in his .netrc file.


Conclusion

If you want to make your web server, which is on a dynamic IP address, easily
found by your friends and other. This script can
make it as easy for them to find your home server as going to http://www.MyIS P.com/~JoeUser/ip.html. The scripts are easy to reconfigure to suite your needs. My next step is to write a PHP script tha t will ping my IP address and if it gets a response it would send you to the server. If no response was received, it wou ld give a page that explains that the site it down. I hope you find this as useful and fun as I did.
Jason Bailey

When I'm not at work doing system admin stuff, at school pursuing my Computer Science degree, at a Susitna Linux Users Group meeting or off doing freelance computer work, you can find me hanging out in beautiful Palmer, Alaska with my wife and kids.


This page edited and maintained by the Editors of Linux Gazette Copyright © 2001
Published in issue 71 of Linux Gazette October 2001
HTML script maintained by Heather Stern of Starshine Technical Services, http://www.starshine.org/


[ Table Of Contents ][ Answer Guy Current Index ] greetings   1   2   3   4   5   6   7   8 [ Index of Past Answers ]