Naujiena sandėlyje: Momentinio paruošimo Bare Metal tipo serveriai jau Nyderlanduose! Užsisakykite dabar.

Žinynas

How to set Google DNS in a Linux dedicated server? Spausdinti

  • dedicated server
  • 11

Setting up Google DNS on your dedicated Linux server can help improve your server's DNS resolution speed and reliability. Google’s DNS servers are known for their speed, security, and uptime, making them a popular choice among server administrators. This guide will walk you through the steps to configure Google DNS on your Linux-based dedicated server.

Prerequisites

- A dedicated server running a Linux-based operating system (e.g., Ubuntu, CentOS, Debian).
- SSH access to the server with root or sudo privileges.

Step 1: Access Your Server via SSH

1. Open your preferred terminal application.
2. Connect to your dedicated Linux server using SSH. Replace `username` with your actual username and `server_ip` with the IP address of your server:


ssh username@server_ip

3. Enter your password when prompted.

Step 2: Backup Your Current DNS Configuration

Before making any changes, it's always a good idea to back up your current DNS configuration file. This allows you to revert to the original settings if needed.

1. Navigate to the `/etc` directory:


cd /etc

2. Make a backup of the current `resolv.conf` file:


sudo cp resolv.conf resolv.conf.backup

Step 3: Edit the resolv.conf File

The `resolv.conf` file is where DNS servers are configured in Linux. To set Google DNS, you’ll need to edit this file.

1. Open the `resolv.conf` file in a text editor (e.g., `nano` or `vim`):


sudo nano /etc/resolv.conf

2. Remove or comment out the existing `nameserver` lines by adding a `#` at the beginning of each line. This step is optional but recommended if you want to use only Google DNS.

3. Add the following lines to set Google DNS:


nameserver 8.8.8.8
nameserver 8.8.4.4

- `8.8.8.8` and `8.8.4.4` are the IP addresses of Google’s primary and secondary DNS servers, respectively.

4. Save and exit the editor:
- If using `nano`, press `CTRL + X`, then `Y` to confirm changes, and press `Enter`.
- If using `vim`, press `ESC`, type `:wq`, and press `Enter`.

Step 4: Prevent resolv.conf from Being Overwritten (Optional)

Some Linux distributions and network management services (like `dhclient` or `NetworkManager`) might overwrite the `resolv.conf` file after a reboot or network restart. To prevent this, you can make the file immutable:

1. Make the `resolv.conf` file immutable:


sudo chattr +i /etc/resolv.conf

This command prevents any changes to the file until you explicitly allow them by removing the immutable attribute.

Step 5: Test the DNS Configuration

After configuring Google DNS, it's important to test if the new settings are working correctly.

1. Use the `dig` or `nslookup` command to query a domain and check if the DNS resolution is working properly:


dig google.com

or


nslookup google.com

If the command returns an IP address for the domain, the DNS configuration is successful.

Step 6: (Optional) Revert Changes

If you encounter issues after setting Google DNS or need to revert to your original settings, you can restore the backup:

1. Replace the modified `resolv.conf` with the backup:


sudo cp /etc/resolv.conf.backup /etc/resolv.conf

2. If you made the `resolv.conf` file immutable, make it mutable again:


sudo chattr -i /etc/resolv.conf

Conclusion

By following these steps, you have successfully configured Google DNS on your dedicated Linux server. This setup can improve your server's DNS lookup times and overall performance. Remember to test your configuration and monitor your server to ensure everything is working as expected. If you encounter any issues, you can always revert to your previous DNS settings using the backup you created.


Ar šis atsakymas buvo naudingas?

« Atgal