old-www/LDP/LG/issue76/tag/12.html

361 lines
14 KiB
HTML

<!--startcut ======================================================= -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<META NAME="generator" CONTENT="lgazmail v1.4F.n">
<TITLE>The Answer Gang 76: setting nameservers from the command line</TITLE>
</HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000"
LINK="#3366FF" VLINK="#A000A0">
<!--endcut ========================================================= -->
<P> <hr>
<!--startcut ======================================================= -->
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</p>
<!--endcut ========================================================= -->
<!--startcut ======================================================= -->
<P> <hr>
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
<p align="center">
<table width="100%" border="0"><tr>
<td align="right" valign="center"
><IMG ALT="" SRC="../../gx/navbar/left.jpg"
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="middle" border="0"
><A HREF="..//"
><IMG SRC="../../gx/navbar/toc.jpg" align="middle"
ALT="[ Table Of Contents ]" border="0"></A
><A HREF="../lg_answer.html"
><IMG SRC="../../gx/dennis/answertoc.jpg" align="middle"
ALT="[ Answer Guy Current Index ]" border="0"></A></td>
<td align="center" valign="center"><A HREF="../lg_answer.html#greeting"><img align="middle"
src="../../gx/dennis/smily.gif" alt="greetings" border="0"></A> &nbsp;
<A HREF="../tag/bios.html">Meet&nbsp;the&nbsp;Gang</A> &nbsp;
<A HREF="1.html">1</A> &nbsp;
<A HREF="2.html">2</A> &nbsp;
<A HREF="3.html">3</A> &nbsp;
<A HREF="4.html">4</A> &nbsp;
<A HREF="5.html">5</A> &nbsp;
<A HREF="6.html">6</A> &nbsp;
<A HREF="7.html">7</A> &nbsp;
<A HREF="8.html">8</A> &nbsp;
<A HREF="9.html">9</A> &nbsp;
<A HREF="10.html">10</A> &nbsp;
<A HREF="11.html">11</A> &nbsp;
<A HREF="12.html">12</A>
</td>
<td align="left" valign="center"><A HREF="../../tag/kb.html"
><IMG SRC="../../gx/dennis/answerpast.jpg" align="middle"
ALT="[ Index of Past Answers ]" border="0"></A
><IMG ALT="" SRC="../../gx/navbar/right.jpg" align="middle"
WIDTH="14" HEIGHT="45" BORDER="0"></td></tr></table>
</p>
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<!--endcut ========================================================= -->
<P> <hr> <P>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<center>
<H1><A NAME="answer">
<img src="../../gx/dennis/qbubble.gif" alt="(?)"
border="0" align="middle">
<font color="#B03060">The Answer Gang</font>
<img src="../../gx/dennis/bbubble.gif" alt="(!)"
border="0" align="middle">
</A></H1>
<BR>
<H4>By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and...
(<a href="bios.html">meet the Gang</a>) ...
the Editors of Linux Gazette...
and You!
<br>Send questions (or interesting answers) to
The Answer Gang
for possible publication
(but read the <a href="ask-the-gang.html">guidelines</a> first)
</H4>
</center>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<p><hr><p>
<!-- begin 12 -->
<H3 align="left"><img src="../../gx/dennis/qbubble.gif"
height="50" width="60" alt="(?) " border="0"
>setting nameservers from the command line</H3>
<p><strong>From Faber Fedor
</strong></p>
<p></strong></p>
<!-- sig -->
<p align="right"><strong>Answered By Ben Okopnik, John Karns, Chris Gianakopoulos, Jay R. Ashworth
</strong></p>
<P><STRONG>
Here's an interesting problem that I've yet to find a solution for:
</STRONG></P>
<P><STRONG><BLOCKQuote>
A friend of mine has Live <A HREF="http://www.slackware.org/">Slackware</A> Linux on a CD: he can boot off of
the CD and have a functioning Linux box. Of course, the entire
filesystem is read-only.
</BLOCKQuote></STRONG></P>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [John K]
Interesting - I just happened to have been reading the following HowTo a
couple of hours ago, and it mentioned something related:
</blockQuote>
<TABLE WIDTH="95%" BORDER="1" BGCOLOR="#FFFFCC"><TR><TD>
<p align="center">...............</p>
<blockQuote><BLOCKQuote>
CD-Writing HOWTO
Winfried Tr.mper &lt;<A HREF="mailto:winni@xpilot.org"
>winni@xpilot.org</A>&gt;
v2.9.3, 23 July 2000
</BLOCKQuote></blockQuote>
<blockQuote>
4.12. How to make CD-ROMs writable like a hard disk?
</blockQuote>
<blockQuote>
There is an overlay filesystem available for Linux, which is mounted
over the CD-ROM and intercepts all writing operations. New and
modified files are stored elsewhere, but for the user it looks like
the CD-ROM is modified. For more information, see
<A HREF="http://home.att.net/~artnaseef/ovlfs/ovlfs.html"
>http://home.att.net/~artnaseef/ovlfs/ovlfs.html</A>.
</blockQuote><p align="center">...............</p>
</TD></TR></TABLE>
<blockQuote>
BTW, the <A HREF="http://www.suse.com/">SuSE</A> 7.3 live CD writes a file to the FAT partition (approx 80
MB, IIRC) on the hard disk, and keeps config data there. One can edit
files (don't know what restrictions there are in that regard), and it
"remembers" the changes the next boot.
</blockQuote>
<P><STRONG>
<IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
If he had a functioning DHCP server, he would then manually configure
the NIC and run the DHCP client daemon, dhcpcd. Of course, the DHCP
server would provide the ip address of a name server.
</STRONG></P>
<P><STRONG>
But he doesn't have a functioning DHCP server. Since he can't edit
<TT>/etc/resolv.conf</TT> (read-only filesystem, rememeber?) how does he set his
nameserver?
</STRONG></P>
<P><STRONG>
I check the man pages and found that he can set his resolver options and
search domain with enviroment variables, but nothing was said of how to
change/set the nameserver IP(s). I went looking for a program called
'resolv.*' but I couldn't find where the resolver actually resides.
</STRONG></P>
<P><STRONG>
I suggested he mount <TT>/etc/</TT> to a ramdisk, but there should be a more
elegant way to do it.
</STRONG></P>
<P><STRONG>
Suggestions?
</STRONG></P>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Ben]
Grab the source and stare at it for a bit. Either there <EM>is</EM> a command-line
option for it, or you should be able to hack it in fairly easily.
</blockQuote>
<P><STRONG>
<IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
Great Minds Think Alike! That's what I did after posting my message.
Here's what I found out:
</STRONG></P>
<P><STRONG><BLOCKQuote>
You're not going to be able to do it, at least not from "the command
line". AFAICT, there is no "resolver program" per se; all name
resolution is done by calling glibc functions (gethostbyname in my
case).
</BLOCKQuote></STRONG></P>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Ben]
Oh... of course. I actually knew that, but had filed it in a dusty corner
of the brain, and the file cabinet slides rusted and froze in place.
</blockQuote>
<P><STRONG>
<IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
The code in question lies in glibc-&lt;version&gt;/resolv/res_init.c around
line 230 in my version. The authors allow for setting resolv.conf's
"domain" and "search" options from enviromant variables (LOCALDOMAIN and
RES_OPTIONS, respectively) but they don't allow any such thing for
nameservers. Adding the code to read nameservers information from
enviroment variables do that doesn't seem difficult. Learning how to
compile and debug system libraries under linux, OTOH...
<IMG SRC="../../gx/dennis/smily.gif" ALT=";-)"
height="24" width="20" align="middle">
</STRONG></P>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Ben]
<IMG SRC="../../gx/dennis/smily.gif" ALT="&lt;grin&gt;"
height="24" width="20" align="middle"> Ask Chris. He's the one that keeps reading that "writing drivers and
whatever under Unix" book.
</blockQuote>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Jay]
Written, if it's the one I think you mean, by one of my correspondents,
Jon Corbet from LWN, along with some European gent whose name eludes me
for the moment.
</blockQuote>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Chris]
Here I go jumping in the middle of a conversation after I disappear for a
week. I'm always reading those books by W. Richard Stevens. These days,
the book is "Unix Network Programming", the 1990 edition. The newer editions
are in the queue, where he discusses network programming in his first
volume and IPC (including threads) in his second volume. What's cool
about the first volume of the new edition of "Unix Network Programming" is
that he talks about Linux, too.
</blockQuote>
<P><STRONG>
<IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
Another interesting thing I found out: the path and name of
<TT>/etc/resolv.conf</TT> is hard coded, in both the <A HREF="http://www.redhat.com/">Red Hat</A> version and the GNU
version!
</STRONG></P>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Jay]
Not surprising.
</blockQuote>
<P><STRONG>
<IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
I assume you're talking about the hardcoding of <TT>/etc/resolv.conf</TT> and not
the lack of reading the nameserver(s) from the enviroment.
</STRONG></P>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
Note that making that part of glibc environment dependent makes
possible certain Trojan-style holes that are much more difficult to
cause otherwise;
</blockQuote>
<P><STRONG>
<IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
So why does that not apply to LOCALDOMAIN and RES_OPTIONS? I could
force you to search my domain (nefarious.com) by planting a trojan that
sets LOCALDOMAIN. And, if I read the man pages correctly, I can set
RES_OPTIONS="ndots:0" and force you to search my domain.
</STRONG></P>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Jay]
...It doesn't, actually.
</blockQuote>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Jay]
[re: Trojans] caution is indicated (and I could almost guarantee a
formal patch would be rejected by the maintainers).
</blockQuote>
<P><STRONG>
<IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
I'm jazzed enough about this that I want to search down the maintainers
and quiz them about this. Perhaps this weekend...
</STRONG></P>
<blockQuote>
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
> [Jay]
Be interesting to hear.
</blockQuote>
<!-- end 12 -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href="http://www.linuxgazette.com/copying.html"
>Copyright &copy;</a> 2002
<BR>Published in issue 76 of <I>Linux Gazette</I> March 2002</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<!--startcut ======================================================= -->
<P> <hr>
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
<p align="center">
<table width="100%" border="0"><tr>
<td align="right" valign="center"
><IMG ALT="" SRC="../../gx/navbar/left.jpg"
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="middle" border="0"
><A HREF="..//"
><IMG SRC="../../gx/navbar/toc.jpg" align="middle"
ALT="[ Table Of Contents ]" border="0"></A
><A HREF="../lg_answer.html"
><IMG SRC="../../gx/dennis/answertoc.jpg" align="middle"
ALT="[ Answer Guy Current Index ]" border="0"></A></td>
<td align="center" valign="center"><A HREF="../lg_answer.html#greeting"><img align="middle"
src="../../gx/dennis/smily.gif" alt="greetings" border="0"></A> &nbsp;
<A HREF="../tag/bios.html">Meet&nbsp;the&nbsp;Gang</A> &nbsp;
<A HREF="1.html">1</A> &nbsp;
<A HREF="2.html">2</A> &nbsp;
<A HREF="3.html">3</A> &nbsp;
<A HREF="4.html">4</A> &nbsp;
<A HREF="5.html">5</A> &nbsp;
<A HREF="6.html">6</A> &nbsp;
<A HREF="7.html">7</A> &nbsp;
<A HREF="8.html">8</A> &nbsp;
<A HREF="9.html">9</A> &nbsp;
<A HREF="10.html">10</A> &nbsp;
<A HREF="11.html">11</A> &nbsp;
<A HREF="12.html">12</A>
</td>
<td align="left" valign="center"><A HREF="../../tag/kb.html"
><IMG SRC="../../gx/dennis/answerpast.jpg" align="middle"
ALT="[ Index of Past Answers ]" border="0"></A
><IMG ALT="" SRC="../../gx/navbar/right.jpg" align="middle"
WIDTH="14" HEIGHT="45" BORDER="0"></td></tr></table>
</p>
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<!--endcut ========================================================= -->
<P> <hr>
<!--startcut ======================================================= -->
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</p>
<!--endcut ========================================================= -->
<!--startcut ======================================================= -->
</BODY></HTML>
<!--endcut ========================================================= -->