How to set DNS when the device is connected via Ethernet?

9.5k views Asked by At

My android target is connect via Ethernet using static IP. I am able to connect it by using ADB, but I am not able to ping any server. Please tell me how can I configure my DNS setting so that I can ping any server.

2

There are 2 answers

2
Aditya Pratap Singh On BEST ANSWER

Use this Command by superuser

su

for versions before marshmallow 6.x

ndc resolver setifdns (interface) (dns1) (dns2)

e.g.- ndc resolver setifdns eth0 8.8.8.8 8.8.4.4

for versions from marshmallow 6.x

ndc resolver setnetdns (interface) (dns1) (dns2)

e.g.- ndc resolver setnetdns eth0 8.8.8.8 8.8.4.4

2
izhoujinjian On

Android 8.0

////////////////////////////////////////////////////////////

ifconfig usb0 192.168.225.3 netmask 255.255.255.0

ndc network create 9792

ndc network interface add 9792 usb0

ndc network route add 9792 usb0 0.0.0.0/0 192.168.225.1

ndc resolver setnetdns 9792 8.8.8.8 8.8.4.4

ndc network default set 9792

///////////////////////////////////////////////////////////