I had the same problem. @Emmby's solution sounded as if it should do exactly what I needed, but, oddly enough, it didn't work. The commands were executed, but after that, viewing the hosts file showed that it was not actually updated.
But I did a little more research, and I decided what the problem was.
The main problem that I encountered was that the emulator operating system already accounted for 100% of the available storage, so the changes were not written to the hosts file. However, there was no error message.
My guess is that the reason @emmby was not related to this problem, because the problem varies depending on the version of Android you put on the emulator; Some versions may give you some free space for work.
If you have this problem, the solution to this is to run an emulator with a large amount of memory. This can be done using the -partition-size argument to the emulator command, for example:
emulator -partition-size 128 @MyEmulatedDevice
Then you can use the adb -e shell command and edit the file according to @emmby's answer.
However, if editing a file from the shell is a pain, adb also gives you the option to copy it from the emulator to your host OS, edit it locally and copy it back. He is also engaged in restoration. You would do it like this:
adb pull /system/etc/hosts C:\wherever\you\want\to\save\it
Then edit it in your favorite editor.
Then remount the emulator in read / write mode and copy the file back:
adb remount adb push C:\wherever\you\saved\hosts /system/etc/hosts
Please note that since the reset emulator returns to its default state upon reboot, this may be the best solution, because you can save the edited file locally, so you do not need to repeat adb pull and edit the steps each time; you can just run the emulator, do remount and push , and you are in business.
Hope this helps.