Difference between revisions of "Resolv.conf"

From ArchWiki
Jump to: navigation, search
m (Preserve DNS settings)
Line 6: Line 6:
 
==Preserve DNS settings==
 
==Preserve DNS settings==
  
Dhcpcd, NetworkManager, and various other processes can overwrite {{Filename|/etc/resolv.conf}}.  This is usually desirable behavior, but sometimes DNS settings need to be set manually (e.g. when using a static IP).  When using dhcpcd, you can prevent your nameservers from being lost by creating a file called {{Filename|/etc/resolv.conf.head}} containing your DNS servers. Dhcpcd will prepend this file to the beginning of resolv.conf.   An example {{Filename|/etc/resolv.conf.head}} for someone using OpenDNS would be:
+
Dhcpcd, NetworkManager, and various other processes can overwrite {{Filename|/etc/resolv.conf}}.  This is usually desirable behavior, but sometimes DNS settings need to be set manually (e.g. when using a static IP).  There are several ways to accomplish this. If you are using NetworkManager, see [http://bbs.archlinux.org/viewtopic.php?id=45394 this thread] on how to prevent it from overriding your resolv.conf.
  
  # First OpenDNS server
+
===Use resolv.conf.head===
 +
You can prevent your nameservers from being lost by creating a file called {{Filename|/etc/resolv.conf.head}} containing your DNS servers.  Dhcpcd will prepend this file to the beginning of resolv.conf.  An example {{Filename|/etc/resolv.conf.head}} for someone using OpenDNS would be:
 +
 
 +
  # OpenDNS servers
 
  nameserver 208.67.222.222
 
  nameserver 208.67.222.222
# Second OpenDNS server
 
 
  nameserver 208.67.220.220
 
  nameserver 208.67.220.220
  
Alternatively, dhcpcd's configurations file may be edited to prevent the dhcpcd daemon from overwriting the ({{Filename|/etc/resolv.conf}}).  To do this, you will need to modify the {{Filename|/etc/conf.d/dhcpcd}} configuration.  For example:
+
===Modify the dhcpcd Config===
 +
Alternatively, dhcpcd's configuration file may be edited to prevent the dhcpcd daemon from overwriting the ({{Filename|/etc/resolv.conf}}).  To do this, you will need to modify the {{Filename|/etc/conf.d/dhcpcd}} configuration.  For example:
  
 
  # Arguments to be passed to the DHCP client daemon
 
  # Arguments to be passed to the DHCP client daemon
Line 19: Line 22:
 
  DHCPCD_ARGS="-C resolv.conf -q"
 
  DHCPCD_ARGS="-C resolv.conf -q"
  
 +
If the above does not work, use the full filename of the script (found in {{Filename|/usr/lib/dhcpcd/dhcpcd-hooks}}) instead:
 +
DHCPCD_ARGS="-C 20-resolv.conf -q"
 +
 +
===Write-protect resolv.conf===
 
Another way to protect your resolv.conf from being edited by anything is setting the write-protection attribute:
 
Another way to protect your resolv.conf from being edited by anything is setting the write-protection attribute:
 
  chattr +i /etc/resolv.conf
 
  chattr +i /etc/resolv.conf
 
If you are using NetworkManager, see [http://bbs.archlinux.org/viewtopic.php?id=45394 here] how to prevent it from overriding your resolv.conf.
 

Revision as of 17:04, 22 April 2010

The resolver is a set of routines in the C library that provide access to the Internet Domain Name System (DNS). The resolver configuration file contains information that is read by the resolver routines the first time they are invoked by a process. The file is designed to be human readable and contains a list of keywords with values that provide various types of resolver information.

On a normally configured system this file should not be necessary. The only name server to be queried will be on the local machine; the domain name is determined from the host name and the domain search path is constructed from the domain name.

Preserve DNS settings

Dhcpcd, NetworkManager, and various other processes can overwrite Template:Filename. This is usually desirable behavior, but sometimes DNS settings need to be set manually (e.g. when using a static IP). There are several ways to accomplish this. If you are using NetworkManager, see this thread on how to prevent it from overriding your resolv.conf.

Use resolv.conf.head

You can prevent your nameservers from being lost by creating a file called Template:Filename containing your DNS servers. Dhcpcd will prepend this file to the beginning of resolv.conf. An example Template:Filename for someone using OpenDNS would be:

# OpenDNS servers
nameserver 208.67.222.222
nameserver 208.67.220.220

Modify the dhcpcd Config

Alternatively, dhcpcd's configuration file may be edited to prevent the dhcpcd daemon from overwriting the (Template:Filename). To do this, you will need to modify the Template:Filename configuration. For example:

# Arguments to be passed to the DHCP client daemon
# DHCPCD_ARGS="-q"
DHCPCD_ARGS="-C resolv.conf -q"

If the above does not work, use the full filename of the script (found in Template:Filename) instead:

DHCPCD_ARGS="-C 20-resolv.conf -q"

Write-protect resolv.conf

Another way to protect your resolv.conf from being edited by anything is setting the write-protection attribute:

chattr +i /etc/resolv.conf