0

I need to prepend my /etc/resolv.conf with an entry. My interface is enp0s3. So I created /etc/dhcp/dhclient-enp0s3.conf and added the line:

prepend domain-name-servers 127.0.0.2

When I restart the CentOS VM, the NetworkManager automatically creates this file: /var/lib/NetworkManager/dhclient-enp0s3.conf

When I cat that I can see that my dhclient-enp0s3.conf file in /etc/dhcp IS being read properly:

[root@localhost network-scripts]# cat /var/lib/NetworkManager/dhclient-enp0s3.conf
# Created by NetworkManager
# Merged from /etc/dhcp/dhclient-enp0s3.conf

prepend domain-name-servers 127.0.0.2

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
option ms-classless-static-routes code 249 = array of unsigned integer 8;
option wpad code 252 = string;

also request rfc3442-classless-static-routes;
also request ms-classless-static-routes;
also request static-routes;
also request wpad;
also request ntp-servers;

However, when I cat /etc/resolv.conf, the prepended nameserver doesn't appear anywhere. I also ran dig just to test if my internal hostnames would resolve properly, but they don't.

Since the NetworkManager config appears to be generated, where do I go from here?

3
  • Thank you for the edits @cas. Thanks to your edit, I looked at the markup and learned how to do some of it properly! (Now if I knew how to reference your username properly. :)
    – alfreema
    Aug 14, 2017 at 1:55
  • 1
    for code and command/file names etc use either backticks or the {} icon in the editor (the latter especially for multi-line blocks of code - or just indent each line by four spaces). @cas works. sorry i can't help with your actual question - my attitude to networkmanager, resolvconf and other things that mess with my hand-crafted configs is apt-get purge with the --nuke-from-orbit-its-the-only-way-to-be-sure option :).
    – cas
    Aug 14, 2017 at 2:22
  • hahaha ... yeah for an old skool guy like me its painful to learn the new way
    – alfreema
    Aug 14, 2017 at 3:31

1 Answer 1

5

Config statements in dhclient.conf (and other dhcp config files) must be terminated with a semicolon.

So prepend domain-name-servers 127.0.0.2; should do the trick.

3
  • Bingo! This indeed did the trick.
    – alfreema
    Aug 14, 2017 at 18:03
  • 3
    Can you do the following? prepend domain-name-servers 8.8.8.8, 8.8.4.4;. A simple yes or no will do for me! :)
    – Fiddy Bux
    Jan 25, 2019 at 22:58
  • 1
    If you have multiple ips, you can add multiple "prepend domain-name-servers" lines
    – Nico Toub
    Sep 22, 2021 at 12:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .