1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> Setting up dynamic IP web server via PPP connection </TITLE>
<META NAME="GENERATOR" CONTENT="Mozilla/3.0Gold (X11; I; Linux 2.0.0 i486) [Netscape]">
</HEAD>
<BODY>
<H4>"Linux Gazette...<I>making Linux just a little more fun!</I>
"</H4>
<P> <HR> <P>
<!--===================================================================-->
<center><H1>Setting up dynamic IP web server via PPP connection</H1></center>
<center><H4>By Henry H. Lu, <A HREF="mailto:honglu@rt66.com">honglu@rt66.com</A>,
<A HREF="http://www.tc.umn.edu/nlhome/m508/luxxx012/">http://www.tc.umn.edu/nlhome/m508/luxxx012/</A>
</H4> </center>
<center><H5>Copyright (c) 1996</H5></center>
<center> <H5>Published in Issue 10 of the Linux Gazette</H5></center>
<P>Have you been thinking of seting up a reachable web server at your home
PC in addition to your permenent page at ISP? There are obvious reasons
to do this: You can show off your home linux box to the world; you do not
need to use other messy method (email) to know your current IP in order
to login remotely; finally, it is fun! </P>
<P>First, You need to have ppp connection and httpd working and a PERMANENT
web page before trying the following dynamic IP solution. </P>
<H3>Description of files: </H3>
<P><B>web_up: </B>shell script I run to update webpage at permenet site
with new IP whenever connection is up. </P>
<P><B>web_down:</B> shell script I run before shutting down the link, to
inform others of the shutdown </P>
<P><B>update_uppage:</B> perl scripts to creat up.html page with updated
IP address on the fly, called by web_up. </P>
<P><B>up.html_source:</B> fixed part of up.html </P>
<P><B>down.html:</B> web page used when link is down. </P>
<P><B>/etc/add, /etc/last_add:</B> files where I put IP address. </P>
<P><B>ip-down, ip-up:</B> files executed when ppp link is disconnected
or connected. they are used to update the /etc/add files here. </P>
<H3>Now lets look at scripts web_up: </H3>
<PRE>------------------------------------------------------------------
#!/bin/sh
#check new IP
new_ip()
{
if [ -f /etc/add ]; then
if [ -f /etc/last_add ]; then
if /usr/bin/diff /etc/add /etc/last_add >/dev/null ; then
exit 1
else
return 0
fi
else
return 0
fi
else
exit 1
fi
}
#check whether maroon is connected
try_connect()
{
if ping -c4 -l3 128.101.118.21 2>&1 | grep "0 packets" > /dev/null
then
return 1
else
return 0
fi
}
if try_connect
then
touch /var/run/maroon_connected
else
rm -f /var/run/maroon_connected
fi
# ftp to update page
if [ -f /var/run/maroon_connected ] && new_ip
then
# update_uppage is perl scripts, exit status is opposite of shell
if ( ! /home/honglu/public_html/update_uppage )
then
cd /home/honglu/public_html
if echo "put up.html /nlhome/m508/luxxx012/dynamic.html" \
| /usr/bin/ftp maroon
then
rm -f /etc/last_add
cp /etc/add /etc/last_add
exit 0
else
exit 1
fi
fi
else
exit 1
fi
-----------------------------------------------------------------
</PRE>
<P>Now let's look at web_up in detail. </P>
<P>Function <B>new_ip()</B> is used to check whether we have new IP and
whether the new IP is different from the last one. /etc/ppp/ip-up and /etc/ppp/ip-down
update IP adress in files /etc/add and /etc/last_add so that we can compare
files "add" with "last_add" to tell whether we need
to update page. </P>
<P>Function <B>try_connect()</B> is used to test whether the perment web
site is reachable. </P>
<P>Next is fun part, I used automatic feature of <B>ftp</B> to update webpage.
In order to make it work, you have to set file ~/.netrc correctly, type
"man ftp" for more information. </P>
<P><B>update_uppage</B> is straitforward perl scripts to parse and creat
up.html by using new IP from /etc/add file. </P>
<P>Final part is to update /etc/add /etc/last_add to reflect correct status
IP address. </P>
<P>You can put "web_up" in your crontab entry ( or ip-up, or
keapalive.sh) to let it execute automatically whenever your PC is connected.</P>
<H3>Web_down is a similar page, main difference is in ftp part: </H3>
<PRE>-----------------------------------------------------
......
......
# ftp to send down.html page
if [ -f /var/run/maroon_connected ]
then
cd /home/honglu/public_html
if echo "put down.html /nlhome/m508/luxxx012/dynamic.html" \
| /usr/bin/ftp maroon
then
rm -f /etc/last_add
else
exit 1
fi
else
exit 1
fi
----------------------------------------------------
</PRE>
<P>Instead of ftp up.html as web_up did, web_down put down.html to permenent
web site to inform the delink of page. </P>
<P>web_down should be run before you shut down the machine. I created a
scripts called "shut" to shutdown machine: </P>
<PRE>-----------------------------------------
#!/bin/sh
if web_down
then
shutdown -h now
else
echo "can not web_down"
exit 1
fi
-----------------------------------------
</PRE>
<P>For more detail check out my home page for source code: </P>
<P><A HREF="http://www.tc.umn.edu/nlhome/g625/luxxx024/">http://www.tc.umn.edu/nlhome/g625/luxxx024/</A></P>
<P>Henry H Lu
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./lg_toc10.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../lg_frontpage.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="plugin.gimp.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="xaos.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
</BODY>
</HTML>
|