Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url mappings in hosts file in emulator is being ignored

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

like image 774
Navakanth Avatar asked Nov 23 '15 11:11

Navakanth


3 Answers

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)"

enter image description here

You con confirm the line endings by going to "View >> Show Symbol >> Show End of Line"

enter image description here

That will show the LF characters

enter image description here

To verify that the host file is working you can go to adb shell and ping the domain.

enter image description here

like image 195
Raghav Avatar answered Nov 09 '22 10:11

Raghav


I had the same problem. The following resolved it:

  • Make sure you have a blank line after the last entry of the hosts file
  • If you use tabs in the hosts file, replace them with spaces

Restart Android and try again:

adb reboot
like image 42
hai Avatar answered Nov 09 '22 11:11

hai


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.

like image 2
Nick Roz Avatar answered Nov 09 '22 11:11

Nick Roz