How to Configure Static DNS on CentOS/Redhat/Fedora Linux Systems

undefined

If you want to hard-code DNS servers to use on CentOS or Fedora, the method can differ, depending on whether you use Network Manager or network service. On RHEL based systems, Network Manager is used to manage network interfaces by default, while you can switch to network service.

Configure static DNS with Network Manager

  • If you are using Network Manager, you can configure static DNS as follows:

In case of DHCP, choose “Automatic (DHCP) addresses only” method, so that your DHCP server cannot override your DNS setting. Then in the “DNS servers” field, enter a comma separate list of DNS servers to use (e.g., 8.8.8.8 and 8.8.4.4).

static_dns1

  • If you use a static IP address, simply enter your DNS servers in the “DNS servers” field as follows:

static_dns2

Configure static DNS in /etc/sysconfig/network-scripts/ifcfg-ethX

If you disabled Network Manager, but use network service instead, you can use interface configuration files (e.g., /etc/sysconfig/network-scripts/ifcfg-eth0) to specify static DNS. In this case, there are actually two options to do it.

Hints:

1. Any modifications in the network interface file will need restarting the network service.

2. If you used any option from the below two options, then restart your network service after editing the interface file.
  • Option One

Use “PEERDNS=no”. This option will prevent /etc/resolv.conf from being modified by a DHCP server. So instead of using DHCP-provided DNS, you can specify any arbitrary DNS servers you want to use in /etc/resolv.conf.

The configuration file for your network interface (e.g., eth0) looks like the following.

# vim /etc/sysconfig/network-scripts/ifcfg-eth0
And add peerdns=no as follows:
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
PEERDNS=no

Then, add static DNS to /etc/resolv.conf

# vim /etc/resolv.conf
Add the following two global dns servers:
nameserver 8.8.8.8
nameserver 8.8.4.4
  • Option Two

Alternatively, you can specify DNS servers directly in the interface configuration file, instead of modifying /etc/resolv.conf yourself. That is:

# vim /etc/sysconfig/network-scripts/ifcfg-eth0
Append the two dns server to the end of your network interface file as follows:
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
DNS1=8.8.8.8
DNS2=8.8.4.4

The DNS servers specified with “DNS1/DNS2” directives will then automatically be added to /etc/resolv.conf when the interface is activated. So there is no need to modify /etc/resolv.conf yourself.

The above two methods can be applied similarly to a static IP address case. That is:

DEVICE=eth0
BOOTPROTO=manual
ONBOOT=yes
IPADDR=10.0.1.27
NETWORK=10.0.1.0
NETMASK=255.255.255.0
PEERDNS=no  (then add DNS to /etc/resolv.conf)

Or:

DEVICE=eth0
BOOTPROTO=manual
ONBOOT=yes
IPADDR=10.0.1.27
NETWORK=10.0.1.0
NETMASK=255.255.255.0
DNS1=8.8.8.8
DNS2=8.8.4.4

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

Your email address will not be published. Required fields are marked *