nsswitch名称解析框架

1. nsswitch名称解析框架

1.1  简介&作用

1)作用

  • 让多种应用程序能灵活进行名称解析的通用框架
  • 通用框架与各种类型存储进行交互的公共实现
    • 规定通过哪些途径以及按照什么顺序通过这些途径来查找特定类型的信息
    • 还可以指定某个方法奏效或失效时系统将采取什么动作

2)注意

  • nsswitch通常是为本机上的各种应用程序在名称解析时,完成各种解析库的对应的
  • nsswitch库需要跟各种存储接口解析交互,所以nsswitch对各种对应接口都有一个与之交互的实现方案

1.2 实现

  • /usr/lib64/libnss*
  • /lib64/libnss*
  • 说明:
    • 框架:libnss
    • 驱动:libnss_files-

1.3 名称解析流程

  • 基本流程
    • 应用程序 --> nsswitch(配置文件,查询顺序) --> 对应库文件 --> 解析库 --> 完成解析
  • 解析流程
    • 当需要提供nsswitch.conf文件所描述的信息的时候,系统将检查含有适当info字段的配置行
    • 它按照从左向右的顺序开始执行配置行中指定的方法,在默认情况下,如果找到期望的信息,系统将停止搜索
    • 如果没有指定action,那么当某个方法未能返回结果时,系统就会尝试下一个动作

2. nsswitch配置文件

2.1 配置项详解

 

2.2  配置文件示例

#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Valid entries include:
#
#    nisplus            Use NIS+ (NIS version 3)
#    nis            Use NIS (NIS version 2), also called YP
#    dns            Use DNS (Domain Name Service)
#    files            Use the local files
#    db            Use the local database (.db) files
#    compat            Use NIS on compat mode
#    hesiod            Use Hesiod for user lookups
#    [NOTFOUND=return]    Stop searching if not found so far
#

# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd:    db files nisplus nis
#shadow:    db files nisplus nis
#group:     db files nisplus nis

passwd:     files sss
shadow:     files sss
group:      files sss
#initgroups: files sss

#hosts:     db files nisplus nis dns
hosts:      files dns myhostname

# Example - obey only what nisplus tells us...
#services:   nisplus [NOTFOUND=return] files
#networks:   nisplus [NOTFOUND=return] files
#protocols:  nisplus [NOTFOUND=return] files
#rpc:        nisplus [NOTFOUND=return] files
#ethers:     nisplus [NOTFOUND=return] files
#netmasks:   nisplus [NOTFOUND=return] files     

bootparams: nisplus [NOTFOUND=return] files

ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files sss

netgroup:   nisplus sss

publickey:  nisplus

automount:  files nisplus sss
aliases:    files nisplus

2.3 getent命令

  • 作用:手动查找对应的解析
  • 语法:getent  DATABASE  [key]
  • 示例:
    • getent  passwd  root
    • getent  services  ssh  

3. 思维导图

 

 

 

 

 

 

posted @ 2020-05-06 20:14  Praywu  阅读(520)  评论(0编辑  收藏  举报