home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 8 / CDACTUAL8.iso / docs / mini / dynamic- < prev    next >
Encoding:
Text File  |  1996-07-11  |  17.3 KB  |  468 lines

  1. Dynamic-IP-Hacks Mini-HOWTO  moderated by Michael Driscoll
  2.                                         <fenris@lightspeed.net>
  3.  
  4.  
  5. Version 0.4 Created 4/22.  Last updated 6/1.
  6.  
  7. 0.0 Table of Contents
  8. 1.0 Legalities, Definitions, &c.
  9.  1.1 Where to get the latest version of this HOWTO
  10.  1.2 Feedback
  11.  1.3 Why this HOWTO?
  12.  1.4 What is dynamic IP addressing and why do I have to put up with it?
  13.  1.5 Can you help me set up {pppd,telnetd,sendmail,&c.}?
  14.  1.6 Hey, what about SLIP?
  15.  1.7 Copyright
  16.  1.8 A Warning
  17. 2.0 Hack #1: Keeping your system up and accessible 24/7
  18.  2.1 What you'll need
  19.  2.2 Setting up crontab
  20.   2.2.1 Explanation of the crontab entry
  21.  2.3 ip-up and ip-down
  22.   2.3.1 Setting up your ip-up and ip-down
  23.  2.4 How to find out your new IP address
  24.   2.4.1 Telnetting to a POP3 server
  25. 3.0 Hack #2: Dynamically changing /etc/hosts
  26.  3.1 What you'll need
  27.  3.2 More fun with ip-up and ip-down!
  28. 4.0 We need more hacks!
  29. 5.0 CREDITS
  30.  
  31. 1.0 Legalities, Definitions, &c.
  32.  
  33. Section 1.2: Where to get the latest version of this HOWTO
  34.  
  35. The latest version of the Dynamic-IP-Hacks HOWTO can be found at
  36. sunsite.unc.edu under the directory /pub/Linux/docs/howto/mini.
  37.  
  38. Section 1.3: Feedback
  39.  
  40. Any feedback concerning this HOWTO should be addressed to Michael
  41. Driscoll <fenris@lightspeed.net>.
  42.  
  43. Section 1.1: Why this HOWTO?
  44.  
  45. The problem is, Linux just isn't as happy as it could be with dynamic IP
  46. addressing.  It's the Unix equivalent of waking every morning to find
  47. that your postal address has changed and that all of your stationary is
  48. out of date.  Unfortunately, ISP's are moving more and more towards this
  49. kind of addressing these days, and anyone who can't shell out more bucks
  50. for a stable IP address is just kinda stuck with this.  The purpose of
  51. this HOWTO, therefore, is to make your Linux box happier and more
  52. comfortable with dynamic IP addressing, which in turn should make you a
  53. bit happier and more comfortable.
  54.  
  55. Section 1.2: What is dynamic IP addressing and why do I have to put up
  56. with it?
  57.  
  58. First of all, I suppose I should explain just what an IP address is :)
  59. An IP address is a set of four numbers, each from 0 to 255, separated by
  60. a dot.  An example would be 10.127.96.1.  Each computer on the Internet
  61. has a unique IP address.  The human-readable addresses that you probably
  62. use, like sunsite.unc.edu and bak2.lightspeed.net, are just
  63. semi-arbitrary names that are translated into their IP addresses by a
  64. DNS server whenever you try to access them.
  65.  
  66. Dynamic IP addressing is something used by an ISP to cut down on the
  67. number of IP addresses that they need to "own".  The way it works is,
  68. when you dial up your ISP, they simply give you the next IP number in
  69. their queue.  This way, they don't need an IP address for every single
  70. customer they have, they just need one for every customer that might be
  71. online at any given time.  Usually this is only about a tenth of their
  72. customer base at any given time.
  73.  
  74. Why do they do this?  Well, there just aren't enough IP addresses out
  75. there to give to every single customer of every single ISP on the
  76. planet, especially now that every computer user and his dog is getting
  77. connected.  Besides, it doesn't affect Windows users at all, so why
  78. should they care? :) Therefore, it seems that unless you want to shell
  79. out some more money for a stable IP you should just try to make do with
  80. what you have.
  81.  
  82. Section 1.3: Can you help me set up {pppd,telnetd,sendmail,&c.}?
  83.  
  84. No.  Figure it out yourself.  Builds character :)
  85.  
  86. Actually, it would be pretty pointless for me to reinvent the wheel by
  87. helping you set these up, as many documents already exist to help you
  88. out with these.  Start by trying these:
  89.  
  90. man pppd 
  91. man chat 
  92. man in.telnetd 
  93. man inetd 
  94. PPP-HOWTO 
  95. NET-2-HOWTO 
  96. NAG
  97.   (Network Administrator's Guide by Olaf Kirch,
  98.    available at fine LDP sites everywhere!)
  99.  
  100. Section 1.4: Hey, what about SLIP?
  101.  
  102. To tell you the truth, I didn't write about it here because I don't know
  103. it.
  104.  
  105. Luckily, this shouldn't be too much of a problem as PPP seems to be the
  106. emerging standard, especially for dynamic IP addressing.
  107.  
  108. Sorry if you're that 2% out there that has dynamic IP addressing with
  109. SLIP, but maybe you can glean a bit out of this HOWTO and make your own
  110. setup (if you do then be sure to see Section 4 to get your hack included
  111. in this HOWTO!)
  112.  
  113. Section 1.5: Copyright
  114.  
  115. Unless otherwise stated, Linux HOWTO documents are copyrighted by their
  116. respective authors. Linux HOWTO documents may be reproduced and
  117. distributed in whole or in part, in any medium physical or electronic,
  118. as long as this copyright notice is retained on all copies. Commercial
  119. redistribution is allowed and encouraged; however, the author would like
  120. to be notified of any such distributions.
  121.  
  122. All translations, derivative works, or aggregate works incorporating any
  123. Linux HOWTO documents must be covered under this copyright notice. That
  124. is, you may not produce a derivative work from a HOWTO and impose
  125. additional restrictions on its distribution. Exceptions to these rules
  126. may be granted under certain conditions; please contact the Linux HOWTO
  127. coordinator at the address given below.
  128.  
  129. In short, we wish to promote dissemination of this information through
  130. as many channels as possible. However, we do wish to retain copyright on
  131. the HOWTO documents, and would like to be notified of any plans to
  132. redistribute the HOWTOs.
  133.  
  134. If you have questions, please contact Greg Hankins, the Linux HOWTO
  135. coordinator, at gregh@sunsite.unc.edu via email.
  136.  
  137. Section 1.6: A Warning
  138.  
  139. This should go without saying, but I should say it anyways to cover 
  140. things.
  141.  
  142. I'm not sure all of this is the canonical way to do things, and if
  143. something I've done is just too weird let me know how to fix it.  There
  144. might be security risks in all of this, but I don't know of them yet.
  145. This works on my machine, and I don't think it'll break yours too badly
  146. :)  Either way, you should take care when doing this stuff and make sure
  147. you understand at least a bit about what this stuff is doing so you can
  148. fix it if it goes haywire.
  149.  
  150. Happy now? :)
  151.  
  152. *****************************
  153. *The good stuff starts here!*
  154. *****************************
  155.  
  156. 2.0 Hack #1: Keeping your system up and accessible 24/7
  157.  
  158. This hack involves a problem I have with my ISP.  For reasons unknown to
  159. me (or apparently even to them) they like to hang up on me every five
  160. minutes to five hours.  This was a problem for me because I wanted to be
  161. able to show off by telnetting to my Linux box from the computer in math
  162. class :) While it was easy enough to use a cron job to check the network
  163. status every few minutes and start pppd if it wasn't up, since my ISP
  164. uses dynamic addressing I couldn't find my address after this happened
  165. (except by luck).  This hack keeps your PPP session up and puts your new
  166. IP number in an accessible place.
  167.  
  168. Section 2.1: What you'll need
  169.  
  170. Not too much.  A working PPP setup.  A working sendmail (actually it
  171. just has to be working to the point where it can send a message to your
  172. ISP's mail server).  A working telnetd/ftpd/inetd/whatever setup so you
  173. can actually get into your computer from somewhere else.  A working cron.
  174.  
  175. Section 2.2: Setting up crontab
  176.  
  177. cron is a daemon that starts programs at specified times.  You can look
  178. at your crontab by running "crontab -e".  We'll be using crontab to set
  179. up your constant PPP connection.
  180.  
  181. Run crontab -e as root and add this line:
  182.  
  183. #*/2 * * * * ping -c1 your_nameserver 2>&1 | grep "0 packets" >/dev/null
  184. && { /usr/sbin/ppp-off >/dev/null ; kill -9 `/sbin/pidof pppd 2>/dev/null`
  185. ; sleep 2 ; /usr/sbin/pppd }
  186.  
  187. What this line does is ping your ISP's name server every two minutes,
  188. and restarts your connection if it doesn't get a responce.
  189.  
  190. Hint1: This is all one line, don't break it into three!
  191. Hint2: Those ">/dev/null"s and "2>&1"s prevent crond from mailing error and
  192.        status messages to root.  You can take them all out for debugging
  193.        purposes if you're having trouble.
  194. Hint3: Check those paths!
  195. Hint5: I use your ISP's DNS server because I figure that if that's
  196.        down, your net connection is screwed anyways :)
  197. Hint6: Is this all mud to you?  No prob, just check out "man crontab"
  198.        and the next subsection to see why I do what I do.
  199. Hint7: Be sure to use your DNS server's numeric IP address, otherwise
  200.        ping returns a different message.
  201.  
  202. Now whenever you want your connection to stay up, you can just run
  203. crontab -e and take out that "#"...and when you want your connection to
  204. stay down, run crontab -e and put the "#" back in, then kill your
  205. connection with ppp-off or whatever it is that you use.
  206.  
  207. I know there are other ways then this to keep a connection up
  208. (specifically I know that there is a script for pppd, and also a daemon
  209. called pppupd that will do it) but I have not tried them.  If you use
  210. them and think them worthwhile, then drop me a note and I'll try them
  211. out.
  212.  
  213. Section 2.2.1: Explanation of the crontab entry
  214.  
  215. Let's look at that line in its component pieces:
  216.  
  217. Part 1: ping -c1 your_nameserver 2>&1 | grep "0 packets" > /dev/null
  218.  
  219. This bit pings the address of your ISP's name server once.  If the
  220. connection is down, then ping returns a status message that includes
  221. "0 packets received", which is what we're grepping for.
  222.  
  223. Part 2: { /usr/sbin/ppp-off >/dev/null ; kill -9 `/sbin/pidof pppd 2>
  224.    /dev/null` ; sleep 2 ; /usr/sbin/pppd }
  225.  
  226. What this part does is kill the ppp-connection (ppp-off), kill the pppd
  227. itself in case that didn't happen before for some reason (kill -9 `/sbin/
  228. pidof pppd 2> /dev/null`), wait for two seconds to make sure everything
  229. is dead, then start pppd again.
  230.  
  231. For ppp-off and pppd substitute whatever you use to stop and start your
  232. ppp connection.
  233.  
  234. Section 2.3: ip-up and ip-down
  235.  
  236. /etc/ppp/ip-up and /etc/ppp/ip-down are rather useful scripts for us.
  237. They are executed when pppd goes up/down and therefore are good for
  238. events that need to occur at this time.  Mine look like this:
  239.  
  240. ip-up:
  241.  
  242. >#!/bin/sh 
  243. >echo -n ^G > /dev/console 
  244. >echo $4 > /etc/add 
  245. >mail -s "New IP address" fenris@lightspeed.net < /etc/add 
  246. >chmod 644 /etc/add
  247. >echo "127.0.0.1 localhost" > /etc/hosts 
  248. >echo $4 ulfheim.lightspeed.net ulfheim >> /etc/hosts
  249.  
  250. ip-down:
  251.  
  252. >#!/bin/sh 
  253. >echo -n ^G > /dev/console 
  254. >rm /etc/add 
  255. >echo 127.0.0.1 ulfheim.lightspeed.net localhost ulfheim > /etc/hosts
  256.  
  257. Don't worry if you don't get all of this, we'll be explaining most of it
  258. right now.
  259.  
  260. Section 2.3.1: Setting up your ip-up and ip-down
  261.  
  262. The second part of this hack involves making your new IP address
  263. available to you from practically any machine on the net.  To achieve
  264. this we do the following:
  265.  
  266. Create a file as root called /etc/ppp/ip-up.  Put this in it:
  267.  
  268. #!/bin/sh 
  269. # $4 is our ip address in these two scripts (convenient eh?) 
  270. # /etc/add will hold our address 
  271. echo $4 > /etc/add
  272. # mails our address to our ISP's mail server, with the subject "new ip
  273. # address"
  274. mail -s "New IP address" yourname@your_internet_address < /etc/add
  275.  
  276. Then create /etc/ppp/ip-down and put this in it:
  277.  
  278. #!/bin/sh rm /etc/add
  279.  
  280. Then run "chmod 700 /etc/ppp/ip-up /etc/ppp/ip-down" to make them
  281. executable.
  282.  
  283. Now edit your rc startup scripts and put in a "rm /etc/add" anywhere
  284. you feel is appropriate (just in case your power goes down while your
  285. connection is up, not really necessary, but I like to be somewhat
  286. complete about these things :)  I put it in /etc/rc.d/rc.S, which should
  287. be okay.
  288.  
  289. Voila!  Now every time pppd is started your address will be mailed to
  290. your ISP's mail server.  We retreive it in the next section.
  291.  
  292. Section 2.4: How to find out your new IP address
  293.  
  294. Well, this calls for some resourcefulness on your part.  I really can't
  295. walk you through it, as it depends on which machine you're trying to get
  296. it from.  In Windows, you can try to set up an email program to do
  297. retrieve mail from your ISP's mail server, and if you're in Unix see if
  298. there's a program called "popclient" or somesuch.  If all else fails,
  299. you can always use telnet (see the next section).
  300.  
  301. Section 2.4.1: Telnetting to a POP3 server
  302.  
  303. This is how I retrieve my IP address, as I am usually showing off when I
  304. do all of this anyways, and it really confuses all of the GUI users I
  305. show it to :)  Hopefully your ISP uses a POP3 server for mail (most
  306. likely), otherwise you'll just have to figure this out yourself by
  307. looking up the RFC for the protocol you need and figure out how to do it
  308. by telnet.
  309.  
  310. Anyways, first you want to telnet to port 110 of your ISP's mail server.
  311. In Unix you do this with "telnet your_isp's_mail_server 110", on a VAX
  312. you might need to do "telnet your_isp's_mail_server/port=110", and in a
  313. Web browser you should use "telnet://your_isp's_mail_server:110".
  314. Hopefully you can figure it out.
  315.  
  316. Once you are connected, you should see something like this:
  317.  
  318. >Connected to new-ls.lightspeed.net.  
  319. >Escape character is '^]'.  
  320.  
  321. >+OK QUALCOMM Pop server derived from UCB (version 2.1.4-R3) at
  322. >new-ls.lightspeed.net starting.
  323.  
  324. type "user your_username" to login.
  325.  
  326. >+OK Password required for fenris.
  327.  
  328. now type "pass your_password"
  329.  
  330. >+OK fenris has 2 message(s) (3030 octets).
  331.  
  332. type "list" to look at a list of your messages.
  333.  
  334. >+OK 2 messages (3030 octets) >1 2400 >2 630 >.
  335.  
  336. See that message with size 630?  That's my IP address!  How do I know?
  337. Because it's always that size :)
  338.  
  339. Now type "retr message_number" to retrieve the message you want.
  340.  
  341. >+OK 630 octets 
  342. >Received: from ulfheim.lightspeed.net (root@bak2-pp-ls.lightspeed.net
  343. >[204.216.66.74]) by new-ls.lightspeed.net (8.6.12/8.6.12) with ESMTP id
  344. >TAA12048 for <fenris@lightspeed.net>; Mon, 22 Apr 1996 19:15:37 -0700
  345. >Received: (from root@localhost) by ulfheim.lightspeed.net (8.7/8.6.9)
  346. >TAA00594 for fenris@lightspeed.net; Mon, 22 Apr 1996 19:15:29
  347. >Date: Mon, 22 Apr 1996 19:15:29 -0700
  348. >From: Deus In Machina <root@ulfheim.lightspeed.net>
  349. >Message-Id: <199604230215.TAA00594@ulfheim.lightspeed.net>
  350. >To: fenris@lightspeed.net
  351. >Subject: New IP address 
  352. >204.216.66.74
  353. >
  354. >.
  355.  
  356. And there it is!  Use "dele message_number" to get rid of it or just
  357. "quit" to leave it there and quit.  Now just telnet to your machine at
  358. that address and have fun!
  359.  
  360. If any of this is just not working, then check out RFC 1225, which
  361. describes the POP3 protocol in full detail.
  362.  
  363. 3.0 Hack #2: Dynamically changing /etc/hosts
  364.  
  365. As I said before, Linux isn't completely happy with dynamic IP
  366. addressing.  For example, sometimes talkd won't work with kludgy values
  367. in /etc/hosts.  However, the following hack makes up for a lot of that
  368. by changing /etc/hosts according to the IP address we receive when we
  369. call up our ISP.
  370.  
  371. For me this fixed problems with "hostname" and "talk".
  372.  
  373. Section 3.1: What you'll need.
  374.  
  375. Nothing but a working PPP setup, really.
  376.  
  377. Section 3.2: More fun with ip-up and ip-down
  378.  
  379. This hack is really very easy, and only involves three files, ip-up,
  380. ip-down, and an rc file (I put it in rc.S).
  381.  
  382. First, make a backup of /etc/hosts, just in case this screws up
  383. anything.
  384.  
  385. Add the following lines to /etc/ppp/ip-up:
  386.  
  387. echo 127.0.0.1 localhost > /etc/hosts 
  388. echo $4 yourmachine.yourdomain yourmachine >> /etc/hosts 
  389. #
  390.  
  391. EXAMPLE:  My machine is named "ulfheim" and its domain is
  392. "lightspeed.net".  The lines in my ip-up say:
  393.  
  394. echo 127.0.0.1 localhost > /etc/hosts 
  395. echo $4 ulfheim.lightspeed.net ulfheim >> /etc/hosts 
  396. #
  397.  
  398. Then add the following lines to /etc/ppp/ip-down:
  399.  
  400. echo 127.0.0.1 yourmachine.yourdomain localhost yourmachine > /etc/hosts
  401. #
  402.  
  403. EXAMPLE:  My machine is named "ulfheim" and its domain is
  404. "lightspeed.net".  The lines in my ip-down say:
  405.  
  406. echo 127.0.0.1 ulfheim.lightspeed.net localhost ulfheim > /etc/hosts 
  407. #
  408.  
  409. Now put the following in an rc script (I chose rc.S, it seems ok there).
  410.  
  411. echo 127.0.0.1 yourmachine.yourdomain localhost yourmachine > /etc/hosts
  412. #
  413.  
  414. EXAMPLE:  My machine is named "ulfheim" and its domain is
  415. "lightspeed.net".  The lines at the end of my /etc/rc.d/rc.S say:
  416.  
  417. echo 127.0.0.1 ulfheim.lightspeed.net localhost ulfheim > /etc/hosts 
  418. #
  419.  
  420. This last one is in case your power goes out or something while your
  421. connection was still up.
  422.  
  423. 4.0 We need more hacks!
  424.  
  425. If you have a Dynamic IP hack that you would like to contribute to this
  426. HOWTO, then let me know.  Be warned that if you do so that it will have
  427. to be covered under the copyright notice in Section 1.5, for reasons of
  428. CD publishing and whatnot.
  429.  
  430. If you {liked this HOWTO, didn't like this HOWTO, thought this HOWTO was
  431. too confusing, found something in this HOWTO that doesn't work and/or is
  432. just plain wrong, want to send me email, don't want to send me email,
  433. found a security problem in this howto, etc} then please mail me at
  434. <fenris@lightspeed.net>.  I mean it, I really would appreciate *any*
  435. feedback on this HOWTO, even if you just mailed me to say that you read
  436. it!
  437.  
  438. Really!  Just e-mail me on anything!  I *really do* love getting e-mail!
  439.  
  440. Flames will *not* go to /dev/null.  I think if you feel that strongly
  441. about it, I should listen.
  442.  
  443. If you write up a chapter for this HOWTO not only will you be helping
  444. the Linux community, but you will receive full credit for your hack,
  445. your name will go into the credits at the end of this HOWTO, you will be
  446. acknowledged as a contributor in the beginning of this HOWTO, your idea
  447. will be archived with almost every CD Linux distribution in the world,
  448. you'll be the envy of all of your peers, etc.
  449.  
  450. 5.0 CREDITS
  451.  
  452. "Michael Driscoll" <fenris@lightspeed.net> 
  453.   is the HOWTO moderator and the author of hacks one and two.
  454. "Christian G. Warden" <cwarden@loop.com>
  455.   helped debug the crontab line used in hack one, now the entry will work
  456.   in (hopefully) all cases, including those when the connection goes down
  457.   but pppd does not.
  458.  
  459. YOUR NAME IN LIGHTS HERE!  Just send me a hack to put in this mini-HOWTO!
  460.  
  461.