LDAP 主机
本文档将允许您将 /etc/hosts 放入您的 LDAP 服务器。首先确保您已启动并运行 LDAP 服务器(可参考 LDAP 认证 作为入门)。接下来,您需要从 /etc/hosts 创建一个合适的 ldif 文件。实际上我的文件如下所示
127.0.0.1 localhost 192.168.1.1 gojira.marex.local gojira 192.168.1.50 gamera.marex.local gamera 192.168.1.51 iris.marex.local iris 192.168.1.52 zedan.marex.local zedan
其中 127.0.0.1 是 localhost (当然),192.168.1.1 是 LDAP 服务器,后面至少跟着 3 个工作站 (gamera, iris & zedan)。对于 ldif 文件,您需要为您的主机和每个主机创建一个 ou(我将下一个文件命名为 hosts.ldif)
dn: ou=Hosts,dc=marex,dc=local objectClass: organizationalUnit objectClass: top ou: Hosts dn: cn=gojira+ipHostNumber=192.168.1.1,ou=Hosts,dc=marex,dc=local objectClass: ipHost objectClass: device objectClass: top cn: gojira ipHostNumber: 192.168.1.1 dn: cn=gamera+ipHostNumber=192.168.1.50,ou=Hosts,dc=marex,dc=local objectClass: ipHost objectClass: device objectClass: top cn: gamera ipHostNumber: 192.168.1.50 dn: cn=iris+ipHostNumber=192.168.1.51,ou=Hosts,dc=marex,dc=local objectClass: ipHost objectClass: device objectClass: top cn: iris ipHostNumber: 192.168.1.51 dn: cn=zedan+ipHostNumber=192.168.1.52,ou=Hosts,dc=marex,dc=local objectClass: ipHost objectClass: device objectClass: top cn: zedan ipHostNumber: 192.168.1.52
接下来,使用您的凭据将文件放入您的 LDAP 服务器中(输出已截断)
$ ldapadd -x -W -D 'cn=ldapadmin,dc=marex,dc=local' -h 192.168.1.1 -p 389 -f hosts.ldif ... adding new entry "cn=zedan+ipHostNumber=192.168.1.52,ou=Hosts,dc=marex,dc=local"
如果一切都已填充,则编辑您的 /etc/nss_ldap.conf 并将以 nss_base_hosts 开头的行更改为以下内容
nss_base_hosts ou=Hosts,dc=marex,dc=local?one
现在更改 /etc/hosts,使其仅包含 localhost、LDAP 服务器和工作站自身的名称。以下是在工作站 gamera 上的示例
127.0.0.1 localhost 192.168.1.1 gojira.marex.local gojira 192.168.1.50 gamera.marex.local gamera
在 LDAP 服务器上,您可以忽略每个工作站。最后,您需要编辑 /etc/nsswitch.conf 中的 hosts 条目
hosts: files dns ldap
现在测试您的配置
$ getent hosts 127.0.0.1 localhost 192.168.1.1 gojira.marex.local gojira 192.168.1.50 gamera.marex.local gamera 192.168.1.1 gojira 192.168.1.50 gamera 192.168.1.51 iris 192.168.1.52 zedan
前 3 行来自 /etc/hosts,后 4 行来自您的 LDAP 服务器。最后,为了使 ping 与 LDAP 一起工作,您需要启动 nscd
$ mkdir -p /var/db/nscd $ mkdir -p /var/run/nscd $ /etc/rc.d/nscd start $ ping iris PING iris (192.168.1.51) 56(84) bytes of data. ...