I am using genymotion emulator and pulled hosts file from it using
adb remount
adb pull /system/etc/hosts C:\Users\Rkn09\Desktop\hosts
and I added new mapping like 192.168.0.115 xxx.mydomain.com and I pushed it back to emulator using
adb push C:\Users\Rkn09\Desktop\hosts /system/etc/hosts
but when I make a request to xxx.mydomain.com its not redirecting to my local machine in LAN 192.168.0.115. I even checked the hosts file using cat /etc/hosts and it has my mapping, can anyone help me with this issue.
PS: Same process is woking fine in Mac OS X EI Captain, I am getting this problem in windows7
It was CR LF characters for me at the end of host file. The hosts file you are copying to Android Emulator should be having Unix Line Feed.
You can set and detect that via NotePadd ++.
Open the host file in NotePadd ++ and select "Edit >> EOL COnversion >> Unix (LF)"
You con confirm the line endings by going to "View >> Show Symbol >> Show End of Line"
That will show the LF characters
To verify that the host file is working you can go to adb shell and ping the domain.
I had the same problem. The following resolved it:
Restart Android and try again:
adb reboot
hosts
file should have been written using linux line ending style.
It's impossible to achieve this in Notepad as well as in Wordpad. Try installing another editor which supports this feature and ensure you saved hosts
file properly.
(I tried AkelPad, but Nodepad++ offers the same feature as well)
Presumably, no matter what the encoding is. Both Windows-1252 (ANSI)
and utf-8
worked.
Having done all the changes push hosts
file to device:
adb remount
adb push hosts /system/etc/hosts
Ensure you have correct hosts
file and it is loaded and whether it works or not:
adb shell cat /system/etc/hosts
adb shell ping my.domain.com
Open browser from Genymotion device and ensure everything works by typing:
http://my.domain.com
You may add port if needed
http://my.domain.com:1234
You do not need rebooting Android device.
In case problem had not gone make sure it is related to hosts
file itself by pinging ip address directly:
adb shell ping 192.168.x.x
If it works, then check line endings in file once more. Some text editors may mix them up and an option to use Unix line ending is quite often related to new files only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With