I've tried editing it in the same way as in Windows 7. E.g. opening Notepad/Notepad++ as Administrator and then opening the file and save it.
Right after saving it Windows Defender will say Malware Detected. Closing the hosts file and opening it again will give me the default hosts file, with my changes removed.
How can I modify the hosts file and have my changes kept?
There are several reasons to edit the hosts file. To block web sites, but mainly my reason for modifying it is when developing web services. Mocking a server and have the program believe it's talking to the real server makes testing much easier.