How to Set DNS to 8.8.8.8 in Linux?


How to Set DNS to 8.8.8.8 in Linux?

In the vast realm of Linux, configuring DNS settings is a routine task for users seeking optimal internet connectivity. One popular DNS option is Google's public DNS server, which is easily accessible via the IP address 8.8.8.8. This article will guide you through the process of setting your DNS to 8.8.8.8 in a Linux environment, ensuring a smooth and efficient browsing experience.

  1. Check Current DNS Settings:
    Before making any changes, it's prudent to check your current DNS settings. Open a terminal and enter the following command:

    cat /etc/resolv.conf

    This will display your current DNS configuration.

  2. Backup Your Current DNS Configuration:
    While making changes, it's a good practice to create a backup. You can use the 'cp' command to duplicate your existing resolv.conf file:

    sudo cp /etc/resolv.conf /etc/resolv.conf.backup
  3. Edit the resolv.conf File:
    To set the DNS to 8.8.8.8, open the resolv.conf file in a text editor. We'll use nano in this example:

    sudo nano /etc/resolv.conf
  4. Update DNS Configuration:
    In the resolv.conf file, locate the line starting with 'nameserver' and replace the existing IP address with 8.8.8.8:

    nameserver 8.8.8.8

    Save the changes and exit the text editor.

  5. Verify the Changes:
    Confirm that the changes have taken effect by once again using the 'cat' command on the resolv.conf file:

    cat /etc/resolv.conf
  6. Restart Networking Services:
    For the changes to be applied, restart your networking services. The exact command may vary based on your Linux distribution:

    • For systems using systemd:
      sudo systemctl restart NetworkManager
    • For systems using init.d:
      sudo service networking restart

More Examples:

  • Using NetworkManager Command Line Interface (nmcli):
    If you prefer a command-line approach, you can use 'nmcli' to modify your DNS settings:

    sudo nmcli con mod <connection-name> ipv4.dns "8.8.8.8"
  • Setting DNS in Ubuntu:
    Ubuntu users can also update the DNS settings via the network configuration file:

    sudo nano /etc/network/interfaces

    Add the following line:

    dns-nameservers 8.8.8.8

Related Searches and Questions asked:

  • What is the Best DNS for Linux?
  • What is the DNS Configuration File and How to Edit It?
  • Setting Up a Linux DNS Server on Ubuntu
  • What is an Example of DNS Server Software?
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.