I need to write a small script that allows me to switch between development environments by changing the /etc/hosts file.

I would like to use a symbolic link instead of replacing the whole /etc/hosts file, but when I do the /etc/hosts is ignored. Why?

2 Answers 2


Yes, a symbolic link does not work.

Use a hard link instead:

sudo ln -f {source} /etc/hosts
  • 1
    I'd say this is a good alternative to what OP is trying to achieve instead of the accepted answer.
    – shriek
    Feb 7, 2019 at 19:09

Hosts is a very basic system file and many OS functions depend on it. So they won't accept sym links on such files and expect them to be of type 'ordinary'.

Try overwriting it with your versions, keeping the originals. By the way, you may want to try running local DNS with different zones instead.

  • You didn't answer the question.
    – thedp
    Apr 8, 2018 at 14:12
  • updated to meet your request.
    – MTG
    Apr 8, 2018 at 14:56
  • It seems to be the case, I guess I will just cp the different hosts files I have to /etc/hosts. Thank you.
    – thedp
    Apr 8, 2018 at 21:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .