How to change DNS nameserver for CoreOS?

September 19, 2014 6k views
bryantluk
By:
bryantluk

Hi,

I'm using the CoreOS image for my droplet. Is there any way to change which DNS name server is used? I would actually like to use consul.io for service lookup and have it fallback to the Google DNS servers.

1 Answer

On CoreOS, /etc/resolve.conf is managed by systemd. One way to append to it would be to use the cloud-config metadata to add a new systemd unit file. Something like:

#cloud-config
coreos:
  etcd:
    # generate a new token for each unique cluster from https://discovery.etcd.io/new
    discovery: https://discovery.etcd.io/[your-token-here]
    # multi-region deployments, multi-cloud deployments, and droplets without
    # private networking need to use $public_ipv4
    addr: $private_ipv4:4001
    peer-addr: $private_ipv4:7001
  fleet:
    public-ip: $private_ipv4   # used for fleetctl ssh command
  units:
    - name: etcd.service
      command: start
    - name: fleet.service
      command: start
      units:
    - name: nameservers.network
      content: |
        [Network]
        DNS=8.8.4.4
        DNS=8.8.8.8
  • Thanks. While I can append entries to the nameservers list, I don't think it guarantees usage. I guess I would really like to replace the nameservers used entirely.

Have another answer? Share your knowledge.