2

In Android we have applications like daedalus which is a local VPN (Not remote) and used to change DNS quickly. I need such way in Ubuntu in order to change DNS whenever needed.

Do we have any way to create such VPN which doesn't make remote tunnel and just changes DNS? Or any other way to switch DNS servers as I need to switch my DNS frequently.

1
  • 1
    The only way to do this would be to run some type of DNS interception program locally that would then direct DNS elsewhere. I do this with a highly custom configured BIND9 instance, but its simple enough to restart the service after telling it where to forward DNS lookups to. (However, this setup isn't for the faint-hearted and requires Command Line changes and understanding what you're changing and then restarting the BIND9 service when you change the DNS servers in use)
    – Thomas Ward
    Dec 6, 2019 at 14:49

2 Answers 2

2

The possible way to do it is:

  1. Disable DNS cache (for example, this way https://tecadmin.net/disable-local-dns-caching-ubuntu/)

  2. Change your connection to "Automatic (addresses only)"

  3. Add your DNS and then change it.

Another way is to create your own local DNS which will redirect you to another one, set it as your default DNS and then just change setting of your local DNS. But it's not too easy.

In Android VPN is probably needed because you can't access network settings directly.

One more way is to do it with network-manager console client like this:

nmcli con modify eth0 +ipv4.dns 8.8.8.8 # add 8.8.8.8 to IPv4 DNS list servers
nmcli con modify eth0 -ipv4.dns 8.8.8.8 # remove 8.8.8.8 from list of DNS

Note: Replace eth0 by name of your network interface if needed.

You can also create bash aliases for these commands, appending following lines to ~/.bashrc

alias dns_add='nmcli con modify eth0 +ipv4.dns'
alias dns_rm='nmcli con modify eth0 -ipv4.dns'

And the use them like this:

$ dns_add 8.8.8.8
$ dns_rm 8.8.8.8
8
  • I understand what you say about changing DNS in network connection settings. Of course it needs to disable automatic DNS in order to set it to your prefer one. I need to switch DNS because I need it frequently. It would be appreciated if you could give a more specific answer to switch DNS. Dec 6, 2019 at 14:54
  • Do you need to switch it to certain addresses, or to some public servers? Dec 6, 2019 at 14:57
  • certain addresses. Dec 6, 2019 at 14:58
  • Well, maybe it's possible to write a script that will change the /etc/resolv.conf and make it easy to use. Dec 6, 2019 at 15:01
  • You are right. I tested it and worked. If you could give such script or two scripts to switch DNS in this way, It would be the correct answer. Dec 6, 2019 at 15:05
0

I did it this way:

/bin/dnsme:

#!/bin/bash
sudo cp /etc/resolv.conf /etc/resolv-original.conf
sudo cp /etc/resolv-dnsme.conf /etc/resolv.conf

/bin/undnsme:

#!/bin/bash
sudo cp /etc/resolv-original.conf /etc/resolv.conf

in /etc/resolv-dnsme.conf:

nameserver x.x.x.x
nameserver x.x.x.x
options edns0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .