Path: samba!concert!gatech!pitt.edu!apollo!qralston From: qralston@gl.pitt.edu (James Ralston Crawford) Newsgroups: comp.sys.sun.admin Subject: SUMMARY: making Sun DNS hostname resolving work without running NIS Keywords: Sun DNS resolve resolving NIS name nameserver Message-ID: <3299@blue.cis.pitt.edu.UUCP> Date: 18 Jul 92 04:07:28 GMT Sender: news+@pitt.edu Reply-To: qralston@gl.pitt.edu Organization: University of Pittsburgh [CIS] Lines: 445 I received a great number of suggestions and "me-too"s to my question concerning name resolving without NIS. I've extrapolated all of the suggested methods into what (IMHO) works the best. Read the "Caveats" and "Parting comments" sections at the end of this, though. Problem: For whatever reason(s), you're not using NIS on your Sun. You're relying on a properly configured /etc/resolv.conf(5) (and, therefore, DNS) to resolve hostnames. However, utilities such as nslookup(8c) can resolve hostnames successfully, but any programs that are dynamically linked (ping, telnet, ftp, etc) will only resolve hostnames if they are in the /etc/hosts(5) file. Quick answer: As provided by Sun, the resolving routines in /usr/lib/libc.so don't use DNS to resolve hostnames; they use NIS. More detailed answer: Sun's default resolving routines in /usr/lib/libc.so use a two-step process to resolve names: 1. See if the hostname exists in /etc/hosts. 2. If that fails, then give the hostname to the NIS server, and let it resolve it. The NIS server then performs these steps: 1. See if the name exists in /etc/NIS/hosts (or wherever the NIS master hosts file is) 2. If that fails, and the "B=-b" option was set in /var/yp/Makefile, the NIS server will attempt to use DNS to attempt to resolve the name. Partial solutions: 1. Give in to Sun's belief that everyone loooooves and uses NIS; install NIS; set up an NIS server. For a lot of people, this is not a practical solution. Many organizations are working to. wards a distributed network, in which each machine depends on as few as other machines as possible (AFS and DFS are two prime examples.) In this case, installing NIS and having all of your machines depending on one NIS server for resolving hostnames is taking a step backwards instead of forwards. In addition, unless the domain name server is also the NIS server, for hostnames that are not known locally, this makes more work for the NIS master server, and more network traffic. (In other words, hostname resolve requests not known locally would be handled like this: localhost -> NIS server -> nameserver By setting up each machine to use DNS on its own, you eliminate the middle man (so to speak), and get this: localhost -> nameserver 2. Replace the resolving routines in /usr/lib/libc.so with the ones located in /usr/lib/libresolv.a. This will make it so that *ALL* hostname resolves will go directly to DNS, without checking /etc/hosts; the resolving routines in libresolv.a do not look at /etc/hosts. (Sun's logic behind this is that if you're attempting to resolve via DNS, naturally NIS has already made the attempt to resolve from /etc/NIS/hosts, /etc/hosts, etc. Besides having the effect of making your machine rely on DNS for resolving everything, there are few programs that won't like the fact that /etc/hosts isn't looked at. In particular, syslogd will fail to recognize the machine "loghost" (because this is defined in the /etc/hosts file.) The real (tm) solution: ----------------------- Throw away Sun's libresolv.a and build a *real* one. Then merge those routines into your existing C libraries. Here's how you can do this. 1. Ensure that the "Shlib Custom" optional software category was loaded from your SunOS 4.1.x media. 2. cd to /usr/lib/shlib.etc 3. su 4. Copy the file included below to README.DNS in this directory. ----------------------------------------------------------------------- 8<----------/usr/lib/shlib.etc/README. .DNS----------cut-here---------->8 This is how to get intelligent DNS resolving in your shared libc library. This assumes that you are already familiar with the procedure outlined in the original README file. Note! If you are interested in a System V libc, please substitute libcs5_pic.a for libc_pic.a in step 6, libcs5.so.x.y.z for libc.so.x.y.z in step 17. 1. cd to /usr/lib/shlib.etc and become super user, if you haven't already. $ cd /usr/lib/shlib.etc $ su 2. Obtain and unpack the resolv+ package, written by Bill Wisner. (It should be available via anonymous ftp from hayes.ims.alaska.edu, in the /networking directory. If it's not, then use archie to track a copy down, and tailor the commands below as necessary.) # mkdir resolv+ # cd resolv+ # ftp hayes.ims.alaska.edu # /bin/sh resolv+.shar 3. Add the -pic flag to the CFLAGS line in the Makefile for resolv+. (Additionally, you may have to eliminate the ${DEFS} and -O flags and remove the additional ld and mv steps if, in step 14, you get this error from ld concerning tmp/gethostnamadr.o: base relative static symbol(__gethtbyname) botch Try it first without changing these additional things; if you run into problems, then go ahead and change them according to this diff): *** Makefile.orig Fri Jul 17 03:12:40 1992 --- Makefile Fri Jul 17 03:13:16 1992 *************** *** 19,23 **** mktemp.o strcasecmp.o strpbrk.o strerror.o DEFS= -DDEBUG ! CFLAGS= -O ${DEFS} -Iinclude libresolv.a: ${OBJS} --- 19,23 ---- mktemp.o strcasecmp.o strpbrk.o strerror.o DEFS= -DDEBUG ! CFLAGS= -pic -Iinclude libresolv.a: ${OBJS} *************** *** 31,46 **** .c.o: ${CC} ${CFLAGS} -c $*.c - -ld -x -r $*.o - mv a.out $*.o gethostnamadr.o: named/gethostnamadr.c ${CC} -c ${CFLAGS} named/gethostnamadr.c - -ld -x -r gethostnamadr.o - . mv a.out gethostnamadr.o sethostent.o: named/sethostent.c ${CC} -c ${CFLAGS} named/sethostent.c - -ld -x -r sethostent.o - mv a.out sethostent.o clean: FRC --- 31,40 ---- 4. Run `make` in the resolv+ directory. This should give you libresolv.a. # make 5. Change back to /usr/lib/shlib.etc, and make a temporary directory. # cd .. # mkdir tmp 6. Change to the "tmp" directory just made, extract the contents of the libresolv you just built and the pic .o from libc_pic.a (in that order!), and rm the file __.SYMDEF. # cd tmp # ar x ../resolv+/libresolv.a # ar x ../libc_pic.a # rm __.SYMDEF 7. Rename any files that "ar" truncated (grrrrr) to 16 characters to their original, proper names. (The original README file neglects to mention the xccs.multibyte.o file; if you use any Internationalization features and need to handle multi-byte character sets, do not forget this step. # /bin/ls -1 | egrep -v .o$ rpc_commondata. rpc_dtablesize. xccs.multibyte. # mv rpc_commondata. rpc_commondata.o # mv rpc_dtablesize. rpc_dtablesize.o # mv xccs.multibyte. xccs.multibyte.o 8. Remove the old routine to do the hostname/addr resolution: # rm gethostent.o 9. Remove the libresolv module that contains `strncasecmp' (which is now in the main C library, so it is redundant): # rm strcasecmp.o 10. Go back up to the /usr/lib/shlib.etc directory. # cd .. 11. Edit the lorder-sparc file. You need to remove the reference to gethostent.o and add the references to the new resolver library routines. Use this patch to guide you: *** lorder-sparc.orig Fri Jul 17 14:16:19 1992 --- lorder-sparc Fri Jul 17 14:17:39 1992 *************** *** 150,154 **** getwd.o getnetgrent.o ! gethostent.o ypxdr.o ttyname.o --- 150,161 ---- getwd.o getnetgrent.o ! gethostnamadr.o ! sethostent.o ! res_query.o ! res_mkquery.o ! res_send.o