ownexample.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <title>
  7. Your Own Domain Name with External DHCP for Slackware on a Gateway
  8. </title>
  9. <base target="_blank">
  10. </head>
  11. <body bgcolor=white style="font-family: helvetica">
  12. <table width="100%">
  13. <tr>
  14. <td align=left valign=top>
  15. <img align=middle src="gnudip.jpg" alt="GnuDIP Logo" border=0 height=60 width=113>
  16. <td>
  17. <h1>
  18. Your Own Domain Name with External DHCP for Slackware on a Gateway
  19. </h1>
  20. </tr>
  21. </table>
  22. <hr>
  23. <p>
  24. This article assumes the reader is familiar with the contents of
  25. <a href="owndomain.html">owndomain.html</a>.
  26. <p>
  27. In this scenario we are running
  28. <a href="http://slackware.com/">Slackware Linux</a> on an Internet gateway,
  29. obtaining its dynamic external IP address using DHCP.
  30. <p><hr>
  31. <p>
  32. Ideally, choose dynamic DNS services that do not themselves have dynamic
  33. IP addresses, and whose name server names are inside there own domains.
  34. This will give more efficiency, and some resolver programs
  35. will choke on two many levels of indirection, despite what the RFC-s
  36. say.
  37. <p>
  38. The zone file would contain something like:
  39. <blockquote>
  40. <pre>
  41. $TTL 1D
  42. you.ca. SOA you.ca. root.you.ca. (
  43. 20020101 ;serial
  44. 3600 ;refresh
  45. 1800 ;retry
  46. 604800 ;expiration
  47. 0 ;TTL for NACK
  48. )
  49. you.ca. NS you.dyndnservice1.ca.
  50. you.ca. NS you.dyndnservice2.ca.
  51. $ORIGIN you.ca.
  52. $INCLUDE /etc/bind/IP-address
  53. </pre>
  54. </blockquote>
  55. <p>
  56. Make sure that the gateway will boot (to the point where there is a login prompt
  57. on the gateway console) with the DSL or cable modem unplugged! This
  58. means <code>named</code> has to be restarted again right after booting, but makes
  59. things much simpler and grief free.
  60. <p>
  61. Start a script that uses ISC <code>dhlient</code> in background using "<code>&</code>"
  62. after everything is up using <code>/etc/rc.d/rc.local</code>:
  63. <blockquote>
  64. <pre>
  65. #!/bin/sh
  66. #
  67. # /etc/rc.d/rc.local: Local system initialization script.
  68. #
  69. # Put any local setup commands in here:
  70. # set up external interface
  71. echo "Attempting to configure eth1 by contacting a DHCP server..."
  72. /bin/touch /var/log/dhclient-at-boot
  73. /usr/local/dhcp/sbin/dhclient eth1 &> /dev/null 2>&1 &
  74. echo Starting fetchmail daemon ...
  75. /etc/rc.d/rc.fetchmail 2>&1 | /usr/bin/logger -t rc.fetchmail -s &
  76. </pre>
  77. </blockquote>
  78. <p>
  79. Provide an "enter hooks" script for <code>dhclient</code>
  80. - <code>/etc/dhclient-enter-hooks</code>:
  81. <blockquote>
  82. <pre>
  83. #!/bin/sh
  84. # enter hooks for dhclient-script
  85. # do not overwrite /etc/resolv.conf
  86. function make_resolv_conf() { return; }
  87. </pre>
  88. </blockquote>
  89. <p>
  90. Provide an "exit hooks" script for <code>dhclient</code>
  91. - <code>/etc/dhclient-exit-hooks</code>:
  92. <blockquote>
  93. <pre>
  94. #!/bin/sh
  95. # exit hooks for dhclient-script
  96. # for debugging
  97. #( \
  98. # echo ==== start of debug dump ==== ; \
  99. # echo parms: $* ; \
  100. # env ; \
  101. # echo ==== end of debug dump ==== ; \
  102. # ) | /usr/bin/logger -t rc.dhclient-exit-hooks
  103. # call our setup script if dhclient has set up interface
  104. if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
  105. [ x$reason = xREBIND ] || [ x$reason = xREBOOT ] || \
  106. [ x$reason = xTIMEOUT ]; then
  107. /etc/rc.d/rc.dhclient_exit 2>&1 | /usr/bin/logger -t rc.dhclient_exit &
  108. exit
  109. fi
  110. # set up interface ourselves and call our setup script
  111. if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || \
  112. [ x$reason = xRELEASE ] || [ x$reason = xSTOP ]; then
  113. if [ x$old_ip_address = x ]; then
  114. if [ -r /var/log/dhclient-addresses ]; then
  115. read zzz old_ip_address < /var/log/dhclient-addresses
  116. fi
  117. fi
  118. if [ x$old_ip_address = x ]; then
  119. # provide a last ditch default? comment out exit
  120. old_ip_address=10.10.10.10
  121. exit
  122. fi
  123. ifconfig $interface inet $old_ip_address
  124. export new_ip_address=$old_ip_address
  125. /etc/rc.d/rc.dhclient_exit 2>&1 | /usr/bin/logger -t rc.dhclient_exit &
  126. exit
  127. fi
  128. </pre>
  129. </blockquote>
  130. <p>
  131. You may also want to replace the call to the "<code>ping</code>" command
  132. in the "<code>TIMEOUT</code>" section of the "<code>sbin/dhclient-script</code>"
  133. script (part of ISC DHCP) with a call to the "<code>true</code>" command.
  134. Without this, if your ISP's router is down, the "<code>ping</code>" command
  135. may run indefinitely.
  136. <p>
  137. The "exit hooks" script for <code>dhclient</code> calls
  138. <code>/etc/rc.d/rc.dhclient_exit</code>:
  139. <blockquote>
  140. <pre>
  141. #!/bin/sh
  142. # read old IP address
  143. if [ -r /var/log/dhclient-addresses ]
  144. then
  145. read zzz old_ip_address < /var/log/dhclient-addresses
  146. fi
  147. if [ "$old_ip_address" == "" ]
  148. then
  149. old_ip_address="0.0.0.0"
  150. fi
  151. # (re)erect firewall if address changed or boot time
  152. if [ "$old_ip_address" != "$new_ip_address" ] ||
  153. [ -e /var/log/dhclient-at-boot ]
  154. then
  155. # ensure kernel had time to set up interface
  156. #/usr/bin/sleep 1
  157. # reset firewall
  158. /bin/echo \(re\)setting firewall ...
  159. /etc/rc.d/rc.firewall
  160. fi
  161. # record old and new IP addresses
  162. /bin/echo -n $old_ip_address $new_ip_address &> /var/log/dhclient-addresses
  163. # say whether or not IP address changed
  164. if [ "$old_ip_address" == "$new_ip_address" ]
  165. then
  166. /bin/echo IP address has not changed
  167. else
  168. /bin/echo IP address has changed from $old_ip_address to $new_ip_address
  169. fi
  170. # configure BIND
  171. /bin/echo mail IN CNAME mail.$new_domain_name. > /etc/bind/services
  172. /bin/echo news IN CNAME news.$new_domain_name. >> /etc/bind/services
  173. /bin/echo www IN CNAME www.$new_domain_name. >> /etc/bind/services
  174. #
  175. /bin/echo "@ IN A" $new_ip_address > /etc/bind/IP-address
  176. #
  177. /bin/echo zone \"$new_domain_name\" { type forward\; forwarders { > /etc/bind/forward
  178. for nameserver in $new_domain_name_servers
  179. do
  180. /bin/echo $nameserver\; >> /etc/bind/forward
  181. done
  182. /bin/echo }\; }\; >> /etc/bind/forward
  183. #
  184. /bin/echo BIND has been configured
  185. # IP address changed?
  186. if [ "$old_ip_address" != "$new_ip_address" ]
  187. then
  188. # update address in local dynamic zones
  189. /bin/echo Updating addresses for dynamic zones to $new_ip_address
  190. /usr/local/bind/bin/nsupdate -v -k \
  191. /usr/local/gnudip/etc/Kgnudip-key.+157+41184.private << EOF
  192. server localhost
  193. update delete dyn.you.ca. A
  194. update add dyn.you.ca. 60 A $new_ip_address
  195. update delete dyn2.you.ca. A
  196. update add dyn2.you.ca. 60 A $new_ip_address
  197. EOF
  198. /bin/echo
  199. /usr/local/bind/bin/host dyn.you.ca.
  200. /usr/local/bind/bin/host dyn2.you.ca.
  201. fi
  202. # restart affected daemons if address changed or boot time
  203. if [ "$old_ip_address" != "$new_ip_address" ] ||
  204. [ -e /var/log/dhclient-at-boot ]
  205. then
  206. # restart named
  207. if /bin/ps -C named &> /dev/null
  208. then
  209. /bin/echo Stopping named ...
  210. /bin/killall named
  211. fi
  212. /bin/echo Starting named ...
  213. /etc/rc.d/rc.named
  214. # (re)start ntpd
  215. if /bin/ps -C ntpd &> /dev/null
  216. then
  217. /bin/echo Stopping ntpd ...
  218. /bin/killall ntpd
  219. else
  220. /bin/echo Calling ntpdate ...
  221. /usr/local/ntp/bin/ntpdate ddd.ddd.ddd.ddd
  222. fi
  223. /bin/echo Starting ntpd ...
  224. /usr/local/ntp/bin/ntpd
  225. # (re)start iplog
  226. if /bin/ps -C iplog &> /dev/null
  227. then
  228. /bin/echo Stopping iplog ...
  229. /bin/killall iplog
  230. fi
  231. /bin/echo Starting iplog ...
  232. /usr/local/iplog/sbin/iplog
  233. fi
  234. # no longer boot time
  235. /bin/rm /var/log/dhclient-at-boot &> /dev/null
  236. # update dynamic DNS services?
  237. /etc/rc.d/rc.dyndns
  238. </pre>
  239. </blockquote>
  240. <p>
  241. And <code>/etc/rc.d/rc.dhclient_exit</code> calls <code>/etc/rc.d/rc.dyndns</code>:
  242. <blockquote>
  243. <pre>
  244. #!/bin/sh
  245. #
  246. # rc.dyndns
  247. #
  248. # update dynamic DNS services if needed
  249. echo Updating IP address at GnuDIP servers ...
  250. /usr/local/gdipc/bin/gdipc.pl -f /etc/gdipc/gdipc.conf
  251. echo Updating IP address at notgnudip.org ...
  252. /usr/local/ez-ipupdate/bin/notgnudip.org.conf
  253. </pre>
  254. </blockquote>
  255. <p>
  256. Some daemons have to be restarted when the address changes, because they are
  257. listening on specific IP addresses, and will not automatically listen on
  258. the new address (use "<code>netstat -ap | less -S</code>" to see which).
  259. This applies to named. Also you may want to supply <code>named</code> with
  260. information from DHCP which has to go in <code>named.conf</code>.
  261. So <code>named</code> has to be restarted. You could make the zones for your
  262. internal machines and <code>you.ca</code> dynamic, but you may find it more
  263. convenient to be able to edit the files (and use <code>$INCLUDE</code>).
  264. <p><hr>
  265. </body>
  266. </html>