Change DNS servers, wifi and mobile data
-
Looking on the forum I found how to change the DNS servers only for the wifi networks but I wanted to choose the servers also for mobile data ... I created a script to set up alternate DNS servers / restore original settings.
This script makes a file immutable (chattr +i) and this may cause the OTA update to fail, so before the update OTA 23 I have restored the original settings.
- nano /home/phablet/your_path/setdns.sh
and make it executable (chmod u+x)
#!/bin/bash # Make sure only root can run this script if [ "$(id -u)" != "0" ]; then echo " Must be run as root, you must prepend sudo !" 1>&2 exit 1 fi echo -e '\n - You can set up alternate DNS servers / restore original settings -\n' ; # # these are Cloudflare's DNS servers, you can change them with your preferred dns_one=1.1.1.1 dns_two=1.0.0.1 PS3='Please enter your choice : ' options=("Set new DNS servers" "Roll back your system" "Quit") select opt in "${options[@]}" do case $opt in "Set new DNS servers") if grep -qs 'dns=dnsmasq' /etc/NetworkManager/NetworkManager.conf then echo -e '\n Remember to "roll back" your system before the next OTA update !\n' ; # mount root in read/write mode mount -o remount,rw / ; # remove /etc/resolv.conf (is a symbolic link pointing to /run/resolvconf/resolv.conf) rm /etc/resolv.conf ; # create /etc/resolv.conf touch /etc/resolv.conf ; # add it your DNS servers echo -e "nameserver $dns_one\nnameserver $dns_two" >> /etc/resolv.conf ; # set permission chmod 644 /etc/resolv.conf ; # make it immutable chattr +i /etc/resolv.conf ; # replace dns=dnsmasq with dns=none in NetworkManager conf file sed -i 's/dns=dnsmasq/dns=none/' /etc/NetworkManager/NetworkManager.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e ' Done, DNS servers are set up !\n' exit 0 else echo -e '\n Remember to "roll back" your system before the next OTA update !\n' ; # mount root in read/write mode mount -o remount,rw / ; # makes /etc/resolv.conf writable/erasable chattr -i /etc/resolv.conf ; # add it your DNS servers echo -e "nameserver $dns_one\nnameserver $dns_two" > /etc/resolv.conf ; # make it immutable chattr +i /etc/resolv.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e ' Done, DNS servers are set up !\n' exit 0 fi ;; "Roll back your system") # mount root in read/write mode mount -o remount,rw / ; # makes /etc/resolv.conf writable/erasable chattr -i /etc/resolv.conf ; # remove it rm /etc/resolv.conf ; # recreate original simbolic link ln -s /run/resolvconf/resolv.conf /etc/resolv.conf ; # replace dns=none with dns=dnsmasq in NetworkManager conf file sed -i 's/dns=none/dns=dnsmasq/' /etc/NetworkManager/NetworkManager.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Done, DNS settings restored, reboot your device !\n' exit 0 ;; "Quit") break ;; *) echo "invalid option $REPLY" ;; esac done
this script sets the Cloudflare's DNS servers, before running it you can change them with your preferred.
- cd /home/phablet/your_path
sudo ./setdns.sh
- You can check the DNS server used here
- nano /home/phablet/your_path/setdns.sh
-
-
-
--------- UPDATE ---------
New version to install/uninstall with single command, see here for further information.You can set alternative dns servers and restore the default settings in an easy way, reboot not required.
You can switch between two preset providers or enter the one you prefer.
three steps :
1 - download (just click) set-dns.1.01.tar.gz from here
2 - open file manager, go to Downloads, click set-dns.1.01.tar.gz and extract archive
3 - open terminal and type :
sudo Downloads/set-dns.1.01/setdns.sh
You will see this :
type 1 to set Cloudflare servers
type 2 to set OpenDNS servers
type 3 to set your preferred servers (*)
type 4 to restore default settings (Restore OS)
type 5 to exit (OS unchanged)Remember to "Restore OS" before the next OTA update !
Preview :
#!/bin/bash # Make sure only root can run this script if [ "$(id -u)" != "0" ]; then echo " - You must prepend 'sudo' !" 1>&2 exit 1 fi echo -e '\n- Set DNS servers / Restore default -\n' ; # these are Cloudflare's DNS servers CLF_one=1.1.1.1 CLF_two=1.0.0.1 # these are OpenDNS servers OPE_one=208.67.222.222 OPE_two=208.67.220.220 PS3=' Please enter your choice : ' options=(" Cloudflare" " OpenDNS" " Custom DNS" " Restore OS" " Quit") select opt in "${options[@]}" do case $opt in " Cloudflare") # search the default string if grep -qs 'dns=dnsmasq' /etc/NetworkManager/NetworkManager.conf then # -------------------- runs if found default dns settings -------------------- # mount root in read/write mode mount -o remount,rw / ; # remove /etc/resolv.conf (is a symbolic link pointing to /run/resolvconf/resolv.conf) rm /etc/resolv.conf ; # create /etc/resolv.conf touch /etc/resolv.conf ; # add it Cloudflare servers echo -e "nameserver $CLF_one\nnameserver $CLF_two" >> /etc/resolv.conf ; # set permission chmod 644 /etc/resolv.conf ; # make it immutable chattr +i /etc/resolv.conf ; # replace dns=dnsmasq with dns=none in NetworkManager conf file sed -i 's/dns=dnsmasq/dns=none/' /etc/NetworkManager/NetworkManager.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Cloudflare DNS are set up !\n' exit 0 else # -------------------- runs if dns settings are already changed -------------------- # mount root in read/write mode mount -o remount,rw / ; # makes /etc/resolv.conf writable/erasable chattr -i /etc/resolv.conf ; # add it Cloudflare servers echo -e "nameserver $CLF_one\nnameserver $CLF_two" > /etc/resolv.conf ; # make it immutable chattr +i /etc/resolv.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Cloudflare DNS are set up !\n' exit 0 fi ;; " OpenDNS") # search the default string if grep -qs 'dns=dnsmasq' /etc/NetworkManager/NetworkManager.conf then # -------------------- runs if found default dns settings -------------------- # mount root in read/write mode mount -o remount,rw / ; # remove /etc/resolv.conf (is a symbolic link pointing to /run/resolvconf/resolv.conf) rm /etc/resolv.conf ; # create /etc/resolv.conf touch /etc/resolv.conf ; # add it OpenDNS servers echo -e "nameserver $OPE_one\nnameserver $OPE_two" >> /etc/resolv.conf ; # set permission chmod 644 /etc/resolv.conf ; # make it immutable chattr +i /etc/resolv.conf ; # replace dns=dnsmasq with dns=none in NetworkManager conf file sed -i 's/dns=dnsmasq/dns=none/' /etc/NetworkManager/NetworkManager.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n OpenDNS Servers are set up !\n' exit 0 else # -------------------- runs if dns settings are already changed -------------------- # mount root in read/write mode mount -o remount,rw / ; # makes /etc/resolv.conf writable/erasable chattr -i /etc/resolv.conf ; # add it OpenDNS servers echo -e "nameserver $OPE_one\nnameserver $OPE_two" > /etc/resolv.conf ; # make it immutable chattr +i /etc/resolv.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n OpenDNS Servers are set up !\n' exit 0 fi ;; " Custom DNS") # search the default string if grep -qs 'dns=dnsmasq' /etc/NetworkManager/NetworkManager.conf then # -------------------- runs if found default dns settings -------------------- # mount root in read/write mode mount -o remount,rw / ; # remove /etc/resolv.conf (is a symbolic link pointing to /run/resolvconf/resolv.conf) rm /etc/resolv.conf ; # create /etc/resolv.conf touch /etc/resolv.conf ; read -p " Type primary server : " priDN echo -e "nameserver $priDN" > /etc/resolv.conf ; read -p " Type secondary server : " secDN echo -e "nameserver $secDN" >> /etc/resolv.conf ; # set permission chmod 644 /etc/resolv.conf ; # make it immutable chattr +i /etc/resolv.conf ; # replace dns=dnsmasq with dns=none in NetworkManager conf file sed -i 's/dns=dnsmasq/dns=none/' /etc/NetworkManager/NetworkManager.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Custom DNS are set up !\n' exit 0 else # -------------------- runs if dns settings are already changed -------------------- # mount root in read/write mode mount -o remount,rw / ; # makes /etc/resolv.conf writable/erasable chattr -i /etc/resolv.conf ; read -p " Type primary server : " priDN echo -e "nameserver $priDN" > /etc/resolv.conf ; read -p " Type secondary server : " secDN echo -e "nameserver $secDN" >> /etc/resolv.conf ; # make it immutable chattr +i /etc/resolv.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Custom DNS are set up !\n' exit 0 fi ;; " Restore OS") # mount root in read/write mode mount -o remount,rw / ; # makes /etc/resolv.conf writable/erasable chattr -i /etc/resolv.conf ; # remove it rm /etc/resolv.conf ; # recreate original simbolic link ln -s /run/resolvconf/resolv.conf /etc/resolv.conf ; # replace dns=none with dns=dnsmasq in NetworkManager conf file sed -i 's/dns=none/dns=dnsmasq/' /etc/NetworkManager/NetworkManager.conf ; # remount root in read only mode mount -o remount,ro / ; # restart daemon service network-manager restart ; echo -e '\n Default settings have been restored !\n' exit 0 ;; " Quit") echo -e '\n OS unchanged !\n' break ;; *) echo "invalid option $REPLY" ;; esac done
(*) For example, if you want to set Google DNS servers enter 8.8.8.8 as primary server and 8.8.4.4 as secondary server.
-
OTA-25 --- You can reinstall, it works.
-
@Br1
Did you consider building an app for your 3 scripts to be nooby friendly ? -
@Br1 As he said, Keneda if you can building an app, this would be great. I tried it on focal. It worked with me in the first time, and when I tried to return to restore default settings, I lost my connection to the Internet without finding a solution, despite my attempts to fix it, which forced me to re-install UT
-
@Keneda I can't promise anything but I will try.
-
@Br1
I don't know if you saw my post responding to you on another of your thread so i put link here, it may be helpfull : https://forums.ubports.com/topic/8144/how-to-record-calls/4?_=1680905394718 -
@Keneda to build apps it is necessary to know qml and python and I don't know them "Touch IDE" is an interesting app, but I would like to do something with shell scripting
-
This post is deleted! -
-
This post is deleted! -
---- UPDATE OTA-2 Focal ----
---- Stable Channel ----Usual three steps :
1 - download (just tap) setdns-ota.2 from here
2 - open file manager, go to Downloads, tap setdns-ota.2.tar.gz and tap extract archive
3 - open terminal, type :
sudo Downloads/setdns-ota.2/setdns-ota.2.sh
and hit enter,
type 1 + enter to set Cloudflare servers
type 2 + enter to set OpenDNS servers
type 3 + enter to set custom servers (*)
type 4 + enter to restore default settings (Restore OS)
type 5 + enter to exit (OS unchanged)Remember to "Restore OS" before the next OTA update !
set-dns is one single script, preview :
#!/bin/bash # Make sure only root can run this script if [ "$(id -u)" != "0" ]; then echo " - You must prepend 'sudo' !" 1>&2 exit 1 fi echo -e '\n- Set DNS servers / Restore default -\n' ; rsv_cnf=/etc/resolv.conf ; # these are Cloudflare's DNS servers CLF_one=1.1.1.1 CLF_two=1.0.0.1 # these are OpenDNS servers OPE_one=208.67.222.222 OPE_two=208.67.220.220 PS3=' Please enter your choice : ' options=(" Cloudflare - " " OpenDNS - " " Custom DNS - " " Restore OS - " " Quit - ") select opt in "${options[@]}" do case $opt in " Cloudflare - ") # check resolv.conf if [ ! -L $rsv_cnf ] ; then # -------------------- runs if resolv.conf is a file -------------------- # mount root in read/write mode mount -o remount,rw / ; # add it Cloudflare servers echo -e "# Cloudflare servers" > $rsv_cnf ; echo -e "nameserver $CLF_one" >> $rsv_cnf ; echo -e "nameserver $CLF_two" >> $rsv_cnf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Cloudflare DNS are set up !\n' exit 0 else # -------------------- runs if resolv.conf is a symbolic link -------------------- # mount root in read/write mode mount -o remount,rw / ; # delete symbolic link rm /etc/resolv.conf ; # create file touch /etc/resolv.conf ; # add it Cloudflare servers echo -e "# Cloudflare servers" > $rsv_cnf ; echo -e "nameserver $CLF_one" >> $rsv_cnf ; echo -e "nameserver $CLF_two" >> $rsv_cnf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Cloudflare DNS are set up !\n' exit 0 fi ;; " OpenDNS - ") # check resolv.conf if [ ! -L $rsv_cnf ] ; then # -------------------- runs if resolv.conf is a file -------------------- # mount root in read/write mode mount -o remount,rw / ; # add it Cloudflare servers echo -e "# OpenDNS servers" > $rsv_cnf ; echo -e "nameserver $OPE_one" >> $rsv_cnf ; echo -e "nameserver $OPE_two" >> $rsv_cnf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n OpenDNS servers are set up !\n' exit 0 else # -------------------- runs if resolv.conf is a symbolic link -------------------- # mount root in read/write mode mount -o remount,rw / ; # delete symbolic link rm /etc/resolv.conf ; # create file touch /etc/resolv.conf ; # add it Cloudflare servers echo -e "# OpenDNS servers" > $rsv_cnf ; echo -e "nameserver $OPE_one" >> $rsv_cnf ; echo -e "nameserver $OPE_two" >> $rsv_cnf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n OpenDNS servers are set up !\n' exit 0 fi ;; " Custom DNS - ") # check resolv.conf if [ ! -L $rsv_cnf ] ; then # -------------------- runs if resolv.conf is a file -------------------- # mount root in read/write mode mount -o remount,rw / ; echo -e "# Custom DNS servers" > $rsv_cnf ; read -p " Type primary server : " priDN echo -e "nameserver $priDN" >> $rsv_cnf ; read -p " Type secondary server : " secDN echo -e "nameserver $secDN" >> $rsv_cnf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Custom DNS are set up !\n' exit 0 else # -------------------- runs if resolv.conf is a symbolic link -------------------- # mount root in read/write mode mount -o remount,rw / ; # delete symbolic link rm /etc/resolv.conf ; # create file touch /etc/resolv.conf ; echo -e "# Custom DNS servers" > $rsv_cnf ; read -p " Type primary server : " priDN echo -e "nameserver $priDN" >> $rsv_cnf ; read -p " Type secondary server : " secDN echo -e "nameserver $secDN" >> $rsv_cnf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Custom DNS are set up !\n' exit 0 fi ;; " Restore OS - ") # mount root in read/write mode mount -o remount,rw / ; # delete file rm /etc/resolv.conf ; # recreate symbolic link ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf ; # remount root in read only mode mount -o remount,ro / ; echo -e '\n Default settings have been Restored !\n' exit 0 ;; " Quit - ") echo -e '\n - OS unchanged !\n' break ;; *) echo "invalid option $REPLY" ;; esac done
(*) For example, if you want to set Google DNS servers enter 8.8.8.8 as primary server and 8.8.4.4 as secondary server.
-
@Br1 Hello. is your OTA-2 work / procedure the same for OTA-3 ? Thanks again
-
I can’t test ota 3 update, install at your own risk (*) -
OTA 3 Stable channel --- You can reinstall, no changes are necessary.
-
@Br1 Done, it works as expected.
-
@Br1 I am on RC test OTA-4, it seems ok for me.
-
New tests.
I noted this:
. Sometimes a reboot is necessary to get my carrier's DNS fully restored if I no longer want to use cloudflare dns. Just using the 'restore' option in the script is not enough.. When using cloudflare, in the list of cloudflare DNS servers, some are in the USA (Missouri). Is this normal ? Shouldn't cloudflare DNS all stay in its country of origin like I see with Firefox (all in France for me) ?
Thank you to enlighten me.
-
@domubpkm said in Change DNS servers, wifi and mobile data:
Sometimes a reboot is necessary to get my carrier's DNS fully restored
It could be caused by dns cache, after restoring try this :
sudo resolvectl flush-caches
if it works, I can add it to next version
@domubpkm said in Change DNS servers, wifi and mobile data:
Shouldn't cloudflare DNS all stay in its country of origin
servers in 120+ countries ... I don’t know what criteria they use
-
@Br1 said in Change DNS servers, wifi and mobile data:
It could be caused by dns cache, after restoring try this :
sudo resolvectl flush-caches
Sorry, i can't confirm it works for me. A reboot is yet necessary.
@Br1 said in Change DNS servers, wifi and mobile data:
Shouldn't cloudflare DNS all stay in its country of origin
servers in 120+ countries ... I don’t know what criteria they use
When i did my precedent feedback, i was in RC TEST OTA-4. Now i am on 'real' OTA-4 and all cloudfare DNS are in my country. So for this, it's solved.