Android: change DNS for data and WiFi
Published: 03 Aug 2014 | Updated: 01 Jun 2018 | Author: Mentor
If we want change the DNS on our smartphone Android we can use a simple script as the following:
#!/system/bin/sh
#
# Script to change DNS on Android
# by Mentor - www.internauta37.altervista.org
# [email protected]
#
nameserver_1='1.1.1.1'
nameserver_2='1.0.0.1'
iptables -t nat -I OUTPUT -p tcp --dport 53 -j DNAT --to-destination $nameserver_1:53
iptables -t nat -I OUTPUT -p udp --dport 53 -j DNAT --to-destination $nameserver_1:53
iptables -t nat -I OUTPUT -p tcp --dport 53 -j DNAT --to-destination $nameserver_2:53
iptables -t nat -I OUTPUT -p udp --dport 53 -j DNAT --to-destination $nameserver_2:53
to automatically execute it at the boot it have to be put in the path /system/etc/init.d
with permissions 755 and the kernel have to support the Init.d .
In this way we can use our prefered DNS for the data traffic and for the Wi-Fi.
Fonte: Dualjoe