Pazar, Aralık 22, 2024

Specify a Different Nameserver in /etc/resolv.conf When Using DHCP in CentOS 7

yüksek çözünürlüklü centos işletim sistemi logosu

Using dhcp within a ifcfg network configuration file you may want to specify a different nameserver instead of using the nameserver assigned by the DHCP server.

Use the PEERDNS, DNS1 and DNS2 options.

DEVICE="ck"
BOOTPROTO="dhcp"
ONBOOT="yes"
TYPE="Ethernet"
PEERDNS="yes"
DNS1="1.1.1.1"
DNS2="1.0.0.1"

To check that it all works grep ^nameserver /etc/resolv.conf

nameserver 1.1.1.1
nameserver 1.0.0.1

If you want to use the nameservers that are provided by DHCP server but also specify an extra nameserver within your /etc/resolv.conf, you can make use of dhclient.conf options in /etc/dhcp/dhclient-em1.cfg

prepend domain-name-servers 1.0.0.1;