How can I easily switch DNS settings on Linux without manual configuration?

0
4
Asked By CuriousCat42 On

I'm looking for a simple way to change my DNS settings on the fly. I live in Bangladesh, where the internet isn't great—my base speed is only 2.5 MB/s. My ISP provides a DNS that routes to cached servers for better speeds on certain sites. I usually use Cloudflare DNS for everything, but I want to be able to switch between these DNS servers easily. Manually editing the `/etc/resolv.conf` file is a hassle, and I don't want systemd to overwrite it. Any tips or methods that could help?

2 Answers

Answered By TechWhiz99 On

One way to switch your DNS without diving into the config files every time is to create a script. You could set up a script like `~/switchdns.sh` that swaps your `resolv.conf` file between different DNS setups. For instance, you could use a couple of commands to move the files around like so:

```bash
mv /etc/resolv.conf /etc/resolv.conf.old
mv /etc/resolv.conf.alt /etc/resolv.conf
mv /etc/resolv.conf.old /etc/resolv.conf.alt
```

It’s a bit of a janky workaround, but it does the trick! There might be smoother solutions out there, but this is a quick fix you can try out.

QuickFixMaster -

That's actually a clever idea! Just make sure the script is executable, and you should be good to go. Plus, you can assign it a keyboard shortcut for even faster access!

Answered By LinuxGuru88 On

Also, you might want to mention your Linux distribution. Different distros handle DNS setups in their own ways, and knowing which one you're using could help others provide better advice. For example, some users might have perfect solutions for Arch, while others might find it tricky on Ubuntu or Fedora.

CuriousCat42 -

Ah, I'm on Arch! That might explain some things. Thanks for the tip!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.