old-www/LDP/LG/issue71/tag/6.html

276 lines
11 KiB
HTML

<!--startcut ======================================================= -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<META NAME="generator" CONTENT="lgazmail v1.3F.f">
<TITLE>The Answer Gang 71: How to let the world find your Linux Server when using DHCP</TITLE>
</HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000"
LINK="#3366FF" VLINK="#A000A0">
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<P> <hr>
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</p>
<P> <hr>
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
<p align="center">
<table width="100%" border="0"><tr>
<td align="right" valign="center"
><IMG ALT="" SRC="../../gx/navbar/left.jpg"
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="middle" border="0"
><A HREF="..//"
><IMG SRC="../../gx/navbar/toc.jpg" align="middle"
ALT="[ Table Of Contents ]" border="0"></A
><A HREF="../lg_answer71.html"
><IMG SRC="../../gx/dennis/answertoc.jpg" align="middle"
ALT="[ Answer Guy Current Index ]" border="0"></A></td>
<td align="center" valign="center"><A HREF="../lg_answer71.html#greeting"><img align="middle"
src="../../gx/dennis/smily.gif" alt="greetings" border="0"></A> &nbsp;
<A HREF="1.html">1</A> &nbsp;
<A HREF="2.html">2</A> &nbsp;
<A HREF="3.html">3</A> &nbsp;
<A HREF="4.html">4</A> &nbsp;
<A HREF="5.html">5</A> &nbsp;
<A HREF="6.html">6</A> &nbsp;
<A HREF="7.html">7</A> &nbsp;
<A HREF="8.html">8</A>
</td>
<td align="left" valign="center"><A HREF="../../tag/kb.html"
><IMG SRC="../../gx/dennis/answerpast.jpg" align="middle"
ALT="[ Index of Past Answers ]" border="0"></A
><IMG ALT="" SRC="../../gx/navbar/right.jpg" align="middle"
WIDTH="14" HEIGHT="45" BORDER="0"></td></tr></table>
</p>
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<P> <hr> <P>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<center>
<H1><A NAME="answer">
<img src="../../gx/dennis/qbubble.gif" alt="(?)"
border="0" align="middle">
<font color="#B03060">The Answer Gang</font>
<img src="../../gx/dennis/bbubble.gif" alt="(!)"
border="0" align="middle">
</A></H1>
<BR>
<H4>By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and the Gang,
the Editors of Linux Gazette...
and You!
<br>Send questions (or interesting answers) to
<a href="mailto:linux-questions-only@ssc.com">linux-questions-only@ssc.com</a>
</H4>
<p><em><font color="#990000">There is no guarantee that your questions
here will <b>ever</b> be answered. Readers at confidential sites
must provide permission to publish. However, you can be published
anonymously - just let us know!
</font></em></p>
</center>
<p><hr><p>
<!-- endcut ======================================================= -->
<!-- begin 6 -->
<H3 align="left"><img src="../../gx/dennis/qbubble.gif"
height="50" width="60" alt="(?) " border="0"
>How to let the world find your Linux Server when using DHCP</H3>
<p><strong>From Jason Bailey
</strong></p>
<p align="right"><strong>Answered By
<p></strong></p>
<h4 align="center"><br> Abstract
</h4>
<BLOCKQUOTE>
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.
</BLOCKQUOTE>
<h4 align="center"><br> Introduction
</h4>
<BLOCKQUOTE>
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.
</BLOCKQUOTE>
<BLOCKQUOTE>
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.
</BLOCKQUOTE>
<BLOCKQUOTE>
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.
</BLOCKQUOTE>
<h4 align="center"><br> Automating FTP
</h4>
<BLOCKQUOTE>
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:
</BLOCKQUOTE>
<BLOCKQUOTE><BLOCKQuote>
machine www.MyISP.com login JoeUser password Top$ecret
</BLOCKQuote></BLOCKQUOTE>
<BLOCKQUOTE>
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.
</BLOCKQUOTE>
<h4 align="center"><br> HTML File Template
</h4>
<BLOCKQUOTE>
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.
</BLOCKQUOTE>
<p align="center">See attached <tt><a href="../misc/tag/up.html_source.txt">up.html_source.txt</a></tt></p>
<h4 align="center"><br> The Shell Script
</h4>
<BLOCKQUOTE>
I'll first show the script and then explain what each part does.
</BLOCKQUOTE>
<p align="center">See attached <tt><a href="../misc/tag/dhcp-myip.sh.txt">dhcp-myip.sh.txt</a></tt></p>
<BLOCKQUOTE>
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
</BLOCKQUOTE>
<BLOCKQUOTE>
one with a valid Internet IP address.
</BLOCKQUOTE>
<BLOCKQUOTE>
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
</BLOCKQUOTE>
<BLOCKQUOTE><BLOCKQUOTE><CODE>
time the script ran. If these two
</CODE></BLOCKQUOTE></BLOCKQUOTE>
<BLOCKQUOTE>
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.
</BLOCKQUOTE>
<BLOCKQUOTE>
Make sure you do a chmod +x to the script after you save it.
</BLOCKQUOTE>
<h4 align="center"><br> Repeating the Process
</h4>
<BLOCKQUOTE>
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.
</BLOCKQUOTE>
<h4 align="center"><br> Conclusion
</h4>
<BLOCKQUOTE>
If you want to make your web server, which is on a dynamic IP address, easily
</BLOCKQUOTE>
<BLOCKQUOTE>
found by your friends and other. This script can
</BLOCKQUOTE>
<BLOCKQUOTE>
make it as easy for them to find your home server as going to <A HREF="http://www.MyIS"
>http://www.MyIS</A>
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.
</BLOCKQUOTE>
<BLOCKQUOTE>
Jason Bailey
</BLOCKQUOTE>
<HR width="10%" align="left"><BLOCKQUOTE>
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.
</BLOCKQUOTE>
<!-- end 6 -->
<!--startcut ======================================================= -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href="http://www.linuxgazette.com/copying.html"
>Copyright &copy;</a> 2001
<BR>Published in issue 71 of <I>Linux Gazette</I> October 2001</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<P> <hr>
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
<p align="center">
<table width="100%" border="0"><tr>
<td align="right" valign="center"
><IMG ALT="" SRC="../../gx/navbar/left.jpg"
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="middle" border="0"
><A HREF="..//"
><IMG SRC="../../gx/navbar/toc.jpg" align="middle"
ALT="[ Table Of Contents ]" border="0"></A
><A HREF="../lg_answer71.html"
><IMG SRC="../../gx/dennis/answertoc.jpg" align="middle"
ALT="[ Answer Guy Current Index ]" border="0"></A></td>
<td align="center" valign="center"><A HREF="../lg_answer71.html#greeting"><img align="middle"
src="../../gx/dennis/smily.gif" alt="greetings" border="0"></A> &nbsp;
<A HREF="1.html">1</A> &nbsp;
<A HREF="2.html">2</A> &nbsp;
<A HREF="3.html">3</A> &nbsp;
<A HREF="4.html">4</A> &nbsp;
<A HREF="5.html">5</A> &nbsp;
<A HREF="6.html">6</A> &nbsp;
<A HREF="7.html">7</A> &nbsp;
<A HREF="8.html">8</A>
</td>
<td align="left" valign="center"><A HREF="../../tag/kb.html"
><IMG SRC="../../gx/dennis/answerpast.jpg" align="middle"
ALT="[ Index of Past Answers ]" border="0"></A
><IMG ALT="" SRC="../../gx/navbar/right.jpg" align="middle"
WIDTH="14" HEIGHT="45" BORDER="0"></td></tr></table>
</p>
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<P> <hr>
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</p>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
</BODY></HTML>
<!--endcut ========================================================= -->