Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have Gentoo Linux amd64 installed on one of my computers. I have a static IP configured at /etc/conf.d/net:

auto_eth0="true"
config_eth0="192.168.1.2/24"
routes_eth0="default via 192.168.1.1"
enable_ipv6_eth0="false"

I manually edited /etc/resolv.conf and added google dns servers. the problem is that whenever I restart my server /etc/resolv.conf gets wiped out. I tired setting 'chmod a-w /etc/resolv.conf' and it didn't work but i actually don't really like that method anyhow.

how can I let gentoo know that I don't want /etc/resolv.conf to be modified ?

thanks!

share|improve this question
add comment

5 Answers

The right way to do this these days is, I believe, to add the DNS information to your /etc/conf.d/net file, so that the rc scripts manage your /etc/resolv.conf file correctly.

Add:

dns_servers="8.8.8.8 8.8.4.4"

to that file and you should be good to go. If you need other resolver settings, look at the net.example file in /usr/share/doc/openrc-*/. Some of the available settings:

dns_domain
dns_search
dns_options
dns_sortlist
share|improve this answer
add comment

Try:

chattr +i /etc/resolv.conf

If you will ever need to change resolv.conf just remove immutable flag by:

chattr -i /etc/resolv.conf
share|improve this answer
    
While this might prevent whatever process overwriting this file it does not really address the root of the issue. @Mat's answer seems to be the better approach. –  Bram May 20 '12 at 9:28
    
That's true, @Mat's approach is better. –  mzmultics May 20 '12 at 9:38
add comment

Gentoo requires that DNS configuration be added to /etc/conf.d/net in order to be retained after a reboot. Your net file would look something like this:

config_eth0="192.168.1.2/24"
routes_eth0="default via 192.168.1.1"
dns_servers_eth0="8.8.8.8 8.8.4.4"

Similarly, if you wish to specify an interface-independant DNS server (ie. this setting will apply for all interfaces) you can simply use the dns_servers directive, without appending the interface:

config_eth0="192.168.1.2/24"
routes_eth0="default via 192.168.1.1"

dns_servers="8.8.8.8 8.8.4.4"
share|improve this answer
add comment

You can add:

dhcp_eth0="nodns"

to your /etc/conf.d/net to prevent overwriting /etc/resolv.conf

share|improve this answer
add comment

In Debian Linux your DNS servers change after a reboot.

  1. Edit the /etc/resolv.conf file

    nameserver ...........
    nameserver ..........
    search  domainname
    

    save and exit.

  2. /etc/init.d/networking restart

  3. chattr +i /etc/resolv.conf

  4. Reboot system

share|improve this answer
    
it's working.............. –  Nitin Jun 26 '12 at 12:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.