Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

注意:这个alias只对由gethostby()系统调用(和另一个忘了叫啥的系统调用)实现的功能起替换,但是对于从host名字到ip地址的转换还是没办法
所以还是和修改/etc/hosts不一样

实际上并不是修改/etc/hosts,而是取得和修改/etc/hosts类似的效果:

https://unix.stackexchange.com/questions/6887/can-i-create-override-dns-similar-to-writing-in-etc-hosts-without-root-access

use the HOSTALIASES environment variable:

$ echo “foo www.google.com" >> /.hosts
$ HOSTALIASES=
/.hosts wget foo
See hostname(7).

In the example the HOSTALIASES environment variable only affects the wget process. Of course, you can export HOSTALIASES to have it take effect for all subprocesses of the current shell:
add following to ~/.bashrc: (you may create ~/.hosts through first cp /etc/hosts then modify as you need)

export HOSTALIASES=~/.hosts

评论