LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Preventing /etc/resolv.conf from bring overwitten (https://www.linuxquestions.org/questions/slackware-14/preventing-etc-resolv-conf-from-bring-overwitten-649862/)

harryhaller 06-17-2008 06:33 AM

Preventing /etc/resolv.conf from bring overwitten
 
This is the way I believe it should be done:

change /etc/dhclient.conf by adding following:

Code:

interface "eth0" {
prepend domain-name-servers 208.67.222.222 208.67.220.220;
}

didn't work - still used old dns. I thought this saved adding DNS to resolv.conf - and thus fiddling about with it being over-written.

I then changed /etc/rc.d/rc.inet1.conf

Code:

DHCP_KEEPRESOLV[0]="yes"
This resulted in a new resolv.conf being created with no DNS addresses but "search org".

I then improvised. I added the DNS servers to resolv.conf and made it READ-ONLY (0444).

This now works. But surely this is NOT the correct way to do it?

I did not reverse the above changes - but it seems to me that that instead of changing those configuration files, I could have just made resolv.conf read-only in the first place.

What is the correct and orthodox way to add a DNS to the system?

I have a conventional desktop system connected via dhcp and it seems that my IP address is fixed.

houdelou 06-17-2008 07:24 AM

When you specified DHCP_KEEP_RESOLVED="yes", did you try to add your DNS after the new resolv.conf file was created with only search in it?

If yes, one thing you could try is add the -R parameter to the dhcpcd call in rc.inet1 or wherever it is called. This parameter prevent this file to be overwritten.

zQUEz 06-17-2008 07:28 AM

Not sure about slackware type systems, but on Fedora/Red Hat systems you can add an option to the ifcfg-ethx file:
PEERDNS=no
This prevents /etc/resolv.conf being updated.

harryhaller 06-17-2008 08:11 AM

Quote:

Originally Posted by houdelou (Post 3187270)
When you specified DHCP_KEEP_RESOLVED="yes", did you try to add your DNS after the new resolv.conf file was created with only search in it?

No - I went straight on to add the dns and made it read-only.

I've now just changed it back to r/w and rebooted - everything's fine.

It wasn't over-written.

So I should have done an extra re-boot, it seems.


Quote:

Originally Posted by houdelou (Post 3187270)
If yes, one thing you could try is add the -R parameter to the dhcpcd call in rc.inet1 or wherever it is called. This parameter prevent this file to be overwritten.

According to rc.inet1 that is what DHCP_KEEPRESOLV[0]="yes" in /etc/rc.d/rc.inet1.conf does:

Code:

# Get the configuration information from /etc/rc.d/rc.inet1.conf:
. /etc/rc.d/rc.inet1.conf

Code:

        [ "${DHCP_KEEPRESOLV[$i]}" = "yes" ] && DHCP_OPTIONS="$DHCP_OPTIONS -R"
Code:

        /sbin/dhcpcd -d -t ${DHCP_TIMEOUT[$i]:-30} ${DHCP_OPTIONS} ${1}

Thanks houdelou, I have it now set up in an orthodox manner. I can't understand why it produced a rogue resolv.conf beforehand though.

harryhaller 06-17-2008 10:09 AM

Which DNS is really being used?
 
Is there anyway to tell which DNS is being used?

/etc/dhcpc/dhcpcd-eth0.info does not show the new dns which I added, just the old ones (which are still in resolv.conf together with, but after, the new ones).

Also:

Do I still need the addition I made to /etc/dhclient.conf?

This contains the "prepend domain-name-servers" value.

This isn't about "what works" but what should work - i.e. what is the correct way of setting things up.

houdelou 06-17-2008 10:36 AM

I'm not an experienced net admin so I can't tell you the normal way to do this. But I will try to do my best to help you and from what I know, you are on the good track. But it is not a usual problem because when you use DHCP, normally, it does all the work and you don't touch it.

Maybe you could try supersede instead of prepend in your dhclient.conf. Look in man dhclient.conf to know what it does. If this works, maybe you won't need DHCP_KEEPRESOLV. What I would try first is to comment the DHCP_KEEPRESOLV line, add the supersede instead of prepend and restart network services.

According to man resolv.conf the dns are tried in the order listed beginning with the first one.

To know wich dns is being used, but that can vary with each query, you can use the dig command. Look at the adress after SERVER:. There should be an adress with #53 at the end. #53 means port 53 wich is dns service port.

One trick I can give you is that instead of rebooting, try doing /etc/rc.d/inet1 restart. I think it restart all the network processes.


All times are GMT -5. The time now is 10:53 PM.