NOTICE: Rackspace Engineers will be performing a scheduled maintenance on the infrastructure for and on October 23, 2018 and October 24, 2018. During this maintenance, both sites will be down for a few hours between 10:00 PM CDT and 8:00 AM CDT, and customers will not be able to access the How-To or the API documentation. If you have any questions or concerns in regard to this maintenance, please do not hesitate to contact a member of our support team.

Change DNS settings on Linux

  • Last updated on: 2016-08-17
  • Authored by: Jered Heeschen

You might need to change your server’s DNS settings, either because you find that they are misconfigured or because you want to use your own. This article describes how to change your server’s DNS settings.

Add name servers to the configuration file

On Linux, the DNS servers that the system uses for name resolution are defined in the /etc/resolv.conf file. That file should contain at least one nameserver line. Each nameserver line defines a DNS server. The name servers are prioritized in the order the system finds them in the file. Use the IP addresses of the name servers when entering them, because the system won’t know what to do with domain names until after it knows how to get to the DNS servers.

  1. Open the resolv.conf file with an editor, such as nano, to make the necessary changes (if it doesn’t exist already, this command creates the file):

    sudo nano /etc/resolv.conf

  2. Add lines for the name servers that you want to use. The following table displays which name server IP addresses to use depending on which datacenter houses your cloud servers. The “Name server IP address” column shows the lines to add to the configuration file:

    Data center Name server IP address
    Hong Kong (HKG) nameserver
    Northern Virginia (IAD) nameserver
    London (LON) nameserver
    Chicago (ORD) nameserver
    Dallas/Fort Worth (DFW) nameserver
    Sydney (SYD) nameserver
  3. Save the file.

  4. To ensure that your new settings are working, ping the domain name:

    ping -c 3

You should see a result similar to the following one:

PING ( 56(84) bytes of data.
64 bytes from icmp_req=1 ttl=249 time=25.3 ms
64 bytes from icmp_req=2 ttl=249 time=25.2 ms
64 bytes from icmp_req=3 ttl=249 time=25.2 ms

--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 25.236/25.292/25.392/0.147 ms

If you receive an unknown host message, double-check the IP addresses that you set as your DNS servers.

Add same servers with IPv6 addresses

If you’re using IPv6 on your server, you might need to add the IPv6 addresses of your name servers to the resolv.conf file. You can see if a DNS server has an IPv6 address by performing the following steps:

  1. Use host to get the name of the server:

    $ host domain name pointer
  2. Use the domain name you got back in another host lookup:

    $ host has address has IPv6 address 2001:4800:d::1

If an IPv6 address is returned, you can add that as another nameserver line in the resolv.conf file, as follows:

nameserver 2001:4800:d::1

Then test as previously shown, by using the ping6 command instead of the regular ping command to force the system to use IPv6.

Continue the conversation in the Rackspace Community.