Change hosts file(temporary) without rebuild

Hi, is it possibly to change the hosts file without rebuilding the whole system?
I’m a pentester and when connecting to test machines it is very convenient to have a hostname. Since it is often needed it would be a lot of effort to always rebuild the system.

You can probably set environment.etc.hosts.enable = false; and then write /etc/hosts yourself.

1 Like

Thanks i did not knew that there were such options in nixos.
You’re answer inspired me to use environment.etc.hosts.mode = "0700";, which will copy the file instead of symlinking it. So the default config will be written to it but I can also change it anytime

2 Likes

Always worth checking out what happens under the hood when you want to do something that doesn’t seem directly supported by the module you are using.