有时我们想要对主机取别名,比如把 HTB 域名指向目标机器的时候,我们可以这样变更 /etc/hosts
:
10.10.11.27 itrc.ssg.htb signserv.ssg.htb
然而这样的编辑需要特权所以具有侵入性,有没有一种更干净更简单的方案来让每个用户定义自己的
主机别名,而不污染全局空间呢?
不久前找到了 libnss_homehosts 这个项目,这样每个人就能在 ${XDG_CONFIG_HOME}/hosts
或者 $HOME/.hosts
定义用户级别的
主机别名.
1
| paru -S aur/libnss-homehosts-git
|
1
2
3
4
5
6
7
8
9
10
11
| --- ./a/etc/nsswitch.conf 2024-08-23 15:54:09.793769003 +0800
+++ ./b/etc/nsswitch.conf 2024-08-23 15:55:20.103690856 +0800
@@ -8,7 +8,7 @@
publickey: files
-hosts: mymachines resolve [!UNAVAIL=return] files myhostname dns
+hosts: homehosts mymachines resolve [!UNAVAIL=return] files myhostname dns
networks: files
protocols: files
|