Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

/etc/resolv.conf : How to Reload?

4,517 views
Skip to first unread message

S P Arif Sahari Wibowo

unread,
Oct 31, 2005, 3:02:50 PM10/31/05
to
Hi!

How we can get the glibc or libc in a RHEL 4 / Fedora 3 system
to reload /etc/resolv.conf after we make change to it?

After I change /etc/resolv.conf, the command "host" and
"nslookup" works fine, they can follow the new name server
defined in the /etc/resolv.conf, but the command "gethostbyname"
will still use the old name server in the old /etc/resolv.conf.

I tried nscd -i hosts but no effect.

BTW, I have a lot of error of dbus cannot connect to the audit
system, I am not sure it there is any relation.

Thank you!

--
Stephan Paul Arif Sahari Wibowo
_____ _____ _____ _____
/____ /____/ /____/ /____
_____/ / / / _____/ http://www.arifsaha.com/

ynotssor

unread,
Oct 31, 2005, 3:22:44 PM10/31/05
to
"S P Arif Sahari Wibowo" <arif...@yahoo.com> wrote in message
news:Pine.LNX.4.63.05...@localhost.localdomain

> After I change /etc/resolv.conf, the command "host" and
> "nslookup" works fine, they can follow the new name server
> defined in the /etc/resolv.conf, but the command "gethostbyname"
> will still use the old name server in the old /etc/resolv.conf.
>
> I tried nscd -i hosts but no effect.

"/etc/init.d/nscd restart" has the same effect?


S P Arif Sahari Wibowo

unread,
Oct 31, 2005, 3:26:17 PM10/31/05
to

Yes, I tried that too. But nothing change: gethostbyname still
look for the old name server.

Thanks, though.

Brian Wakem

unread,
Oct 31, 2005, 3:31:15 PM10/31/05
to
S P Arif Sahari Wibowo wrote:

> Hi!
>
> How we can get the glibc or libc in a RHEL 4 / Fedora 3 system
> to reload /etc/resolv.conf after we make change to it?
>
> After I change /etc/resolv.conf, the command "host" and
> "nslookup" works fine, they can follow the new name server
> defined in the /etc/resolv.conf, but the command "gethostbyname"
> will still use the old name server in the old /etc/resolv.conf.
>
> I tried nscd -i hosts but no effect.
>
> BTW, I have a lot of error of dbus cannot connect to the audit
> system, I am not sure it there is any relation.
>
> Thank you!
>


'service network restart' will do it. There's probably a more elegant way
though.

--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png

S P Arif Sahari Wibowo

unread,
Oct 31, 2005, 3:46:28 PM10/31/05
to
On Mon, 31 Oct 2005, Brian Wakem wrote:

> S P Arif Sahari Wibowo wrote:
>> How we can get the glibc or libc in a RHEL 4 / Fedora 3 system
>> to reload /etc/resolv.conf after we make change to it?
>

> 'service network restart' will do it. There's probably a more
> elegant way though.

Actually, the problem came up because the /etc/resolv.conf is
written by dhclient. network restart will restore then rewrite
the /etc/resolv.conf, so I will ends up exactly on the same
spot.

Of course I can "hardwire" it by putting the name server the
dhclient will get in the original /etc/resolv.conf, but that
even farther from elegant.

Thanks, though.

gretchen

unread,
Oct 31, 2005, 6:24:59 PM10/31/05
to
"S P Arif Sahari Wibowo" <arif...@yahoo.com> wrote in message
news:Pine.LNX.4.63.05...@localhost.localdomain

> Actually, the problem came up because the /etc/resolv.conf is


> written by dhclient. network restart will restore then rewrite
> the /etc/resolv.conf, so I will ends up exactly on the same
> spot.

You'll save time by not withholding information such as that in your OP.

> Of course I can "hardwire" it by putting the name server the
> dhclient will get in the original /etc/resolv.conf, but that
> even farther from elegant.

Or you can simply "chmod a-w /etc/resolv.conf" (or whatever file the symlink
points to) so it doesn't get overwritten.

S P Arif Sahari Wibowo

unread,
Oct 31, 2005, 7:41:28 PM10/31/05
to
On Mon, 31 Oct 2005, gretchen wrote:
> You'll save time by not withholding information such as that
> in your OP.

I missed limiting the question that way.

The point is, I don't want answer on how get around the problem
for specific case (dhcpc), which I already know, but I would
like to know whether it is possible to reload /etc/resolv.conf
after the network is started.

> Or you can simply "chmod a-w /etc/resolv.conf" (or whatever
> file the symlink points to) so it doesn't get overwritten.

Not really. I actually need those server given by the dhcp
server.

--
(Stephan Paul) Arif Sahari Wibowo

Bit Twister

unread,
Oct 31, 2005, 7:51:13 PM10/31/05
to
On Mon, 31 Oct 2005 15:24:59 -0800, gretchen wrote:
>
> Or you can simply "chmod a-w /etc/resolv.conf" (or whatever file the symlink
> points to) so it doesn't get overwritten.

Or better yet, add PEERDNS=no to
/etc/sysconfig/network-scripts/ifcfg-ethX where X is the dhcp nic.

S P Arif Sahari Wibowo

unread,
Oct 31, 2005, 7:59:40 PM10/31/05
to
On Mon, 31 Oct 2005, Bit Twister wrote:
> Or better yet, add PEERDNS=no to
> /etc/sysconfig/network-scripts/ifcfg-ethX where X is the dhcp nic.

What if I actually want to use the DNS given by the DHCP server?

--
(Stephan Paul) Arif Sahari Wibowo

Bit Twister

unread,
Oct 31, 2005, 10:35:42 PM10/31/05
to
On Tue, 01 Nov 2005 00:59:40 GMT, S P Arif Sahari Wibowo wrote:
> On Mon, 31 Oct 2005, Bit Twister wrote:
>> Or better yet, add PEERDNS=no to
>> /etc/sysconfig/network-scripts/ifcfg-ethX where X is the dhcp nic.
>
> What if I actually want to use the DNS given by the DHCP server?

Make up your mind. You indicated you changed /etc/reolv.conf and
setvice network restart or boot would change it back.
That is how it is supposed to work.

Now, doing a _man dhclient_ , if that is your dhcp client, might lead you
to informaiton on how you can create a script which will run after a
lease is obtained.

S P Arif Sahari Wibowo

unread,
Oct 31, 2005, 11:24:16 PM10/31/05
to
On Mon, 31 Oct 2005, Bit Twister wrote:
> Make up your mind. You indicated you changed /etc/reolv.conf
> and setvice network restart or boot would change it back.

Nope. The service network restart changed the /etc/resolv.conf
and I want to use the that /etc/resolv.conf, but gethostbyname
doesn't use that /etc/resolv.conf.

Ok let's try this: how to make gethostbyname use the
/etc/resolv.conf given by service network restart?

Dimitris Mexis

unread,
Nov 1, 2005, 2:07:49 AM11/1/05
to
S P Arif Sahari Wibowo wrote:
> On Mon, 31 Oct 2005, Bit Twister wrote:
>
>> Make up your mind. You indicated you changed /etc/reolv.conf and
>> setvice network restart or boot would change it back.
>
>
> Nope. The service network restart changed the /etc/resolv.conf and I
> want to use the that /etc/resolv.conf, but gethostbyname doesn't use
> that /etc/resolv.conf.
>
> Ok let's try this: how to make gethostbyname use the /etc/resolv.conf
> given by service network restart?
>
Just do /sbin/services network restart

Bit Twister

unread,
Nov 1, 2005, 7:59:52 AM11/1/05
to
On Tue, 01 Nov 2005 04:24:16 GMT, S P Arif Sahari Wibowo wrote:
>
> Ok let's try this: how to make gethostbyname use the
> /etc/resolv.conf given by service network restart?

Two files which control resolution order are as follows:

$ cat /etc/host.conf
order hosts,bind
multi on
nospoof on
spoofalert on

$ grep hosts: /etc/nsswitch.conf
hosts: files nisplus nis dns

I have changed namesevers in /etc/resolv.conf and tried lookups with dig
and it would use the new values without having to a service network restart.

No, idea why your code is not seeing the change. Guessing you could force a
new read with the res_init() function prior to doing the gethostbyname.

man 3 resolver

ken

unread,
Nov 1, 2005, 7:21:53 PM11/1/05
to
S P Arif Sahari Wibowo wrote:
> Hi!
>
> How we can get the glibc or libc in a RHEL 4 / Fedora 3 system to reload
> /etc/resolv.conf after we make change to it?
>
> After I change /etc/resolv.conf, the command "host" and "nslookup" works
> fine, they can follow the new name server defined in the
> /etc/resolv.conf, but the command "gethostbyname" will still use the old
> name server in the old /etc/resolv.conf.
>
> I tried nscd -i hosts but no effect.
>
> BTW, I have a lot of error of dbus cannot connect to the audit system, I
> am not sure it there is any relation.
>
> Thank you!
>

It might help to let us know exactly what you are doing, and what you
are trying to do. The changes you made and the commands being issued.
Hide the names and ip addresses if you want. /etc/resolv.conf is always
read, no reload is required. Overwriting as you already know will be
done by restarting networking. Any changes can be done by a script
called from /etc/rc.d/rc.local during startup. If you restart
networking, you must rerun the script to reapply the changes.

Ken

Scott Lurndal

unread,
Nov 1, 2005, 9:15:18 PM11/1/05
to


My guess is that he is not restarting his application after changing
/etc/resolv.conf and glibc is caching the older version.

scott

S P Arif Sahari Wibowo

unread,
Nov 2, 2005, 1:08:13 AM11/2/05
to
On Tue, 1 Nov 2005, ken wrote:
> It might help to let us know exactly what you are doing, and
> what you are trying to do. The changes you made and the
> commands being issued.

Ok, just simple. I want the gethostbyname use the name servers
received by the system from the dhcp server.

I start the network (which means the system get the IP and the
name servers from dhcp server, and put it in /etc/resolv.conf),
but gethostbyname won't use that name server. "host" will use
that name server without any issues. The gethostbyname will only
do name resolving with named run locally, and I don't want to
run named in this machine.

> /etc/resolv.conf is always read, no reload is required.

Well, apparently not.

> Overwriting as you already know will be done by restarting
> networking.

Restart networking will put new name server in /etc/resolv.conf,
which won't be used by gethostbyname.

--
(Stephan Paul) Arif Sahari Wibowo

S P Arif Sahari Wibowo

unread,
Nov 2, 2005, 1:18:43 AM11/2/05
to
On Tue, 1 Nov 2005, Bit Twister wrote:
> Two files which control resolution order are as follows:
>
> $ cat /etc/host.conf
> order hosts,bind
> multi on
> nospoof on
> spoofalert on
>
> $ grep hosts: /etc/nsswitch.conf
> hosts: files nisplus nis dns

$ grep "^[[:space:]]*hosts:" /etc/nsswitch.conf
hosts: files dns

The /etc/host.conf is exactly like yours.

> I have changed namesevers in /etc/resolv.conf and tried
> lookups with dig and it would use the new values without
> having to a service network restart.

dig works fine, as host and nslookup.

But calling gethostbyname goes nowhere, as also some program
that apparently use gethostbyname only, like pine, lftp, etc.

> No, idea why your code is not seeing the change. Guessing you
> could force a new read with the res_init() function prior to
> doing the gethostbyname.

Is that mean res_init() have side effect? So, just compile a
small program that just call res_init() and exit?

Thanks!

S P Arif Sahari Wibowo

unread,
Nov 2, 2005, 1:20:14 AM11/2/05
to
On Wed, 2 Nov 2005, Scott Lurndal wrote:
> My guess is that he is not restarting his application after
> changing /etc/resolv.conf and glibc is caching the older
> version.

Nope. The applications all started AFTER the new
/etc/resolv.conf established.

Robert Nichols

unread,
Nov 2, 2005, 12:56:50 PM11/2/05
to
In article <Pine.LNX.4.63.05...@localhost.localdomain>,
S P Arif Sahari Wibowo <arif...@yahoo.com> wrote:

:On Tue, 1 Nov 2005, ken wrote:
:> It might help to let us know exactly what you are doing, and
:> what you are trying to do. The changes you made and the
:> commands being issued.
:
:Ok, just simple. I want the gethostbyname use the name servers
:received by the system from the dhcp server.
:
:I start the network (which means the system get the IP and the
:name servers from dhcp server, and put it in /etc/resolv.conf),
:but gethostbyname won't use that name server. "host" will use
:that name server without any issues. The gethostbyname will only
:do name resolving with named run locally, and I don't want to
:run named in this machine.
:
:> /etc/resolv.conf is always read, no reload is required.
:
:Well, apparently not.
:
:> Overwriting as you already know will be done by restarting
:> networking.
:
:Restart networking will put new name server in /etc/resolv.conf,
:which won't be used by gethostbyname.

If you are running nscd (name service caching daemon) you might
want to read its manpage, paying particular attention to the
NOTES section.

--
Bob Nichols AT comcast.net I am "RNichols42"

Scott Lurndal

unread,
Nov 3, 2005, 5:55:43 PM11/3/05
to
S P Arif Sahari Wibowo <arif...@yahoo.com> writes:
>On Tue, 1 Nov 2005, ken wrote:
>> It might help to let us know exactly what you are doing, and
>> what you are trying to do. The changes you made and the
>> commands being issued.
>
>Ok, just simple. I want the gethostbyname use the name servers
>received by the system from the dhcp server.
>
>I start the network (which means the system get the IP and the
>name servers from dhcp server, and put it in /etc/resolv.conf),
>but gethostbyname won't use that name server. "host" will use
>that name server without any issues. The gethostbyname will only
>do name resolving with named run locally, and I don't want to
>run named in this machine.
>
>> /etc/resolv.conf is always read, no reload is required.
>
>Well, apparently not.

What what does the output of 'strace -f' on the
application which is calling gethostbyname show?

It should show an open of /etc/resolv.conf followed
sometime later by a 'sendmsg' to port 53 of the IP
address in your resolv.conf.

>
>> Overwriting as you already know will be done by restarting
>> networking.
>
>Restart networking will put new name server in /etc/resolv.conf,
>which won't be used by gethostbyname.

So either don't use DHCP to get your IP address, or modify
the /etc/dhclient.conf file to set your preferred name
server(s) and prefix.

man dhclient.conf

scott

0 new messages