Skip to content

How to Change DNS on Enterprise Linux 6.5

If you want to change NameServer in your running Linux, you might consider to modify /etc/resolv.conf. Yes, it could be the right way to do it before version 6, but it's not the case as of the version 6.

You have two ways to change DNS
  1. Modify the directive DNS1 directly in the interface configuration file, the configuration will reflect its DNS settings to /etc/resolv.conf after service network restart.
  2. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    TYPE=Ethernet
    UUID= ...
    ONBOOT=yes
    NM_CONTROLLED=yes
    BOOTPROTO=none
    HWADDR= ...
    IPADDR=10.12.13.123
    PREFIX=8
    GATEWAY=10.0.0.1
    DNS1=168.95.1.1
    #DNS1=8.8.8.8
    DOMAIN=example.com
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=yes
    IPV6INIT=no
    NAME="System eth0"

  3. Set the directive PEERDNS explicitly to no in the interface configuration file, and then modify /etc/resolv.conf
  4. [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
    ...
    NAME="System eth0"
    PEERDNS=no
    [root@localhost ~]# vi /etc/resolv.conf
    nameserver 168.95.1.1
    search example.com

    Setting PEERDNS=no explicitly can make NIC configuration stop reflecting its settings (e.g. DNS and Search Domain) to /etc/resolv.conf, therefore, /etc/resolv.conf can be persistent after reboots. You may refer to Red Hat documentation for more about the directive PEERDNS at:
    9.2. Interface Configuration Files

    Here is the quote:
    PEERDNS=answer
        where answer is one of the following:
        yes — Modify /etc/resolv.conf if the DNS directive is set. If using DHCP, then yes is the default.
        no — Do not modify /etc/resolv.conf.
Don't forget to restart the network service after any changes.
[root@localhost ~]# service network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Determining if ip address 10.12.13.123 is already in use for device eth0...
                                                           [  OK  ]

Further reading -How to Change HostName on Enterprise Linux 6.5

Leave a Reply

Your email address will not be published.