5

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?

7

Yes, a symbolic link does not work.

Use a hard link instead:

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

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.

| improve this answer | |
  • You didn't answer the question. – thedp Apr 8 '18 at 14:12
  • updated to meet your request. – MTG Apr 8 '18 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 '18 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.