home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LINUX / HOWTO / mini / dynip.txt < prev    next >
Text File  |  1997-07-07  |  75KB  |  2,040 lines

  1.  
  2. Dynamic-IP-Hacks Mini-HowTo Version 2.1.3
  3.  
  4. Maintained by:         Michael Driscoll <fenris@lightspeed.net>
  5.  
  6. Featuring hacks from: Michael Driscoll <fenris@lightspeed.net>
  7.                       Ryan R. Klems <rklems@primenet.com>
  8.                       Matthew Driver <mdriver@cfmeu.asn.au>
  9.                       Matthew Nuckolls <mnuck@umr.edu>
  10.                       Justin Cragin <beyond@lightspeed.net>
  11.                       Brad Baker <bpb@mlb.cca.rockwell.com>
  12.                       Justin (Gus) Hurwitz <ghurwitz@dyndns.com>
  13.                       Jeremy D. Impson <jdimpson@camelot.syr.edu>
  14.                       Steve Przepiora <gearhead@dreamscape.com>
  15.                       Artur Skawina <skawina@usa.net>
  16.                       Dale Jolliff <taftbbs@e-tex.com>
  17.  
  18. Created        Mon Apr 22 16:24:33 PST 1996
  19. Last Updated   Sun May 25 16:37:41 PDT 1997
  20.  
  21. If you just want to see the hacks skip down to section 2.0.
  22.  
  23. 0.0 Table of Contents
  24. 1.0 Legalities, Definitions, &c.
  25.  1.1 Where to get the latest version of this HowTo
  26.  1.2 Feedback
  27.  1.3 Why this HowTo?
  28.  1.4 What is dynamic IP addressing and why do I have to put up with it?
  29.  1.5 Can you help me set up {pppd,telnetd,sendmail,&c.}?
  30.  1.6 Hey, what about SLIP?
  31.  1.7 Copyright
  32.  1.8 A Warning
  33. 2.0 Intro to Hacks #1-#3
  34. 3.0 Hack #1: Keeping your system up and accessable 24/7 method #1
  35.     by Steve Przepiora <gearhead@dreamscape.com>
  36.  3.1 What you'll need
  37.  3.2 ip-up and ip-down scripts
  38. 4.0 Hack #2: Keeping your system up and accessable 24/7 method #2
  39.     by Michael Driscoll <fenris@lightspeed.net>
  40.  4.1 What you'll need
  41.  4.2 Setting up keepalive.sh
  42.   4.2.1 Using diald instead of a crontab entry
  43. 5.0 Hack #3: Keeping your system up and accessable 24/7 method #3
  44.     by Michael Driscoll <fenris@lightspeed.net>
  45.  5.1 What you'll need
  46.  5.2 Fun with runlevels
  47. 6.0 Hack #4: IP publishing via mail
  48.     by Michael Driscoll <fenris@lightspeed.net>
  49.  6.1 Setting up your ip-up and ip-down
  50.  6.2 How to find out your new IP address from another computer
  51.   6.2.1 Telnetting to a POP3 server
  52. 7.0 Hack #5: Dynamically changing /etc/hosts
  53.     by Michael Driscoll <fenris@lightspeed.net>
  54.  7.1 What you'll need
  55.  7.2 Creating your template host files
  56.  7.3 More fun with ip-up and ip-down!
  57. 8.0 Hacks #6-8: Various hacks 
  58.     by Ryan R. Klems <rklems@primenet.com>
  59.  8.1 mail.c
  60.  8.2 pppdm.c
  61.  8.3 portmsg.c
  62. 9.0 Dynamic DNS entries 
  63. 10.0 Hack #9: Updating your .plan 
  64.      by Matthew Nuckolls <mnuck@umr.edu>
  65. 11.0 Hack #10: A simple procmail recipe for finding your new IP
  66.      by Justin Cragin <beyond@lightspeed.net>
  67. 12.0 Hack #11: Dynamic Home Page via ftp 
  68.      by Michael Driscoll <fenris@lightspeed.net>
  69.  12.1 Why would I want to do this?
  70.  12.2 Setting up your page
  71.  12.2.1 A note on redirects
  72.         by Artur Skawina <skawina@usa.net>
  73.  12.3 Using ncftp to automate page updates
  74.   12.3.1 ncftp versions 1.x.x
  75.   12.3.2 ncftp versions 2.x.x
  76.  12.4 A simple search and replace sed rule
  77. 13.0 Hack #12: Paging yourself with your new IP address
  78.      by Michael Driscoll <fenris@lightspeed.net>
  79.  13.1 The paging program
  80.  13.2 Calling it from ip-up
  81. 14.0 Hack #13: xterm logins through a firewall
  82.      by Brad Baker <bpb@mlb.cca.rockwell.com>
  83. 15.0 Hack #14: Dynamic Home Page via cgi
  84.      by Michael Driscoll <fenris@lightspeed.net>
  85.  15.1 Overview of what we'll try to do
  86.  15.2 The script (dynip.pl)
  87.  15.3 Accessing the CGI when our link goes up
  88. 16.0 Hack #15: Suggestion for rc.*
  89.      by Jeremy D. Impson <jdimpson@camelot.syr.edu>
  90. 17.0 Hack #16: Defeating local and ISP-imposed timeouts with ping
  91.      by Artur Skawina <skawina@usa.net>
  92. 18.0 Hack #17: Using SSI's for dynamic IP publishing
  93.      by Dale Jolliff <taftbbs@e-tex.com>
  94.  
  95. Appendix A: We need more hacks!
  96. Appendix B: CREDITS
  97.  
  98.  
  99. ________
  100. 1.0 Legalities, Definitions, &c.
  101.     by Michael Driscoll <fenris@lightspeed.net>
  102.  
  103. Section 1.1: Where to get the latest version of this HowTo
  104.  
  105. The absolute latest version can always be found at
  106. <URL:http://frob.base.org/howto.txt>.
  107.  
  108. The canonical place to get the HowTo is
  109. <URL:ftp://sunsite.unc.edu/pub/Linux/docs/howto/mini/Dynamic-IP-Hacks>,
  110. though you should use a mirror of the LDP site if you know of any.
  111.  
  112. Section 1.2: Feedback
  113.  
  114. Feedback concerning this mini-HowTo should be addressed to Michael
  115. Driscoll <fenris@lightspeed.net>.
  116.  
  117. Section 1.3: Why this HowTo?
  118.  
  119. The problem is, Linux just isn't as happy as it could be with dynamic IP
  120. addressing.  It's the Unix equivalent of waking every morning to find
  121. that your postal address has changed and that all of your stationary is
  122. out of date.  Unfortunately, ISP's are moving more and more towards this
  123. kind of addressing these days, and anyone who can't shell out more bucks
  124. for a stable IP address is just kinda stuck with this.  The purpose of
  125. this HowTo, therefore, is to make your Linux box happier and more
  126. comfortable with dynamic IP addressing, which in turn should make you a
  127. bit happier and more comfortable.
  128.  
  129. Section 1.4: What is dynamic IP addressing and why do I have to put up
  130. with it?
  131.  
  132. An IP address is a set of four numbers, each from 0 to 255, and each
  133. separated by a dot.  An example would be 198.41.0.8.  Each computer on
  134. the Internet has a unique IP address.  The human-readable addresses that
  135. you probably use, like sunsite.unc.edu and bak2.lightspeed.net, are just
  136. semi-arbitrary names that are translated into their IP addresses by a
  137. DNS server whenever you try to access them.
  138.  
  139. Dynamic IP addressing is something used by an ISP to cut down on the
  140. number of IP addresses that they need to "own".  The way it works is,
  141. when you dial up your ISP, they simply give you the next IP number in
  142. their queue.  This way, they don't need an IP address for every single
  143. customer they have, they just need one for every customer that might be
  144. online at any given time.  Usually an ISP only has about a tenth as many
  145. IP addresses as it has customers, although this of course varies.
  146.  
  147. Why do they do this?  Well, the simple way of explaining it is to say
  148. that there just aren't enough IP addresses in the current scheme.  The
  149. more complex answer is that we have plenty of addresses, it's just that
  150. as more and more of them are used, the routing tables used by the
  151. backbone routers start to look as fragmented as a ten year old MS-DOS
  152. filesystem :-)  By using so many addresses, we lose efficiency in
  153. routing lookups.  The current routing system is expected to blow up
  154. sometime between the years 2000 and 2010.  Hopefully we'll all be
  155. switched over to IPv6 by then anyways, in which case we'll all get our
  156. own stable IP's anyways making this whole HowTo moot :-)
  157.  
  158. Section 1.5: Can you help me set up {pppd,telnetd,sendmail,&c.}?
  159.  
  160. No.  Figure it out yourself.  Builds character :-)
  161.  
  162. Actually, it would be pretty pointless for me to reinvent the wheel by
  163. helping you set these up, as many documents already exist to help you
  164. out.  Start by trying these:
  165.  
  166. the pppd man page
  167. the chat man page
  168. the in.telnetd man page
  169. the inetd man page
  170. the PPP-HOWTO
  171. the NET-2-HOWTO 
  172.    (Available at HowTo sites such as 
  173.     <URL:ftp://sunsite.unc.edu/pub/Linux/docs/howto>)
  174. the NAG
  175.    (Network Administrator's Guide by Olaf Kirch,
  176.     available at fine LDP sites everywhere, such as 
  177.     <URL:ftp://sunsite.unc.edu/pub/Linux/docs/LDP>)
  178.  
  179. Section 1.6: Hey, what about SLIP?
  180.  
  181. To tell you the truth, I didn't write about it here because I don't know
  182. a thing about working with it.
  183.  
  184. Luckily, this shouldn't be too much of a problem as PPP seems to be the
  185. emerging standard, especially for dynamic IP addressing.
  186.  
  187. Sorry if you're that .3% out there that has dynamic IP addressing with
  188. SLIP, but maybe you can glean a bit out of this HowTo and make your own
  189. setup (if you do then be sure to see Appendix A to get your hack included
  190. in this HowTo!)
  191.  
  192. Section 1.7: Copyright
  193.  
  194. Unless otherwise stated, Linux HowTo documents are copyrighted by their
  195. respective authors. Linux HowTo documents may be reproduced and
  196. distributed in whole or in part, in any medium physical or electronic,
  197. as long as this copyright notice is retained on all copies. Commercial
  198. redistribution is allowed and encouraged; however, the author would like
  199. to be notified of any such distributions.
  200.  
  201. All translations, derivative works, or aggregate works incorporating any
  202. Linux HowTo documents must be covered under this copyright notice. That
  203. is, you may not produce a derivative work from a HowTo and impose
  204. additional restrictions on its distribution. Exceptions to these rules
  205. may be granted under certain conditions; please contact the Linux HowTo
  206. coordinator at the address given below.
  207.  
  208. In short, we wish to promote dissemination of this information through
  209. as many channels as possible. However, we do wish to retain copyright on
  210. the HowTo documents, and would like to be notified of any plans to
  211. redistribute the HowTos.
  212.  
  213. If you have questions, please contact Greg Hankins, the Linux HowTo
  214. coordinator, at gregh@sunsite.unc.edu via email.
  215.  
  216. Section 1.8: A Warning
  217.  
  218. This should go without saying, but I should say it anyways to cover
  219. things.
  220.  
  221. I'm not sure all of this is the canonical way to do things, and if
  222. something I've done is just too weird let me know how to fix it.  There
  223. might be security risks in all of this, but I don't know of them yet.
  224. This works on my machine, and I don't think it'll break yours too badly
  225. :-)  Either way, you should take care when doing this stuff and make
  226. sure you understand at least a bit about what this stuff is doing so you
  227. can fix it if it goes haywire.
  228.  
  229. As the name implies, this document is about system *hacks*.  Hacks, by
  230. definition, are a pretty weird way of setting up a system, though
  231. sometimes they may be the only way.  Many times I could have made these
  232. hacks more elegant and crafty, at the cost of simplicity.  I have not
  233. done this, however, because it is my intention that the person who sets
  234. these up on their own machine understand the hacks so that they can
  235. rebuild and recreate them to fit their own specific needs.
  236.  
  237. Also, when reading this Howto keep in mind this quote from the DNS-HOWTO
  238. by Nicolai Langfeldt <janl@math.uio.nl>:
  239.  
  240.     In this document I state flatly a couple of things that are
  241.     not completely true (they are at least half truths though).
  242.     All in the interest of simplification.  Things will probably
  243.     work if you believe what I say.  
  244.  
  245. *****************************
  246. *The good stuff starts here!*
  247. *****************************
  248.  
  249.  
  250. ________
  251. 2.0 Intro to Hacks #1-#3
  252.     by Michael Driscoll <fenris@lightspeed.net>
  253.  
  254. The first three hacks in this howto involve maintaining a constant PPP
  255. connection by restarting pppd when the link goes down.  I thought up the
  256. second of these hacks back when I first ran Linux, but have since moved
  257. onto the third of the hacks, which is a lot more efficient (and,
  258. unfortunately, more difficult to set up).  The first hack was not done
  259. by me, but by Steve Przepiora <gearhead@dreamscape.com>, and is actually
  260. better and more efficient than the second hack (which I thought up), and
  261. is still just as easy to set up.
  262.  
  263. These three hacks work well with Hack #4, which will automatically put
  264. your IP number in an accessible place (your mail spool on your ISP's
  265. POP3 server) whenever your connection goes up.  With these two hacks
  266. working together (automatic reconnect + IP publishing via mail) you
  267. can easily find the dynamic IP of your machine from anywhere on the
  268. network and be able to telnet, ftp, etc. to it.
  269.  
  270. Methods #1 and #2 are the two that are easy to implement, since they
  271. are set up in 'recipe' form and all you have to do is follow directions
  272. and fill in the blanks.  Method #3 is not in 'recipe' form, since it
  273. deals with runlevels and init which vary greatly from distribution to
  274. distribution and which can easily leave your computer in a screwed up
  275. state if they themselves are screwed up.
  276.  
  277. So which method to use?  I suggest #1, it is easy and rather efficient,
  278. or if you are a little more knowledgable, look at #3 to see if you can
  279. figure out how to implement it, since it is the most efficient.  #2 is
  280. only there because it was the first one that I wrote, and is the only
  281. one "tested" so far in this HowTo (the other two are recent additions
  282. which should soon replace #2 altogether).
  283.  
  284. If you don't like either three of the methods, write your own and send
  285. me a line, I'll probably include it if it is something usable by others.
  286.  
  287. Anyways, we now continue with your regularly scheduled hacks:
  288.  
  289.  
  290. ________
  291. 3.0 Hack #1: Keeping your system up and accessible 24/7 method #1
  292.     by Steve Przepiora <gearhead@dreamscape.com>
  293.  
  294. Section 3.1: What you'll need
  295.  
  296. A working PPP setup.
  297.  
  298. Section 3.2: ip-up, ip-down, and other assorted scripts
  299.  
  300. Well, here's how I do it;
  301.  
  302. 1). Fire up vi and make a file called /etc/ppp/ppp-check.dat. Don't put
  303. anything in it just save it.
  304.  
  305. 2). Put this at the top of /usr/sbin/ppp-on :
  306. echo on > /etc/ppp/ppp-check.dat
  307. this will put the word `on' in in /etc/ppp/ppp-check.dat
  308.  
  309. 3). Put this in /usr/sbin/ppp-off:
  310. echo off > /etc/ppp/ppp-check.dat
  311.  
  312. 4). Change the name of your /etc/ppp/ip-down file to
  313. /etc/ppp/ppp-off-final
  314.  
  315. 5). Finally, save this script to /etc/ppp/ip-down:
  316. -----------------------------CUT HERE-------------------------------------
  317.  
  318. #!/bin/sh
  319.  
  320. export LOGGING="yes" ## Change this to no if you dont want to log it.
  321. export LOG_STRING=""
  322. export PPP_CHECK=""
  323.  
  324.  
  325. ##-----------------------Basic setup stuff--------------------------------
  326. PPP_CHECK=`cat /etc/ppp/ppp-check.dat`
  327. ##-------------------------PPP was disconnected log it----------------------
  328. if [ "$LOGGING" = "yes" ]
  329.  then
  330.    logger -i -p local0.notice -t ppp-check  PPP- Disconnected
  331. fi
  332. ##-------------------------Now see how we were called---------------------
  333. if  [ "$PPP_CHECK" = "off" ]
  334.   then
  335.    if [ "$LOGGING" = "yes" ]
  336.      then
  337.      logger -i -p local0.notice -t ppp-check  PPP- Legal disconnect
  338.      logger -i -p local0.notice -t ppp-check  PPP- Turning off NET \
  339. subsystem
  340.      /etc/ppp/ppp-off-final
  341.    fi
  342.    exit
  343. fi
  344. ##----------------------------------------------------------------------
  345. ## If were were just disconnected then  redial
  346. if [ "$LOGGING" = "yes" ]
  347.   then
  348.    logger -i -p local0.notice -t ppp-check  PPP- Illegal disconnect
  349.    logger -i -p local0.notice -t ppp-check  PPP- Attempting to reconnect
  350. fi
  351. /etc/ppp/ppp-off-final
  352. while test -e /var/run/ppp0.pid && test -e /var/lock/LCK..ttyS3
  353.  do
  354.   sleep 1
  355. done
  356.   /usr/sbin/ppp-on
  357.  
  358. ---------------------------------END------------------------------------
  359.  
  360. Steps 2, and 3 will let the script figure out how the connection was
  361. brought down.
  362.  
  363.  
  364. ________
  365. 4.0 Hack #2: Keeping your system up and accessible 24/7 method #2
  366.     by Michael Driscoll <fenris@lightspeed.net>
  367.  
  368. First see the notes about this hack in chapter 2.0.
  369.  
  370. Section 4.1: What you'll need
  371.  
  372. Not too much.  A working PPP setup.  A working cron.
  373.  
  374. Section 4.2: Setting up keepalive.sh
  375.  
  376. (note: This section can be probably be better with diald, see section 4.2.1)
  377.  
  378. cron is a daemon that starts programs at specified times.  You can look
  379. at your crontab by running "crontab -e".  We'll be using crontab to run
  380. a shell program that will keep our PPP connection up.
  381.  
  382. Run "crontab -e" as root and add this line:
  383.  
  384. #*/2 * * * * /etc/ppp/keepalive.sh
  385.  
  386. What this does is call the /etc/ppp/keepalive.sh script every two minutes.
  387. (The '#` comments out the entry so it won't start running the script until
  388.  we are ready).
  389.  
  390. Then put the following script named keepalive.sh in /etc/ppp:
  391. -------------------------------------------------------------------------
  392. #!/bin/sh
  393. if [ -f /var/run/ppp0.pid ] ; then
  394.  ping -c8 -l3 <your nameserver> 2>&1 | grep "0 packets" > /dev/null && \
  395.  { /usr/sbin/ppp-off > /dev/null 2>&1 ; sleep 2 ; /usr/sbin/pppd }
  396. else
  397.  /usr/sbin/pppd
  398. fi
  399. ------------------------------------------------------------------------
  400.  
  401. Now type "chmod 700 /etc/ppp/keepalive.sh" as root to make it an executable
  402. script.
  403.  
  404. /* Hint1: Check those paths!  For pppd and ppp-off insert whatever it is
  405.  *        that you use to start/stop your connection.
  406.  * Hint2: I use your ISP's DNS server because I figure that if that's
  407.  *        down, your net connection is screwed anyways :-)
  408.  * Hint3: Be sure to use your DNS server's numeric IP address, otherwise
  409.  *        ping returns a different message and the "grep" won't work.
  410.  */
  411.  
  412. Now whenever you want your connection to stay up, you can just run
  413. crontab -e and take out that "#" to uncomment the entry...and when you
  414. want your connection to stay down, run crontab -e and put the "#" back
  415. in, then kill your connection with ppp-off or whatever it is that you
  416. use.
  417.  
  418. Section 4.2.1: Using diald instead of a crontab entry 
  419.     by Divya Mahajan <vmahajan@giasdl01.vsnl.net.in>
  420.  
  421. The crontab entry that we just made can also be done (and probably a lot
  422. more elegantly) by other programs, such as diald.  This section
  423. demonstrates how to set up diald for this purpose, should you decide to
  424. take that route instead.  I have left the crontab section in for
  425. reference and because it doesn't require an extra package, but you might
  426. want to try diald out instead.
  427.  
  428. 1: Get the latest diald (should be somewhere near
  429.     <URL:ftp://sunsite.unc.edu/pub/Linux/system/Network/serial/>)
  430.  
  431. 2: Compile the stuff. (Actually you could probably get a precompiled diald
  432.         package too from the Slackware sites)
  433.  
  434. 3: After you have installed diald, you must modify /etc/diald.conf
  435.    Add the following lines to the end:
  436.  
  437. > restrict 06:00 19:00 * * *
  438. > up
  439.    (This would force the link to be up between 6am to 7pm everyday.
  440.     If you want 24hrs + 7days remove the restrict.)
  441. > device /dev/modem
  442.    (Use the correct device;)
  443. > dynamic
  444. > reroute
  445. > connect-timeout 120
  446.    (Modify this if your dialer takes a longer or shorter time to connect
  447.     to your ISP)
  448. > redial-timeout 10
  449.    (Interval between 2 redials)
  450. > defaultroute
  451. > accounting-log /var/adm/diald.log
  452.    (Keep track of how much time you are using)
  453. >connect /path_to_myscript
  454.    (You must use a dialing script so add the above line.  When diald
  455.     calls this script both standard input and standard output are
  456.     redirected to /dev/modem (or whatever you chose above) so ensure
  457.     that your dialer script doesn't print any garbage. I personally use
  458.     "/usr/sbin/dip mydipfile.dip >> /var/adm/dip.log 2>
  459.     /var/adm/dip.err" which logs the dial attempts. Initially you may
  460.     want to run dip with the -v option to debug the dip file, i.e #dip
  461.     -v mydipfile.dip.  Remember to put the line "mode ppp" after you
  462.     have logged in and started your PPP services at the ISP (Use
  463.     dip-3.3.7n-uri). Also store all PPP settings in /etc/ppp/options
  464.     rather than relying on the commandline.  Once your DIP file is
  465.     debugged and ready, its time to roll.  Start up diald
  466.     /usr/sbin/diald, if everything went fine it should start dialing and
  467.     connect you to the ISP.  When PPP shutsdown due to modem HUP, diald
  468.     will automatically retry.  Once you are confident, just put
  469.     /usr/sbin/diald into your /etc/rc.d/rc.local)
  470.  
  471. Now you have a 24hr PPP.
  472.  
  473. diald is also good for a lot of other things, like demand dialing per
  474. port, etc.  Look at the diald homepage
  475. <URL:http://www.dna.lth.se/~erics/diald.html> for some examples.
  476.  
  477.  
  478. ________
  479. 5.0 Hack #3: Keeping your system up and accessable 24/7 method #3
  480.     by Michael Driscoll <fenris@lightspeed.net>
  481.  
  482. First see the notes about this hack in Chapter 2.0.
  483.  
  484. Here's the third method for keeping your PPP connection up, which
  485. is also the one I use.  I wouldn't suggest trying it unless you
  486. actually understand everything that I say in here.  If you don't
  487. understand some of it, here's some resources I'd suggest:
  488.  
  489. man init
  490. man inittab
  491. Essential System Administration, by AEleen Frisch
  492.   (not really necessary, but good for comprehensive knowledge on things
  493.    like runlevels.  I suppose any resource which included a discussion
  494.    on runlevels would be fine.)
  495.  
  496. Section 5.1: What you'll need
  497.  
  498. A working PPP setup.  A working 'init' (I'm pretty sure you have this,
  499. since it is the program which starts all user processes under Unix).
  500.  
  501. Section 5.2: Fun with runlevels
  502.  
  503. Here's how I set this one up.  First, I overhauled my inittab and
  504. rc scripts.  I really hadn't messed with these much since I had
  505. last installed Slackware 3.0, so they looked like the following:
  506.  
  507. 0) Halt
  508. 1) Some kind of broken single-user setup
  509. 2) Empty
  510. 3) Empty
  511. 4) xdm (X)
  512. 5) Normal multi-user (default runlevel)
  513. 6) Reboot
  514.  
  515. I cleaned these out and redid them, so that they were like the following:
  516.  
  517. 0) Halt
  518. 1) Initiate single-user mode
  519. 2) Normal multi-user    # These two will be explained later
  520. 3) Normal multi-user (default runlevel)
  521. 4) Empty
  522. 5) Empty
  523. 6) Reboot
  524.  
  525. Then I put the following line in /etc/inittab:
  526.  
  527. pu:3:respawn:/usr/sbin/pppd -detach
  528.  
  529. What this does is respawn pppd when my system is in runlevel 3, thus
  530. keeping my connection redialing when it dies, and kill the connection
  531. when I change the runlevel to 2.  Then when I want my connection back,
  532. I change the runlevel back to 3 and it is in redial mode again.
  533.  
  534. The -detach on the respawn line keeps pppd from going to background, and
  535. making init think it died (otherwise init will restart pppd a dozen times
  536. and puke).
  537.  
  538. For those interested in my exact setup, I have tarred my /etc/inittab and
  539. /etc/rc.d/* and put them on my web site as
  540. <URL:http://frob.base.org/rc.tar.gz>.
  541.  
  542.  
  543. ________
  544. 6.0 Hack #4: IP Publishing via mail
  545.     by Michael Driscoll <fenris@lightspeed.net>
  546.  
  547. This hack works very well with the previous scripts, because it
  548. automatically publishes your IP when it changes so that you can
  549. find the new address of your machine from anywhere else on the
  550. network after your connection has dropped and restarted.
  551.  
  552. Other hacks which can accomplish this same thing (automatic IP 
  553. publishing) using different means are #6, #8, #9, #10, #11, #12,
  554. and #14 (almost half of them, come to think of it :-).
  555.  
  556. Section 6.1: What you will need
  557.  
  558. Just a working PPP setup, really.  This hack works well with the
  559. automated PPP connection hacks discussed earlier, because it lets you
  560. easily find your machine again after it has automatically reconnected
  561. and had an address change.
  562.  
  563. Section 6.2: Setting up your ip-up and ip-down
  564.  
  565. This hack makes your new IP address available to you from practically
  566. any machine on the net.  To achieve this we use the two scripts
  567. /etc/ppp/ip-up and /etc/ppp/ip-down, which are automatically called by
  568. pppd when your connection goes up or down, respectively.
  569.  
  570. Create a file (if it doesn't already exist) as root called
  571. /etc/ppp/ip-up.  Put this in it:
  572.  
  573. #!/bin/sh 
  574. # $4 is our new ip address passed by pppd 
  575. # /var/run/add will hold our address 
  576. echo $4 > /var/run/add
  577. # mail our address to our ISP's mail server, with the subject "new ip
  578. # address"
  579. mail -s "New IP address" yourname@your_internet_address < /var/run/add
  580.  
  581. Then create /etc/ppp/ip-down and put this in it:
  582.  
  583. #!/bin/sh 
  584. rm /var/run/add
  585.  
  586. Then run "chmod 700 /etc/ppp/ip-up /etc/ppp/ip-down" to make them
  587. executable.
  588.  
  589. Voila!  Now every time pppd is started your address will be mailed to
  590. your ISP's mail server.  We retreive it in the next section.
  591.  
  592. Section 6.3: How to find out your new IP address from another computer
  593.  
  594. Well, this calls for some resourcefulness on your part.  I really can't
  595. walk you through it, as it depends on which kind of machine you're
  596. trying to get it from.  In Windows, you can try to set up an email
  597. program to retrieve mail from your ISP's mail server, and if you're in
  598. Unix see if there's a program called "popclient", or "fetchmail", or
  599. somesuch.  If all else fails, you can always use telnet (see the next
  600. section).
  601.  
  602. Section 6.3.1: Telnetting to a POP3 server
  603.  
  604. This is how I retrieve my IP address, as I am usually showing off when I
  605. do all of this anyways, and it really impresses all of the GUI users I
  606. show it to :-)  Hopefully your ISP uses a POP3 server for mail (most
  607. likely), otherwise you'll just have to figure this out yourself by
  608. looking up the RFC for the protocol you need and figure out how to do it
  609. by telnet.
  610.  
  611. Anyways, first you want to telnet to port 110 of your ISP's mail server.
  612. In Unix you do this with "telnet your.mail.server.net 110", on VAX/VMS
  613. you might need to do "telnet your.mail.server.net/port=110", and in a
  614. Web browser you should use "telnet://your.mail.server.net:110".
  615. Hopefully you can figure it out.
  616.  
  617. Once you are connected, you should see something like this:
  618.  
  619. >Connected to new-ls.lightspeed.net.  
  620. >Escape character is '^]'.  
  621.  
  622. >+OK QUALCOMM Pop server derived from UCB (version 2.1.4-R3) at
  623. >new-ls.lightspeed.net starting.
  624.  
  625. type "user your_username" to login.
  626.  
  627. >+OK Password required for fenris.
  628.  
  629. now type "pass your_password"
  630.  
  631. >+OK fenris has 2 message(s) (3030 octets).
  632.  
  633. type "list" to look at a list of your messages.
  634.  
  635. >+OK 2 messages (3030 octets) 
  636. >1 2400 
  637. >2 630 
  638. >.
  639.  
  640. See that message with size 630?  That's my IP address!  How do I know?
  641. Because it's always that size :-)
  642.  
  643. Now type "retr message_number" to retrieve the message you want.
  644.  
  645. >+OK 630 octets 
  646. >Received: from ulfheim.lightspeed.net (avatar@bak2-pp-ls.lightspeed.net
  647. >[204.216.66.74]) by new-ls.lightspeed.net (8.6.12/8.6.12) with ESMTP id
  648. >TAA12048 for <fenris@lightspeed.net>; Mon, 22 Apr 1996 19:15:37 -0700
  649. >Received: (from avatar@localhost) by ulfheim.lightspeed.net (8.7/8.6.9)
  650. >TAA00594 for fenris@lightspeed.net; Mon, 22 Apr 1996 19:15:29
  651. >Date: Mon, 22 Apr 1996 19:15:29 -0700
  652. >From: Deus In Machina <avatar@ulfheim.lightspeed.net>
  653. >Message-Id: <199604230215.TAA00594@ulfheim.lightspeed.net>
  654. >To: fenris@lightspeed.net
  655. >Subject: New IP address 
  656. >204.216.66.74
  657. >
  658. >.
  659.  
  660. And there it is!  Use "dele message_number" to get rid of it or just
  661. "quit" to leave it there and quit.  Now just telnet to your machine at
  662. that address and have fun!
  663.  
  664. If any of this is just not working for you, then check out RFC 1225,
  665. which describes the POP3 protocol in full detail.
  666.  
  667. By the way, if this part of the hack doesn't work for you because you
  668. have cron automatically downloading your mail, then check out hack #10
  669. which uses procmail to send your new IP address to any email address you
  670. want upon request.
  671.  
  672.  
  673. ________
  674. 7.0 Hack #5: Dynamically changing /etc/hosts
  675.     by Michael Driscoll <fenris@lightspeed.net>
  676.  
  677. As I said before, Linux isn't completely happy with dynamic IP
  678. addressing.  For example, sometimes talkd won't work with kludgy values
  679. in /etc/hosts.  However, the following hack makes up for a lot of that
  680. by changing /etc/hosts according to the IP address we receive when we
  681. call up our ISP.
  682.  
  683. For me this fixed problems with "hostname" and "ntalk".
  684.  
  685. Section 7.1: What you'll need.
  686.  
  687. Nothing but a working PPP setup, really.
  688.  
  689. This hack is really very easy, all you have to do is read the directions
  690. and fill in the blanks.
  691.  
  692. Section 7.2: Creating your template host files
  693.  
  694. ***NOTE***  First, make a backup of /etc/hosts, just in case this 
  695. ***NOTE***  screws up anything.  Just "cp /etc/hosts /etc/hosts.backup"
  696.  
  697. First we'll make our template host files.  The first file will be named
  698. /etc/hosts-down and will contain the following line:
  699.  
  700. ------------------------------------------------------------------------
  701. 127.0.0.1 myhostname.mydomain.net localhost myhostname
  702. ------------------------------------------------------------------------
  703.  
  704. Substitute *your* hostname and domain names in for these values.
  705. This hosts file will be the one used when your PPP connection is
  706. down.
  707.  
  708. The second file will be named /etc/hosts-up and will contain at least 
  709. the following lines: 
  710.  
  711. ------------------------------------------------------------------------
  712. 127.0.0.1 localhost
  713. --IP-- myhostname.mydomain.net myhostname
  714. ------------------------------------------------------------------------
  715.  
  716. Do the substitutions for "myhostname", "mydomain", etc as before (but
  717. do not put anything in for the value "--IP--", that word is an anchor
  718. that we will use in our script to substitute in a new IP address every
  719. time it changes.  If you have no idea what I just said, don't worry, just
  720. know that you *are* supposed to leave that word "--IP--" in there).
  721.  
  722. You can build a bigger /etc/hosts-up file if you want, that can contain
  723. the IP addresses of frequently accessed machines and any nicknames that
  724. you might want to use for them.  For example, my /etc/hosts-up looks like
  725. this:
  726.  
  727. ------------------------------------------------------------------------
  728. 127.0.0.1 localhost
  729. --IP-- ulfheim.lightspeed.net ulfheim
  730. 136.168.201.9 ultrix6.cs.csubak.edu ultrix ultrix6
  731. 128.214.48.39 linux.cs.helsinki.fi linux
  732. 152.2.254.81 sunsite.unc.edu sunsite
  733. 136.168.1.4 academic.csubak.edu academic
  734. 128.214.248.6 nic.funet.fi ftp.funet.fi funet
  735. ------------------------------------------------------------------------
  736.  
  737. Section 7.3: More fun with ip-up and ip-down
  738.  
  739. Add the following lines to /etc/ppp/ip-up:
  740.  
  741. ------------------------------------------------------------------------ 
  742. cat /etc/hosts-up | sed -e s/--IP--/$4/g > /etc/hosts
  743. ------------------------------------------------------------------------ 
  744.  
  745. This puts the hosts-up file through a sed script which substitutes
  746. the word '--IP--' with $4, the variable which contains our
  747. new IP address.
  748.  
  749. Then add the following line to /etc/ppp/ip-down:
  750.  
  751. ------------------------------------------------------------------------ 
  752. cp /etc/hosts-down /etc/hosts
  753. ------------------------------------------------------------------------
  754.  
  755. This copies the hosts-down template to /etc/hosts.
  756.  
  757.  
  758. ________
  759. 8.0 Hacks #6-8: Various hacks
  760.     intro written by Michael Driscoll <fenris@lightspeed.net>
  761.     code straight from Ryan R. Klems <rklems@primenet.com>
  762.  
  763. Here's some C code sent to me from Ryan R. Klems <rklems@primenet.com>.
  764.  
  765. There are three programs, the first, mail.c, is a CGI that scans
  766. through your mail spool for your new IP address as set up by Hack #1.
  767. It then uses the IP address to set up a page containing a link to this
  768. IP address.
  769.  
  770. The second, pppdm.c, can probably take the place of hack #1, as it looks
  771. for a PPP connection, restarts pppd if it is down, and mails your new ip
  772. address to your ISP's mailserver.
  773.  
  774. The third, portmsg.c, sits on a specified port and waits for a telnet
  775. connection.  Upon connection, it will pull grep your mail spool for your
  776. newest IP and output a message containing that.
  777.  
  778. These sources will need a bit of customization, so you probably
  779. shouldn't mess with them unless you know what they are doing.
  780.  
  781. Oh yes, and Ryan has written to tell me that he wouldn't mind helping
  782. you set up the code to meet your needs, as long as you ask nicely :-)
  783.  
  784. Section 8.1: mail.c
  785.  
  786. /*
  787.  * mail.c written by Ryan R. Klems (rklems@primenet.com)
  788.  * Copyright 1996, Author releases this source freely, allowing
  789.  * copying and modification, so long as the original copyright notice
  790.  * is maintained.
  791.  *
  792.  * I request that if you use this file you mail me... Thats all I ask =)
  793.  *
  794.  * A CGI for reading through your mailfile and finding an IP
  795.  * address that you had your computer mail to you.
  796.  *
  797.  * Compiling:
  798.  *    gcc mail.c -o mail.cgi
  799.  *
  800.  * Make sure to 'chmod +s mail.cgi' afterwards...must run with set uid
  801.  * bit on to be able to open the mail file.
  802.  */
  803.  
  804. #include <stdio.h>
  805. #include <string.h>
  806. #define MAILFILE "/var/mail/rklems" /* your mailfile */
  807.  
  808. main(void)
  809. {
  810.   FILE *mail;    /* file pointer for mail file */
  811.   char bob[80], location[80];
  812.  
  813.   printf("Content-type: text/html\n\n");
  814.   printf("<HTML><HEAD><TITLE>IP Address</TITLE></HEAD>\n");
  815.   printf("<BODY><BASEFONT SIZE=4>\n");
  816.   printf("<H1>IP Address</H1>\n");
  817.   strcpy(bob, "42.**");
  818.   if((mail = fopen(MAILFILE, "r")) == NULL)
  819.     printf("Mail file is empty or does not exist.\n");
  820.   else
  821.   {
  822.     /* 
  823.      * loop continues till end of file because you want most recent IP
  824.      * 198.68. is the domain of my ISP, change to yours...
  825.      */
  826.     while(!feof(mail)) /* until reaching EOF, do this */
  827.     {
  828.       fgets(location, 80, mail); /* Grab a line, from mail */
  829.       sscanf(location, "198.68.%s", bob); /* look for domain */
  830.     }
  831.     strcpy(location, "198.68.");
  832.     strcat(location, bob);
  833.     printf("The IP Address of your computer is: %s\n", location);
  834.   }
  835.   printf("</BODY></HTML>\n");
  836. }
  837.  
  838. Section 8.2: pppdm.c
  839.  
  840. /*
  841.  * pppdm.c created by Ryan R. Klems (rklems@primenet.com)
  842.  *   Released freely by the author to use/modify/copy/reditribute
  843.  *   My only request is that if you use it...mail me and let me know =)
  844.  *
  845.  * This program keeps your link dialed up to an ISP and mails you
  846.  * the newest IP address.  Useful for people with Dynamically allocated 
  847.  * IP addresses
  848.  * uses the following files...
  849.  * /root/ip        :   Outputs the IP to this file
  850.  * /root/log       :   If logging is defined
  851.  * /root/pppchat   :   The chat file set up for chat.
  852.  *     My chat file looks like:
  853.  *       ""  ATDT7917777 CONNECT "" "ogin:" "rklems" "assword:" "<password>"
  854.  *  <password> is YOUR password of course (like I'm gonna give you mine ;)
  855.  *  *NOTE* for silent dialing do ATMDT
  856.  *
  857.  *  Compiling...
  858.  *    gcc pppdm.c -o pdm
  859.  *  *NOTE* Don't call it anything like pppdm b/c it looks for pppd
  860.  *  might accidentally kill itself off ;)
  861.  */
  862.  
  863. #include <stdio.h>
  864. #include <stdlib.h>
  865. #include <unistd.h>
  866. #include <signal.h>
  867. #include <time.h>
  868. #define DOLOG
  869.  
  870. void main(void)
  871. {
  872.   FILE *fin,        /* multiuse file pointer */
  873.        *popen();    /* proto of popen() */
  874. #ifdef DOLOG
  875.   FILE *log;        /* log file pointer */
  876. #endif
  877.   char line[80],    /* a line of a file */
  878.        bah[80],        /* just stuff, also used for holding IP addr */
  879.        crap[80],    /* just stuff */
  880.        bob;        /* single char placeholder, not used for anything */
  881.   int j,        /* flag for if a link was found */
  882.       k,        /* flag for if this is a new link */
  883.       pid;        /* pid of pppd process to kill off */
  884. #ifdef DOLOG
  885.   time_t now;        /* thing for time logging */
  886. #endif
  887.  
  888.   for(;;) /* Loop forever... */
  889.   {
  890.     /* look at ifconfig for IP addr */
  891.     if ((fin = popen("ifconfig", "r")) != NULL)
  892.       while(fgets(line, 80, fin) != NULL)
  893.         if(sscanf(line, "ppp0 %s", bah))
  894.         {
  895.           fgets(line, 80, fin);
  896.           sscanf(line, "          inet addr:%15s", bah);
  897.           j=1;
  898.         }
  899.     fclose(fin);
  900.     if (!j) /* no link */
  901.     {
  902.       if((fin = popen("ps -a -x", "r")) == NULL)
  903.       {
  904.         fprintf(stderr, "PPPdm error: cannot open file.\n");
  905.         exit(1);
  906.       }
  907.       /* scan through processes & kill off any zombie pppd processes */
  908.       while(fgets(line, 80, fin) != NULL)
  909.         if (sscanf(line, "%d  ?  %c     %4s pppd%s", &pid, &bob, crap, bah) == 4)
  910.           kill(pid, SIGKILL);
  911.       fclose(fin);
  912.       k=0; /* new dial attempt */
  913.       system("pppd connect 'chat -v -f /root/pppchat'"); /* try again */
  914. #ifdef DOLOG
  915.       now = time(NULL);
  916.       if ((log = fopen("/root/log", "a")) == NULL)
  917.       {
  918.         fprintf(stderr, "Error in opening log file.\n");
  919.         exit(1);
  920.       }
  921.       fprintf(log, "Initiating ppp-link. %s\n", ctime(&now));
  922.       fclose(log);
  923. #endif
  924.       sleep(60); /* wait 1 min and check again */
  925.     }
  926.     if(j && !k) /* first time with new address */
  927.     {
  928.       if ((fin = fopen("/root/ip", "w")) == NULL)
  929.       {
  930.         fprintf(stderr, "Error in opening output file.\n");
  931.         exit(1);
  932.       }
  933.       fprintf(fin, "%s\n", bah); /* write out addr */
  934.       fclose(fin);
  935.       /* mail it to yourself */
  936.       system("mail -s IP joker@your.moma.com < /root/ip");
  937.       k=1;
  938.     }
  939.     else /* take a nap and check again when we wake up */
  940.     {
  941.       j = 0;
  942.       sleep(300); /* wait 5 minutes to check again */
  943.     }
  944.   }
  945. }
  946.  
  947. Section 8.3: portmsg.c
  948.  
  949. /*
  950.  * Portmsg.c written by Ryan R. Klems (rklems@primenet.com)
  951.  * Copyright 1996, Author releases this source freely, allowing
  952.  * copying and modification, so long as the original copyright notice
  953.  * is maintained.
  954.  *
  955.  * I request that if you use this program that you mail me.  Thats
  956.  * all I ask.
  957.  *
  958.  * This program sets up a port on a server to accept telnets.  Upon
  959.  * accepting a telnet, the program outputs a message, and then closes
  960.  * the connection.
  961.  *
  962.  * address of message would be xxx.xxx.xxx.xxx yyyy where the x's
  963.  * s the IP number or IP name, and yyyy is the port number set up
  964.  * within this program.
  965.  *
  966.  * Compiling instructions:
  967.  *    Linux : gcc portmsg_gen.c -o <your_file_name>
  968.  *      SunOS : gcc portmsg_gen.c -lsocket -lnsl -o <your_file_name>
  969.  * ***Note***
  970.  *  I don't have access to any other operating systems, so if you
  971.  *  compile this program on an OS I don't have listed, and use 
  972.  *  compiler options I didn't mention...please email me =)
  973.  */
  974.  
  975. #include <stdlib.h>
  976. #include <stdio.h>
  977. #include <sys/types.h>
  978. #include <sys/socket.h>
  979. #include <sys/uio.h>
  980. #include <errno.h>
  981. #include <netinet/in.h>
  982. #include <strings.h>
  983. #include <netdb.h>
  984. #include <unistd.h>
  985. #define HOSTNAME "ares" /* hostname of computer */
  986. #define PORT 3000    /* tcp port to bind to */
  987. /* #define GETHOSTNAME */ /* uncomment if your server has gethostname() */
  988.  
  989. void get_location(void);    /* proto of my mail reading function */
  990. char location[80];        /* The IP address */
  991.  
  992. void main(void)
  993. {
  994.   struct in_addr host_ip_number;
  995.   struct sockaddr_in host_ip_addr;
  996.   struct sockaddr_in addr;
  997.   char host_name[100];
  998.   struct hostent *hp;
  999.   int s, new_sock;
  1000.   int tmp, length;
  1001.  
  1002.   /* 
  1003.    * The server I wrote this for doesn't have gethostname()
  1004.    * so, I put in a little fix...
  1005.    */
  1006. #ifdef GETHOSTNAME
  1007.   gethostname(host_name, sizeof(host_name));
  1008. #else
  1009.   strcpy(host_name, HOSTNAME); 
  1010. #endif
  1011.   hp = gethostbyname(host_name);
  1012.   bzero((char *)&host_ip_addr, sizeof(host_ip_addr));
  1013.   memcpy((char *)&host_ip_addr.sin_addr, hp->h_addr, hp->h_length);
  1014.   host_ip_addr.sin_family = hp->h_addrtype;
  1015.   host_ip_number = host_ip_addr.sin_addr;
  1016.   host_ip_addr.sin_port = htons(PORT);
  1017.   host_ip_addr.sin_addr.s_addr = INADDR_ANY;
  1018.   /* open a socket s */
  1019.   s = socket(host_ip_addr.sin_family, SOCK_STREAM, 0);
  1020.   if ((int)s==-1)
  1021.   {
  1022.     fprintf(stderr, "Error in opening socket.\n");
  1023.     exit(1);
  1024.   }
  1025.   tmp = 1;
  1026.   if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&tmp, sizeof(tmp))<0)
  1027.   {
  1028.     fprintf(stderr, "Error in setsockopt.\n");
  1029.     exit(1);
  1030.   }
  1031.   /* bind the socket to the server */
  1032.   if (bind(s, (struct sockaddr *)&host_ip_addr, sizeof(host_ip_addr))  == -1)
  1033.   {
  1034.     if(errno == EADDRINUSE)
  1035.     {
  1036.       fprintf(stderr, "Socket already bound!\n");
  1037.       exit(1);
  1038.     }
  1039.     else
  1040.     {
  1041.       fprintf(stderr, "Other error binding socket.\n");
  1042.       exit(1);
  1043.     }
  1044.   }
  1045.   /* tell the server to listen to the port */
  1046.   if (listen(s, 1) == -1)
  1047. /* 1 is the maximum size of the connection queue */
  1048.   {
  1049.     fprintf(stderr, "Error in listen.\n");
  1050.     exit(1);
  1051.   }  
  1052.  while(1) /* just keep looping */
  1053.  {
  1054.    length = sizeof(addr);
  1055.    /*
  1056.     * port has been opened with socket(), bound with bind(), and set
  1057.     * active with listen(), now accept() watches the port for 
  1058.     * connections, it will wait here until it has one...
  1059.     * new_sock is the file descriptor for the new socket
  1060.     */
  1061.    new_sock = accept(s, (struct sockaddr *)&addr, &length);
  1062. /*
  1063.  * The function get_location() and the send()'s are what I did to
  1064.  * suit my particular needs.  Put your own messages in here...
  1065.  */
  1066.    get_location();
  1067.    /* send just sends a string foo of length strlen(foo) with flags */
  1068.    send(new_sock, "Location:\n", 11, 0);
  1069.    send(new_sock, location, strlen(location), 0);
  1070.    close(new_sock); /* Close connection after message printed */
  1071.  }
  1072. }
  1073.  
  1074. void get_location(void)
  1075. {
  1076.   FILE *mail;    /* file pointer for mail file */
  1077.   char a[80];    /* char array for holding ip addr */
  1078.  
  1079. /* 
  1080.  * FYI, this just opens my mail file, looks for a line with
  1081.  * 198.68.(the domain of my ISP), takes the last part, puts
  1082.  * the 198.68. in location, then cats the rest on the end
  1083.  */
  1084.   strcpy(a, "42.**");
  1085.   /* open /var/mail/ryan for read, and check to see there is a file */
  1086.   if((mail = fopen("/var/mail/ryan", "r")) == NULL)
  1087.   {
  1088.     strcpy(location, "Error in obtaining information.\n");
  1089.     return;
  1090.   }
  1091.   else
  1092.   {
  1093.     while(!feof(mail)) /* until reaching EOF, do this */
  1094.     {
  1095.       fgets(location, 80, mail); /* Grab a line, from mail */
  1096.       sscanf(location, "198.68.%s", a); /* look for domain */
  1097.     }
  1098.     strcpy(location, "198.68.");
  1099.     strcat(location, a);
  1100.     /* loops continues till end of file because I want most recent IP */
  1101.   }
  1102. }
  1103.  
  1104.  
  1105. ________
  1106. 9.0 Dynamic DNS entries
  1107.  
  1108. If you're interested in setting up a hack involving Dynamic DNS
  1109. entries (DNS entries that change to point to your computer when
  1110. its IP address changes) then you might want to check out these
  1111. URLs:
  1112.  
  1113. 1) <URL:http://www.cfmeu.asn.au/matthew/virtualip.html>
  1114. Check it out, Matthew got it working and is asking for other people to
  1115. try it to iron out the fine details.  The hack involves already having
  1116. control of a DNS at a static IP.
  1117.  
  1118. 2) <URL:ftp://ietf.org/internet-drafts/draft-ietf-dnsind-dynDNS-11.txt>
  1119. The IETF is the Internet Engineering Task Force, the people who
  1120. basically lay out the future protocols and systems to be used by the
  1121. Internet.  This URL is the IETF's draft for dynamic DNS and should be
  1122. read by anyone who might be thinking of attempting something in this
  1123. direction.
  1124.  
  1125. For those who don't {want to,cant} mess with the details, but just want
  1126. a dynamic name set up without the fuss, check out DynDNS.com.  Quite a
  1127. few people have mailed me regarding their happiness with their service,
  1128. so you might want to check it out.  Their site is at
  1129. <URL:http://www.dyndns.com/>, and you can e-mail Gus Hurwitz
  1130. <info@dyndns.com> for more details.  Another service that has just come
  1131. to my attention is dynip.com, which you can check out at
  1132. <URL:http://www.dynip.com/>.
  1133.  
  1134. [From Artur Skawina <skawina@usa.net>]:
  1135. Another dynamic DNS project exist at <URL:http://www.ml.org/>.  It has
  1136. been operational since january 1997; while it is still in beta tests, it
  1137. works quite well.
  1138.  
  1139. It's very easy to use: you only have to register a hostname once,
  1140. then you can run a special "client" every time your IP changes (There
  1141. exists several linux clients, eg.
  1142. <URL:http://skawina.home.ml.org/mlddc.html>).  For more details on this
  1143. service go to <URL:http://www.ml.org/dyndns/>.
  1144.  
  1145.   [Editors note: If you do use the services of ml.org, please consider
  1146.   making a donation to them in order to help pay them back for the blood,
  1147.   sweat, and tears that they've poured into these projects.  After all,
  1148.   they're still a garage-based organization that do things for the
  1149.   internet community that the InterNIC would normally charge $100 a pop
  1150.   for -- MCD]
  1151.  
  1152.  
  1153. ________
  1154. 10.0 Hack #9: Updating your .plan 
  1155.     by Matthew Nuckolls <mnuck@umr.edu>
  1156.  
  1157. This pair of scripts allows one to put their current IP number in their 
  1158. .plan file on a remote server. I use it so friends and family can see if 
  1159. I'm dialed in, and where to send ytalk requests to.
  1160.  
  1161. Put something like
  1162.  
  1163. /etc/ppp/putip "None, the link is down"
  1164.  
  1165. as the first line in your ppp-off script.
  1166.  
  1167. You need a valid $HOME/.netrc file for putip to work. mine looks like:
  1168.  
  1169. machine rocket
  1170. login mnuck
  1171. password <mypassword>
  1172.  
  1173. and is chmod 600
  1174.  
  1175. -Matthew Nuckolls
  1176.  mnuck@umr.edu
  1177.  
  1178. ip-up:
  1179. ------------------------------------------------------------------------
  1180. #!/bin/sh
  1181. #
  1182. # make sure this is chmod 711, since your password is stored in the clear
  1183.  
  1184. PLANLOC = /home/mnuck/.plan
  1185. REMOTE_USER_NAME = mnuck
  1186. REMOTE_PASSWORD =
  1187. REMOTE_PLANLOC = /afs/umr.edu/users/mnuck/pub/.plan
  1188. REMOTE_SERVER = rocket
  1189.  
  1190. echo "My dynamic IP is: " $4 > /tmp/ip.myip
  1191.  
  1192. cat $PLANLOC /tmp/ip.myip > /tmp/plan
  1193.  
  1194. echo $REMOTE_USER_NAME > /tmp/ip.script
  1195. echo $REMOTE_PASSWORD >> /tmp/ip.script
  1196. echo "put /tmp/plan" $REMOTE_PLANLOC >> /tmp/ip.script
  1197. echo "quit" >> /tmp/ip.script
  1198.  
  1199. ftp $REMOTE_SERVER < /tmp/ip.script &> /dev/null
  1200.  
  1201. rm -f /tmp/ip.myip
  1202. rm -f /tmp/ip.script
  1203. rm -f /tmp/plan
  1204. ------------------------------------------------------------------------
  1205. end ip-up
  1206.  
  1207. putip:
  1208. ------------------------------------------------------------------------
  1209. #!/bin/sh
  1210. #
  1211. # This script relies on a vaild .netrc file
  1212. #  -see ftp man page for details
  1213.  
  1214. PLANLOC = /home/mnuck/.plan
  1215. REMOTE_PLANLOC = /afs/umr.edu/users/mnuck/pub/.plan
  1216. REMOTE_SERVER = rocket
  1217.  
  1218. echo "My dynamic IP is: " $1 > /tmp/ip.myip
  1219.  
  1220. cat $PLANLOC /tmp/ip.myip > /tmp/plan
  1221.  
  1222. echo "put /tmp/plan" $REMOTE_PLANLOC > /tmp/ip.script
  1223. echo "quit" >> /tmp/ip.script
  1224.  
  1225. ftp $REMOTE_SERVER < /tmp/ip.script &> /dev/null
  1226.  
  1227. rm -f /tmp/ip.myip
  1228. rm -f /tmp/ip.script
  1229. rm -f /tmp/plan
  1230. ------------------------------------------------------------------------
  1231. end putip
  1232.  
  1233.  
  1234. ________
  1235. 11.0 Hack #10: A simple procmail recipe for finding your new IP
  1236.     by Justin Cragin <beyond@lightspeed.net>
  1237.     written by Michael Driscoll <fenris@lightspeed.net>
  1238.  
  1239. Here's an easy one, assuming you already have procmail set up.  This
  1240. hack requires that you have a spare shell/email account somewhere on the
  1241. internet where you can temporarily stick an email and is useful when
  1242. you can't use the mailing trick in hack four to get your new IP address
  1243. because you have a cron job regularly downloading your mail.
  1244.  
  1245. host.bogus.net will be the name of the machine where you have the
  1246. shell account to mail your new IP address to.
  1247.  
  1248. In your .procmailrc, simply add the following recipe:
  1249.  
  1250. :0:
  1251. * ^Subject:.*sendmeip
  1252. |mail -s "Your new IP" other.mail.address@host.bogus.net < /var/run/add
  1253.  
  1254. For the email address use a shell account whose mail is not being
  1255. regularly downloaded by a cronjob to your local machine (what, doesn't
  1256. anybody else collect shell accounts?  I only have five so far ;)
  1257.  
  1258. /var/run/add is of course the file containing your IP address that we
  1259. set up in hack one.  If you haven't done that hack, then do something
  1260. like the following in /etc/ppp/ip-up:
  1261.  
  1262. ------------------------------------------------------------------------
  1263. echo $4 > /var/run/add
  1264. ------------------------------------------------------------------------
  1265.  
  1266. Now to use this, just mail your normal mail account from any place on
  1267. the 'net with a subject containing the word "sendmeip", and then telnet
  1268. to the shell account and wait for the cronjob on your machine at home to
  1269. download that mail and automatically send you a reply to the shell
  1270. account with your new IP in it!
  1271.  
  1272. Was that too complex?  Lemme know if I should be clearer on that bit.
  1273.  
  1274.  
  1275. ________
  1276. 12.0 Hack #11: Dynamic Home Page via ftp 
  1277.     by Michael Driscoll <fenris@lightspeed.net>
  1278.  
  1279. This is a simple and easy hack for putting your new IP address on a
  1280. home page on your ISP's http server.  It requires:
  1281.  
  1282. o ncftp (though you could kludge up a script that could use normal ftp) 
  1283. o ftp access to your IPS's web server.
  1284.  
  1285. You can see this hack in action at <URL:http://frob.base.org/>.
  1286.  
  1287. (I also have scripts from <shadow@indirect.com> for another hack that
  1288. accomplishes the same thing that this does, though they use normal ftp
  1289. and are more complex.  You can find these scripts at my home page, as
  1290. <URL:http://frob.base.org/contrib.tar.gz>).
  1291.  
  1292. Note: an alternative to this hack (using CGI) is present in hack #14.
  1293. It is useful for those without ftp access to their ISP's http servers.
  1294.  
  1295. Section 12.1: Why would I want to do this?
  1296.  
  1297. 1: Because it's a neat hack.
  1298. 2: So that all of your friends and family can easily find your new IP
  1299.    address (Ok, maybe that's not a good thing :-)
  1300. 3: So that you can run your own httpd, with your own CGI's (Merely put
  1301.    an http:// pointer to your new IP address which will access your
  1302.    own httpd)
  1303. 4: When have we needed a reason to do something?
  1304.  
  1305. Section 12.2: Setting up your page
  1306.  
  1307. First, you're going to want to write up some HTML to go onto the pointer
  1308. page.  It is beyond the scope of this HowTo to teach you HTML, so you'll
  1309. have to learn that bit yourself.  Try some sites like
  1310. <URL:http://w3.org> and <URL:http://hoohoo.ncsa.uiuc.edu>, they have
  1311. good HTML primers online.  However, when you write the page, in place of
  1312. the address in any pointers to your machine instead put a recognizable
  1313. anchor (I will use the word '--IP--' in this example) so that we can use
  1314. a script to replace that anchor with our IP address.  For example, a
  1315. simple template page would look like this:
  1316.  
  1317. <HTML>
  1318. <HEAD>
  1319. <TITLE>This is Mike Driscoll's Dynamic IP Dynamic Home Page</TITLE>
  1320. </HEAD>
  1321.  
  1322. <BODY>
  1323. <P>Last known IP of ulfheim.lightspeed.net:
  1324. <P><a href=telnet://--IP-->--IP--</a>
  1325. </BODY>
  1326. </HTML>
  1327.  
  1328. Notice that the href and the link name use '--IP--', which the script
  1329. will fill in with our IP address before it uploads the page to the
  1330. server.
  1331.  
  1332. For this example, I'll assume that you've named this template page
  1333. /etc/ppp/index.html.
  1334.  
  1335. Section 12.2.1: A note on redirects
  1336.     by Artur Skawina <skawina@usa.net>
  1337.  
  1338. Instead of only uploading a page with the current IP it's possible to
  1339. upload a page that will directly transfer anybody who loads it into
  1340. their browser to your dynamic host (eg. add a tag like this one to the
  1341. HEAD section of the page:
  1342. <META HTTP-EQUIV="refresh" CONTENT="3; URL=http://--IP--/page"> )
  1343.  
  1344. Section 12.3: Using ncftp to automate page updates.
  1345.  
  1346. Before we do this part we'll have to figure out which version of ncftp
  1347. you are running.  To do this, just start ncftp.
  1348.  
  1349. Here are two examples:
  1350.  
  1351. fenris@ulfheim:~$ ncftp
  1352. 1.9.5 (October 29, 1995)
  1353. ncftp>_
  1354.  
  1355. mdriscol@ultrix6:/usr/stu/mdriscol$ ncftp
  1356. NcFTP 2.0.5 (May 1, 1995), by Mike Gleason, NCEMRSoft.
  1357. NcFTP> _
  1358.  
  1359. Depending on the version number listed when you start ncftp, we will
  1360. do this section in one of two ways.  If the version number is 1.x.x
  1361. (ie. mine is 1.9.5), then use the first method, if the version number
  1362. is 2.x.x (ie. the one in my ultrix account at school is 2.0.5) then
  1363. use the second method.
  1364.  
  1365. Section 12.3.1: ncftp 1.x.x
  1366.  
  1367. Now we'll add some stuff to root's .ncftprc.  In mine, I have the
  1368. following: 
  1369. ----------
  1370. #set auto-binary on
  1371. #set recent-list off
  1372.  
  1373. machine your.isp's.web.server
  1374.         user yourusername
  1375.         password yourpassword
  1376.         macdef init
  1377.         cd /to/your/home/directory
  1378.                 put /tmp/index.html index.html
  1379.                 quit
  1380. ----------
  1381. The auto-binary insures that we'll be in binary mode, the recent-list
  1382. bit stops a .ncrecent file from being created (I just don't like them,
  1383. you can have one if you want), and the machine entry defines my
  1384. password, username, and default actions (you might not need the cd bit,
  1385. at least I don't, since when I ftp to my ISP's server it automatically
  1386. puts me in the right directory).
  1387.  
  1388. Section 12.3.2: ncftp 2.x.x
  1389.     by Tomas Jamate <tvj@miser.umass.edu>
  1390.  
  1391. [Editors note:  I changed Tomas's script a bit before including it in
  1392.  in the HowTo, if I broke it please tell me! -- MCD]
  1393.  
  1394. Here's the setup files I used for getting ncftp v2.x.x to work with 
  1395. Hack #8. Note that ncftp ver 2.x.x keeps all setup files under ~/.ncftp.
  1396. I make no guaruntees, but this setup works for me.  Look at the man
  1397. pages if you want to use other options for ncftp.
  1398.  
  1399. First manually connect to your web service provider using ncftp.
  1400.  
  1401. $ ncftp -u service.provider.com
  1402.  
  1403. The -u means force prompt for user name and password.  Once connected cd
  1404. into your web directory.  This creates a bookmark entry for
  1405. service.provider.com.  (I'm not crazy about the bookmark setup, but hey,
  1406. it works).  Exit ncftp.
  1407.  
  1408. Edit ~/.ncftp/bookmarks.  You'll see the site entry with your username,
  1409. you need to put your password right after the username.  It should look
  1410. something like this:
  1411.  
  1412. NcFTP bookmark-file version: 6
  1413. Number of entries: 1
  1414. service,service.provider.com,Username,Password,,/dir/of/your/web/page,[etc]
  1415.  
  1416. Now create and edit ~/.ncftp/macros, It should look like this:
  1417.  
  1418. macro .open.example
  1419. put /tmp/index.html index.html
  1420. exit
  1421. end
  1422.  
  1423. Now you can automatically upload the index.html with:
  1424.         "ncftp -L example"  -L means go to line mode style
  1425. -or-
  1426.         "ncftp -Lf example"  -the -f means force overwrite of existing
  1427.                               file, for the paranoid ;-)
  1428.  
  1429. Section 12.4: A simple search and replace sed rule
  1430.  
  1431. Now we write the sed rule.  Just put the following in 
  1432. /etc/ppp/ip-up:
  1433.  
  1434. # Begin dynamic IP stuff
  1435. if [ -e /tmp/index.html ]; then
  1436.     mv /tmp/index.html /tmp/index.html-`date +%s`
  1437. fi
  1438. cat /etc/ppp/index.html | sed -e s/--IP--/$4/g > /tmp/index.html
  1439. ncftp your.isps.web.server >/dev/null 2>&1
  1440.  
  1441. First we check for pre-existance of /tmp/index.html.  A cracker could
  1442. be trying to exploit our usage of this to wipe out any file he pleases
  1443. in the filesystem by linking /tmp/index.html to it and waiting until
  1444. the script is run.  If it already exists, the file is harmlessly moved
  1445. out of the way until you look at it, foiling any nefarious plans.
  1446.  
  1447. Then we run our sed script.  This substitutes all occurances of our
  1448. anchor string '--IP--' with our new IP address and dumps the new
  1449. index.html in /tmp.  ncftp is then run to upload the new /tmp/index.html
  1450. which has the current IP address in it.
  1451.  
  1452. Congratulations, it's done, you now have a dynamic home page that you
  1453. can use to point to your home machine!  Have fun customizing it!  Just
  1454. edit /etc/ppp/index.html, and it should be updated the next time you
  1455. dial up your ISP with pppd.
  1456.  
  1457.  
  1458. ________
  1459. 13.0 Hack #12: Paging yourself with your new IP address
  1460.     by Michael Driscoll <fenris@lightspeed.net>
  1461.  
  1462. Here's a neat hack that I don't know anyone will use.  It involves using
  1463. a modem-dialing program to page oneself with one's new IP address.  It
  1464. requires:
  1465.  
  1466. o modem (speed doesn't matter since we're just going to use it to dial
  1467.   [aren't you glad you kept your 300bps modem? :-) ])
  1468. o extra phone line (doesn't need to be dedicated to this, as hopefully
  1469.   you have a modem that will gracefully give up if a voice call is
  1470.   already in progress (I guess that's something you should check, some
  1471.   modems are rather brutal about this)).
  1472. o An ordinary numeric pager
  1473. o A dialing program
  1474.  
  1475. Section 13.1: The paging program
  1476.  
  1477. For this hack you will need some program that has the ability to dial a
  1478. modem from the command line.  For the following examples, I will use the
  1479. program 'modem-stats' by Kenneth J. Hendrickson <kjh@usc.edu>, which can
  1480. be found at
  1481. <URL:ftp://sunsite.unc.edu/pub/Linux/apps/comm/modem-stats.tar.gz>.
  1482.  
  1483. I imagine that other dialing programs can easily be adapted to this
  1484. examples.
  1485.  
  1486. Section 13.2: Calling it from ip-up
  1487.  
  1488. We will put the following lines in /etc/ppp/ip-up:
  1489.  
  1490. #Separate $4 (IP address) into four parts
  1491. part1=`echo $4 | cut -f1 -d.`
  1492. part2=`echo $4 | cut -f2 -d.`
  1493. part3=`echo $4 | cut -f3 -d.`
  1494. part4=`echo $4 | cut -f4 -d.`
  1495. #Run dialing program
  1496. /usr/sbin/modem-stats -c 'atz' /dev/cua2
  1497. /usr/sbin/modem-stats -c 'ats7=15' /dev/cua2
  1498. /usr/sbin/modem-stats \
  1499.  -c 'atdt6384658,,,'${part1}'*'${part2}'*'${part3}'*'${part4} /dev/cua2
  1500.  
  1501. Explanations:
  1502.  
  1503. The atz resets the modem to sane defaults, the ats7=15 sets the time to
  1504. wait for a carrier, the ','s are pauses, and the '*'s are used to
  1505. signify dashes (at least they do on my pager, hopefully they will on
  1506. yours).
  1507.  
  1508. Oh yes, and you might have better results if you put your own pager
  1509. number in place of 638-4658, as that is my pager number :-)  Also,
  1510. replace /dev/cua2 with the device name for your modem.
  1511.  
  1512. Congratulations.  You're done!
  1513.  
  1514.  
  1515. ________
  1516. 14.0 Hack #13: xterm logins through a firewall
  1517.     by Brad Baker <bpb@mlb.cca.rockwell.com>
  1518.  
  1519.  [Editor's note:
  1520.   As the author of this hack notes, this hack may have inherent security
  1521.   problems, such as the possibility of password capture and the breach of
  1522.   your firewall's security inherent in handing out logins to sites outside
  1523.   your localnet.  This hack is being included more for its hack value than
  1524.   its general usefulness.  I wouldn't suggest doing this one unless you
  1525.   are the netadmin for that network or are on very good terms with him or
  1526.   her :-) -- MCD]
  1527.  
  1528. Here's another hack for you to try. This one works, and I'm not sure of
  1529. the security risks yet, but it is amusing.
  1530.  
  1531. It would be nice to be able to get access to my work machine (Sun) from
  1532. home, and vice versa, yet telnet is firewalled at work. Here's a way
  1533. around it.
  1534.  
  1535. For purposes of this explanation I'll give the method for gaining access
  1536. to my work machine from my home Linux machine, with a dial-up PPP
  1537. connection to my ISP and dynamic IP assignment.
  1538.  
  1539. >From home, when I want access to my work machine, I dial-in and fire up
  1540. X, set "xhost +", determine my dynamic IP, and email my dynamic IP to my
  1541. work machine in a mail message with a particular format. On my work
  1542. machine I have a procmail recipe/script setup that parses the body of a
  1543. message whose subject matches a target, say "X-W". If the body of that
  1544. message meets certain requirements then it extracts the IP from the
  1545. message and spawns an xterm with the display directed to my home dynamic
  1546. IP like this:
  1547.  
  1548.      xterm -display my.ip.i.sent:0.0 -e login
  1549.  
  1550. Voila! In about 30 secs to a minute, an xterm login shell appears on my
  1551. home machine! I haven't tried going the other direction yet because my
  1552. home machine isn't on full time, but using the other methods of
  1553. determining the dynamic IP from a remote machine it should work the same
  1554. way.
  1555.  
  1556. I'm quite concerned about security issues though and so I've got it
  1557. disabled until I find out more. When the xterm shows up at home it gives
  1558. a login prompt, and Secure Keyboard can be used to avoid capture of the
  1559. password (I'm not sure how secure this feature is in xterm). Still, I'm
  1560. not real sure at this time what the security features of X are. I'm most
  1561. concerned about my xterm popping up on the wrong IP, or to an IP that I
  1562. had before my line connection got dropped just now, though, most users
  1563. are using Windows and the X access request will not succeed.
  1564.  
  1565. Further required security procedures are to encrypt the IP in the email
  1566. message with PGP or common key encryption and to restrict the dynamic
  1567. IPs to a range, though my ISP won't divulge the range of their dynamic
  1568. IPs to me.
  1569.  
  1570. Here's the .procmailrc rule, script file, and sample email message that
  1571. I used to test it (say 111.222.333.444 is the dynamic ip).
  1572.  
  1573. -- rule set in ~/.procmailrc --
  1574. :
  1575. ^Subject: X-W
  1576. | cat | $HOME/scripts/send_xterm
  1577. -- end --
  1578.  
  1579. -- ~/scripts/send_xterm --
  1580. #!/bin/sh
  1581. XX=`cat $1 | grep "^IP: .*" | sed "s/IP: \(.*\)/\1/"`
  1582. XX=`echo $XX | perl -e '$_ = <>; s/[^0123456789.]//g; print'`
  1583. xterm -display $XX -e login &
  1584. -- end --
  1585.  
  1586. -- sample email message --
  1587. To: bpb@my.machine.com
  1588. Subject: X-W
  1589.  
  1590. IP: 111.222.333.444:0.0
  1591. -- end --
  1592.  
  1593. You can try it out on your own machine by mailing it to yourself
  1594. (after you've setup .procmailrc and send_xterm locally of course).
  1595.  
  1596.  
  1597. ________
  1598. 15.0 Hack #14: Dynamic Home Page via CGI
  1599.     by Michael Driscoll <fenris@lightspeed.net>
  1600.  
  1601. This hack is similar to hack #11, but differs in method.  While hack #11
  1602. involves using ftp access to your ISP's http server to update a page
  1603. containing a link to your new IP, this one accesses a .cgi script on
  1604. your ISP's http server which sets up our new page by itself.
  1605.  
  1606. To use this script you'll have to convince your ISP's sysadmin to put
  1607. this CGI on their http server.  It is not unreasonable for them to charge
  1608. you money to check the script for security since it takes them time and
  1609. is a bit of insurance for the risk of them putting it on the server in
  1610. the first place (although I'll try my best to make this one 'secure').
  1611. For example, my ISP (lightspeed.net) charges $50 per script to check it.
  1612.  
  1613. ***Warning*** Not only is this script new and (largely) untested, but
  1614. I'm writing it at 02:52 PDT to avoid doing my Philosophy mid-term.  If
  1615. you don't know anything about CGI and how to make it secure, then I'd
  1616. suggest you wait until any bugs are worked out before you try foisting
  1617. this upon a poor sysadmin.
  1618.  
  1619. ***Note***
  1620. Well, it's been two months since I wrote that warning and I've heard
  1621. nothing about the security of this CGI, for or against.  Either it
  1622. *is* secure and nobody has let me know, or nobody uses it :-)  Either
  1623. way, I still urge caution.
  1624.  
  1625. Section 15.1: Overview of what we'll try to do.
  1626.  
  1627. Basically, all you'll need to do is take the following script and do
  1628. a little interpretation in filling in the values.
  1629.  
  1630. In the script we'll try to do the following:
  1631.  
  1632. * Parse a newip= parameter, making sure it is a legitimate IP
  1633. * Parse a password= parameter as a *very* loose security to make sure
  1634.   some hoodlums can't easily screw with your script to fill in their own
  1635.   IP values (Note: I know this won't be 100% foolproof but the
  1636.   ramifications if it fail shouldn't be *too* bad, and at least a
  1637.   failure should be non-destructive and there will be server logs noting
  1638.   who the perpitrator is).
  1639. * Check the cgi's $REMOTE_HOST and $REMOTE_ADDR environment variables
  1640.   against your domain name to make sure that it's at least a local
  1641.   request.
  1642. * Finally, if everything checks out, set up the page.
  1643.   
  1644. Section 15.2: The script (dynip.pl)
  1645.  
  1646. #!/usr/bin/perl
  1647. # Written by Michael Driscoll <fenris@lightspeed.net>
  1648. # Suggestions very welcome
  1649.  
  1650. require 5; # Require perl5
  1651. use CGI; # This is the CGI.pm module, available at CPAN sites everywhere like
  1652.          # <URL:ftp://ftp.cdrom.com/pub/perl/CPAN/modules/by-module/CGI>
  1653.  
  1654. # Fill in these values
  1655. $givendomain = "domain.net";               # Put in your ISP's domain name
  1656.                                            # (Actually the last two parts of
  1657.                                            # the domain, although this can
  1658.                                            # be changed below at the split())
  1659. $givenpassword = "potrzebie";              # Fill in a password to use
  1660. $filename = "/some/path/to/my/index.html"; # Get your sysadmin to fill this
  1661.                                            # in (User's page to update).
  1662.                                            # Note to sysadmin: the file
  1663.                                            # indicated will have to give
  1664.                                            # write perms to the userid of
  1665.                                            # httpd, unless you use Apache's
  1666.                                            # suid method or something (not
  1667.                                            # recommended)
  1668.  
  1669. # The followings deal with IP numbers using the scheme aaa.bbb.ccc.ddd
  1670. $higha = "255"; # Fill in the highest range of the aaa part of your
  1671.                 # ISP's IP block.
  1672. $lowa = "0";    # Same for the low range of the aaa part.  Probably the
  1673.                 # same as $higha since most ISP's don't span more than one 
  1674.                 # class A network :-)
  1675. $highb = "255"; # Fill in the highest range for bbb
  1676. $lowb = "0";    # Lowest range for bbb
  1677. $highc = "255"; # You get the point.
  1678. $lowc = "0";    #
  1679. $highd = "255"; #
  1680. $lowd = "0";    #
  1681.  
  1682. # link $query to the cgi.pm module
  1683. $query = new CGI;
  1684.  
  1685. # $newip is our new IP via the newip variable
  1686. $newip = $query->param("newip");
  1687.  
  1688. # $trypassword is the tentative password to check against $givenpassword
  1689. $trypassword = $query->param("password");
  1690.  
  1691. # $hostname is the name of the host this is coming from to check against
  1692. # $givendomain
  1693. $hostname = $query->remote_host;
  1694.  
  1695. # Check the password first of all
  1696. unless ("$trypassword" eq "$givenpassword") {
  1697.     print "Content-type: text/plain\n\n";
  1698.     print "Sorry, wrong password\n";
  1699.     exit;
  1700. }
  1701.  
  1702. # Break up the IP into @IP
  1703. # substitute out any non-numerics except for '.'
  1704. # splice() it to take out anything after the first dotted quad
  1705. # (How did that get there??  Anyways, I'm trying to take as few
  1706. # chances against crackability as possible).
  1707. $newip =~ s/[^\d\.]//g;
  1708. @IP = split /\./, $newip;
  1709. splice(@IP, 4);
  1710.  
  1711. # Check the IP to make sure it's within bounds
  1712. unless (($lowa <= $IP[0]) &&
  1713.     ($lowb <= $IP[1]) &&
  1714.     ($lowc <= $IP[2]) &&
  1715.     ($lowd <= $IP[3]) &&
  1716.     ($higha >= $IP[0]) &&
  1717.     ($highb >= $IP[1]) &&
  1718.     ($highc >= $IP[2]) &&
  1719.     ($highd >= $IP[3])) {
  1720.     print "Content-type: text/plain\n\n";
  1721.     print "Sorry, that IP address doesn't seem to be within bounds\n";
  1722.     exit;
  1723. }
  1724.  
  1725. # Now let's check the hostname
  1726. # Break it up into parts of @hostnamearray
  1727. @hostnamearray = split /\./, $hostname;
  1728. $dompart2 = pop @hostnamearray;
  1729. $dompart1 = pop @hostnamearray;
  1730.  
  1731. # Check it
  1732. unless (("$dompart1"."\.$dompart2" eq "$givendomain") || 
  1733.     ("$hostname" eq "localhost")) {
  1734. # Print an error
  1735.     print "Content-type: text/plain\n\n";
  1736.     print "Sorry, you don't seem to have the right domain\n";
  1737.     exit;
  1738. }
  1739.  
  1740. # Things seem to check out, let's set up the page
  1741. # Make sure to escape out things like #, \, $, @, %, and '
  1742.  
  1743. open(FILE, ">$filename") || 
  1744.     die "dynip.pl cannot open $filename to write: $!";
  1745. flock(FILE, 2);
  1746.  
  1747. # Start html here.  $newip is our new IP address.
  1748. print FILE "<html><head><title>Title etc.</title></head>\n\n";
  1749.  
  1750. print FILE "<body><h1>body here</h1><hr>\n";
  1751. print FILE "<p>blah blah blah\n";
  1752.  
  1753. print FILE "<p>And <a href=telnet://$newip>here</a> is a link to my ";
  1754. print FILE "current IP address.\n";
  1755.  
  1756. print FILE "</body></html>\n";
  1757. flock(FILE, 8);
  1758. close(FILE);
  1759.  
  1760. # Send an ok to our accessing program
  1761. print "Content-type: text/plain\n\n";
  1762.  
  1763. print "Setup was successful\n";
  1764.  
  1765. # End
  1766.  
  1767. Section 15.3: Accessing the CGI when our link goes up
  1768.  
  1769. Now all we do is access it with lynx in our /etc/ppp/ip-up.
  1770. The following line should do it, using the /etc/ppp/ip-up usage of
  1771. $4 for the new IP value: 
  1772.  
  1773. lynx -dump \
  1774. 'http://www.ispserver.net/cgi-bin/dynip.pl?newip=$4&password=potrzebie' \
  1775. >> /etc/ppp/lynxlog
  1776.  
  1777. Put the password you chose in the place of 'potrzebie', of course.  And
  1778. be sure to chmod 700 /etc/ppp/ip-up when you're done, now that it has
  1779. sensitive information in it.
  1780.  
  1781. (BTW, the \'s are just used so that I can fit the command under 80 columns.
  1782. what they do is escape out the newline so that it is considered one command)
  1783.  
  1784. Also be sure to periodically reduce /etc/ppp/lynxlog as it will grow to
  1785. be somewhat big after a while :-)
  1786.  
  1787. There you go...hopefully you're done!
  1788.  
  1789.  
  1790. ________
  1791. 16.0 Hack #15: Suggestion for rc.*
  1792.     by Jeremy D. Impson <jdimpson@camelot.syr.edu>
  1793.     written by Michael Driscoll <fenris@lightspeed.net>
  1794.  
  1795. Previously, this HowTo had various bits of instruction scattered
  1796. throughout which basically copied various parts of /etc/ppp/ip-down in
  1797. the rc.* files, to be run in case of a crash of the system while the PPP
  1798. connection was still up.  Jeremy mailed me with the suggestion of simply
  1799. running the /etc/ppp/ip-down file itself at bootup, instead of tediously
  1800. adding most of it bit by bit to the rc.* files.  Therefore, providing
  1801. that the commands in /etc/ppp/ip-down make sense at bootup and don't
  1802. rely on options passed by pppd (if the latter is true, you can always
  1803. hack up a fake command line), you can simply add the following to the rc
  1804. file of your choice:
  1805.  
  1806. # Run /etc/ppp/ip-down if pppd wasn't shut down cleanly
  1807. if [ -f /var/run/ppp?.pid ]; then
  1808.     /etc/ppp/ip-down
  1809. fi
  1810.  
  1811. Words from Jeremy:  This little trick won't be relevant in every
  1812. situation, but it is in mine, and I thought maybe you'd appreciate it.
  1813.  
  1814. Thanks Jeremy!
  1815.  
  1816.  
  1817. ________
  1818. 17.0 Hack #16: Defeating local and ISP-imposed timeouts with ping
  1819.     by Artur Skawina <skawina@usa.net>
  1820.  
  1821. [Editors note: As Artur notes, this one can be taken too far and
  1822.  can really have an impact on your ISP if they are short on lines
  1823.  or something.  If you do this, and your ISP pointedly asks you
  1824.  to knock it off, then you should seriously consider shelling out
  1825.  the extra money for a dedicated modem on their side or something,
  1826.  which will often get you a dedicated IP anyways, thus making this
  1827.  HowTo moot :-) -- MCD]
  1828.  
  1829. In order to keep a dialup connection open it is sometimes necessary to
  1830. ensure that the link is not idle for long periods of time. Some ISP's
  1831. automatically disconnect a link if there's no traffic, and many modems
  1832. also have the ability to terminate an idle connection. While it is easy
  1833. to alter the local modem settings, it may be impossible to convince your
  1834. ISP to do the same (they may not like people using their resources for
  1835. 24h/day).
  1836.  
  1837. The solution? Add the following line to the ip-up script:
  1838.  
  1839. ping <some_host> -i 180 &
  1840.  
  1841. where <some_host> can be your ISP's main DNS, terminal server etc.
  1842.  
  1843. To change the modems 'Disconnect Inactivity Timer' you have to check the
  1844. modems manual. For example on CirrusLogic chipset based modems it can be
  1845. ATS90=0
  1846.  
  1847.  
  1848. ________
  1849. 18.0 Hack #17: Using SSI's for dynamic IP publishing
  1850.     by Dale Jolliff <taftbbs@e-tex.com>
  1851.  
  1852.  
  1853. This isn't specifically for Linux, but for anything, and you don't have
  1854. to worry about changing anything.  It does require that your ISP allow
  1855. Server Side Includes in your home page.
  1856.  
  1857. Here's what's visible at 
  1858. <URL:http://www.e-tex.com/personal/taftbbs/onlinecheck.shtml>.
  1859. Check it out ... ;>
  1860.  
  1861. You have to know a couple of things about your ISP --
  1862.  The name (or IP#) of the router that you dial into
  1863.  The "gateway" and your own "userid"
  1864.   you can get this in Linux from the "ifconfig" command, it's the
  1865.   IP# there that isn't your machine.... for Windows lusers Trumpet
  1866.   Winsock has a "default gateway", and in Win95, it's in the TCP/IP
  1867.   setup area.
  1868.  
  1869. The critical part of this is that your ISP let you have your own "home 
  1870. page" -- almost required as a "give away" from small providers these 
  1871. days.  If they aren't sharp enough to limit SSI and CGI execution, even 
  1872. better.... mine allows SSI, but not CGI execution (however, if you can 
  1873. do SSI, you can do CGI's.... they just have to be called differently)
  1874.  
  1875. I'm cutting all the extraneous stuff out, and just leaving the critical
  1876. portions to make the thing work here....
  1877.  
  1878. Stick these lines in a SSI page (usually a file that ends in ".shtml"
  1879. for most servers):
  1880.  
  1881. david5.e-tex.com is the router I dial into when I connect to my ISP...
  1882. taftbbs is my userid on thier system...
  1883. this produces a simple one line out put on the page....
  1884.  
  1885. <pre>
  1886. <!--#exec cmd="finger @david5.e-tex.com | grep taftbbs"-->
  1887. </pre>
  1888.  
  1889.  
  1890. <a href="http://<!--#exec cmd="finger @david5.e-tex.com | grep taftbbs | 
  1891. cut -c '66-'"-->">Click here to see if you can see anything!</a>
  1892.  
  1893. The line above will produce a link that will display on the page....
  1894. Finger your router, and look at the output.  The "cut -c '66" part will be 
  1895. dependant upon the make of your router...I have accounts on a couple of 
  1896. providers, and they all seem to use different routers, and each one has
  1897. it's own 'format' when you finger them.
  1898.  
  1899. simple explanation of what happens here:
  1900.  
  1901. <a href="http://   <--open a standard HTML reference anchor...
  1902.  
  1903. <!--#exec cmd=" <-- This is a Server Side Include command.  This 
  1904. means this gets parsed and executed prior to being sent from the server 
  1905. to the client -- the client being your browser.  So, even if you look at the 
  1906. page "source" in your browser, you won't see this, only the output of the 
  1907. command about to be executed on the web server at your ISP.
  1908.  
  1909. finger @david5.e-tex.com | grep taftbbs | cut -c '66-' 
  1910.  
  1911. This is actually what gets executed.  We finger the router, grep for my 
  1912. userid, and cut everything out except the IP#, which on my ISP's router 
  1913. starts in column 66, and is on the end of the line.... may be radically 
  1914. different for other folks.
  1915.  
  1916. "--> 
  1917.  
  1918. make sure you close your SSI command properly, or it won't work...
  1919. DO be careful how you use single and double quotes in your 
  1920. commands... it's easy to get the thing all messed up, play with it a bit.
  1921.  
  1922.  
  1923. ">Click here to see if you can see anything!</a>
  1924.  
  1925. and of course close the link anchor, and stick in your "clickable" text.
  1926.  
  1927. [end of hacks]
  1928.  
  1929.  
  1930. ________
  1931. Appendix A: We need more hacks!
  1932.  
  1933. If you have a dynamic IP hack that you would like to contribute to this
  1934. HowTo, then let me know.  Be warned that if you do so that it will have
  1935. to be covered under the copyright notice in Section 1.7, for reasons of
  1936. CD publishing and whatnot.
  1937.  
  1938. If you {liked this HowTo, didn't like this HowTo, thought this HowTo was
  1939. too confusing, found something in this HowTo that doesn't work and/or is
  1940. just plain wrong, want to send me email, don't want to send me email,
  1941. found a security problem in this HowTo, etc} then please mail me at
  1942. <fenris@lightspeed.net>.  I mean it, I really would appreciate *any*
  1943. feedback on this HowTo, even if you just mailed me to say that you read
  1944. it!
  1945.  
  1946. Really!  Just e-mail me for anything!  I *really do* love getting e-mail!
  1947.  
  1948. Flames will *not* go to /dev/null.  I think if you feel that strongly
  1949. about it, I should listen.
  1950.  
  1951. If you write up a chapter for this HowTo not only will you be helping
  1952. the Linux community, but you will receive full credit for your hack,
  1953. your name will go into the credits at the end of this HowTo, you will be
  1954. acknowledged as a contributor in the beginning of this HowTo, your idea
  1955. will be archived with almost every CD Linux distribution in the world,
  1956. you'll be the envy of all of your peers, etc.
  1957.  
  1958.  
  1959. ________
  1960. Appendix B: CREDITS
  1961.  
  1962. (in order of appearance)
  1963.  
  1964. Michael Driscoll <fenris@lightspeed.net> 
  1965.   is the HowTo maintainer and the author of a few of the hacks.
  1966. Christian G. Warden <cwarden@loop.com>
  1967.   helped debug the keepalive.sh script used in hack two, now the thing
  1968.   will work in (hopefully) all cases, including those when the connection
  1969.   goes down but pppd does not.
  1970. Justin Cragin <beyond@lightspeed.net>
  1971.   gave me the idea for hacks two and four, and then got mad when he
  1972.   found out I stole them.  I also stole the message that my answering
  1973.   machine uses from him, so I guess I owe him this one.  He also
  1974.   recently thought up a nice hack that has become hack ten, so he is now
  1975.   thrice credited.  And he has now helped think of the idea of hack
  1976.   twelve, so he is once again credited.  Furrfu.  Oh well, I guess I
  1977.   owe it to him to make him the new maintainer when I move away to
  1978.   CSM this summer and get my stable IP.
  1979. <shadow@indirect.com> 
  1980.   gave me copies of some real neat scripts of his, see 12.0 for details.
  1981.   I seem to have lost his name, hopefully he'll send it to me again :-)
  1982. Ajit Deshpande <adeshpan@ddt.eng.uc.edu> 
  1983.   wanted to be in the credits.
  1984. Divya Mahajan <vmahajan@giasdl01.vsnl.net.in>
  1985.   sent me the info on diald, which should probably end up replacing the
  1986.   crontab entry in hack two.
  1987. Ryan Klems <rklems@primenet.com>
  1988.   sent me a bunch of his own hacks, see 8.x for details.
  1989. Matthew Driver <mdriver@cfmeu.asn.au>
  1990.   gave me a pointer to his page on dynamic DNS entries.  Check out
  1991.   chapter 9.0 for the URL.
  1992. Matthew Nuckolls <mnuck@umr.edu>
  1993.   gave me hack nine, which updates a .plan containing your new IP address
  1994.   on a remote server via ftp.
  1995. Scott Johnston <sj@odin.iac.net>
  1996.   showed me a better way to set up hack two (took out long and confusing
  1997.   crontab entry and put it in script called by cron instead), and gave me
  1998.   various other pointers.
  1999. Brad Baker <bpb@mlb.cca.rockwell.com>
  2000.   wrote the really neat hack thirteen.
  2001. Christian Hardmeier <101502.1521@CompuServe.COM>
  2002.   got me motivated to write hack fourteen.
  2003. Justin (Gus) Hurwitz <hurwitz@dyndns.com>
  2004.   let me know about his new service providing dynamic DNS entries for
  2005.   hosts with dynamic IP.  Check out the pointer in chapter 9.0.
  2006. Tomas Jamate <tvj@miser.umass.edu>
  2007.   reminded me about ncftp 2.x.x and was even kind enough to send me his
  2008.   own script for inclusion in the HowTo (thanks Tomas!).  He goes to
  2009.   umass but unfortunately doesn't listen to the Pixies.  Oh well.
  2010. Jeremy D. Impson <jdimpson@camelot.syr.edu>
  2011.   wrote me the suggestion that turned into hack fifteen.
  2012. Steve Przepiora <gearhead@dreamscape.com>
  2013.   wrote hack one, and really got the ball rolling for me with the
  2014.   reorganization of this howto that made v2.0.0.
  2015. Whit Blauvelt <whit@transpect.com>
  2016.   gets many thanks for giving me lots of feedback on the HowTo, and
  2017.   especially for fixing hack one.
  2018. Paul C. Richard <pcricha@cs.concordia.ca>
  2019.   also gets thanks for his help fixing up hack one.
  2020. Per Sjoholm <Soile.Kaasila@sth.frontec.se>
  2021.   kept me up to date with the new location of the diald home page.
  2022. Bill Duncan <bduncan@beachnet.org>
  2023.   also notified me that the diald home page had moved.
  2024. Artur Skawina <skawina@usa.net>
  2025.   did a lot, such as hack sixteen, additional material for chapter nine,
  2026.   and the new section 12.2.1.
  2027. Scott Dier - DiEMaN <sdier@isd.net>
  2028.   also told me about ML.org's dyndns project.
  2029. Dale Jolliff <taftbbs@e-tex.com>
  2030.   sent in hack seventeen.
  2031. Bryan Rittmeyer <bryanr@flash.net>
  2032.   debugged hack two and mentioned ML.org's dyndns project.
  2033. Marek Kubita <kubitovi@mbox.lantanet.cz>
  2034.   fixed a gaping hole in hack thirteen.
  2035. --
  2036. Michael Driscoll <fenris@lightspeed.net>
  2037.  
  2038.  
  2039.