Gentoo Archives: gentoo-user

From: Richard Watson <waty@×××××××××××.au>
To: gentoo-user@l.g.o
Subject: [gentoo-user] No /etc/resolv.conf with dhcpcd
Date: Sun, 27 May 2007 03:53:32
Message-Id: 1180237484.10262.9.camel@localhost
1 Hi - For a while now when I run
2 # dhcpcd eth1
3 I get an IP address OK but no DNS. I've established that a
4 /etc/resolv.conf file is not being created when the command is being
5 run.
6
7 There's a script invoked at some stage called
8 /etc/resolvconf/update.d/libc. This is creating a file with all the DNS
9 information called /var/run/resolvconf/interfaces/eth1 (or eth2
10 depending on the interface raised). However it's not then creating
11 /etc/resolv.conf. I can get around this by running my own script to
12 copy
13 the DNS information to /etc/resolv.conf but it would be good to figure
14 out why it's not working.
15
16 I attach output of my /etc/resolvconf/update.d/libc below if anyone can
17 help. I've tried reemerging the package (unsuccessfully).
18
19 Thanks, Richard
20
21 === Begin ===
22
23 #!/bin/bash
24 # Copyright 2006 Gentoo Foundation
25 # Distributed under the terms of the GNU General Public License v2
26
27 # libc resolv.conf updater
28
29 # Written by Roy Marples (uberlord@g.o)
30 # Heavily based on Debian resolvconf by Thomas Hood
31
32 # Load generic Gentoo functions
33 source /etc/init.d/functions.sh
34
35 [[ $(readlink /etc/resolv.conf 2>/dev/null) \
36 != "resolvconf/run/resolv.conf" ]] && exit 0
37
38 RESOLVCONF="$(resolvconf -l)"
39
40 BASE="/etc/resolvconf/resolv.conf.d/base"
41 OUR_NS=
42 if [[ -e ${BASE} ]] ; then
43 OUR_NS="$(sed -n -e 's/^[[:space:]]*nameserver[[:space:]]*//p'
44 "${BASE}")"
45 fi
46 OUR_NS="$(uniqify \
47 ${OUR_NS} \
48 $(echo "${RESOLVCONF}" \
49 | sed -n -e 's/^[[:space:]]*nameserver[[:space:]]*//p') \
50 )"
51
52 # libc only allows for 3 nameservers
53 # truncate after 127 as well
54 i=0
55 NS=
56 for N in ${OUR_NS} ; do
57 ((i++))
58 NS="${NS} ${N}"
59 [[ ${i} == "3" || ${N} == "127."* ]] && break
60 done
61
62 # This is nasty!
63 # If we have a local nameserver then assume they are intelligent enough
64 # to be forwarding domain requests to the correct nameserver and not
65 search
66 # ones. This means we prefer search then domain, otherwise, we use them
67 in
68 # the order given to us.
69 OUR_SEARCH=
70 if [[ ${N} == "127."* ]] ; then
71 if [[ -e ${BASE} ]] ; then
72 OUR_SEARCH="$(sed -n -e 's/^[[:space:]]*search[[:space:]]*//p'
73 "${BASE}")"
74 fi
75 OUR_SEARCH="${OUR_SEARCH} $(echo "${RESOLVCONF}" \
76 | sed -n 's/^[[:space:]]*search[[:space:]]*//p')"
77 if [[ -e ${BASE} ]] ; then
78 OUR_SEARCH="${OUR_SEARCH} $(sed -n -e
79 's/^[[:space:]]*domain[[:space:]]*//p' "${BASE}")"
80 fi
81 OUR_SEARCH="${OUR_SEARCH} $( echo "${RESOLVCONF}" \
82 | sed -n -e 's/^[[:space:]]*domain[[:space:]]*//p')"
83 else
84 if [[ -e ${BASE} ]] ; then
85 OUR_SEARCH="$(sed -n -e 's/^[[:space:]]*search[[:space:]]*//p' \
86 -e 's/^[[:space:]]*domain[[:space:]]*//p' "${BASE}")"
87 fi
88 OUR_SEARCH="${OUR_SEARCH} $(echo "${RESOLVCONF}" \
89 | sed -n -e 's/^[[:space:]]*search[[:space:]]*//p' \
90 -e 's/^[[:space:]]*domain[[:space:]]*//p')"
91 fi
92
93 # libc only allows for 6 search domains
94 i=0
95 SEARCH=
96 for S in $(uniqify ${OUR_SEARCH}) ; do
97 ((i++))
98 SEARCH="${SEARCH} ${S}"
99 [[ ${i} == "6" ]] && break
100 done
101 [[ -n ${SEARCH} ]] && SEARCH="search${SEARCH}"
102
103 # Hold our new resolv.conf in a variable to save on temporary files
104 NEWCONF="# Generated by resolvconf\n"
105 [[ -e /etc/resolvconf/resolv.conf.d/head ]] \
106 && NEWCONF="${NEWCONF}$(< /etc/resolvconf/resolv.conf.d/head)\n"
107 [[ -n ${SEARCH} ]] && NEWCONF="${NEWCONF}${SEARCH}\n"
108 for N in ${NS} ; do
109 NEWCONF="${NEWCONF}nameserver ${N}\n"
110 done
111
112 # Now dump everything else from our resolvs
113 if [[ -e ${BASE} ]] ; then
114 NEWCONF="${NEWCONF}$(sed -e '/^[[:space:]]*$/d' \
115 -e '/^[[:space:]]*nameserver[[:space:]]*.*/d' \
116 -e '/^[[:space:]]*search[[:space:]]*.*/d' \
117 -e '/^[[:space:]]*domain[[:space:]]*.*/d' \
118 "${BASE}")"
119 fi
120
121 # We don't know we're using GNU sed, so we do it like this
122 NEWCONF="${NEWCONF}$(echo "${RESOLVCONF}" | sed -e '/^[[:space:]]*$/d' \
123 -e '/^[[:space:]]*#/d' \
124 -e '/^[[:space:]]*nameserver[[:space:]]*.*/d' \
125 -e '/^[[:space:]]*search[[:space:]]*.*/d' \
126 -e '/^[[:space:]]*domain[[:space:]]*.*/d' \
127 )"
128 [[ -e /etc/resolvconf/resolv.conf.d/tail ]] \
129 && NEWCONF="${NEWCONF}$(< /etc/resolvconf/resolv.conf.d/tail)"
130
131 # Check if the file has actually changed or not
132 if [[ -e /etc/resolv.conf ]] ; then
133 [[ $(< /etc/resolv.conf) == "$(echo -e "${NEWCONF}")" ]] && exit 0
134 fi
135
136 # Create our resolv.conf now
137 echo -e "${NEWCONF}" > /etc/resolvconf/run/resolv.conf
138
139 # Restart nscd if it's running
140 if [[ -x /etc/init.d/nscd ]] ; then
141 if /etc/init.d/nscd --quiet status ; then
142 /etc/init.d/nscd --nodeps --quiet restart
143 fi
144 fi
145
146 # Notify users of the resolver
147 for x in /etc/resolvconf/update-libc.d/* ; do
148 [[ -e ${x} ]] && "${x}" "$@"
149 done
150
151 # vim: ts=4 :
152
153
154 --
155 gentoo-user@g.o mailing list