Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1789945
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: LINUX

2016-05-23 22:08:07

碰到一个同事问,/etc/hosts 里面添加的hostname ,为什么使用nslookup 查询不到。
我也不知道怎么回答,只能胡乱回答说nslookup 和dig 都是查询DNS server, 而不是查询本地的/etc/hosts 文件。
你可以ping 自己设置的hostname ,只要能ping 通就行了,默认/etc/nsswitch.conf  里面一般都会配配置 file,DNS,NIS.

点击(此处)折叠或打开

  1. # Example configuration of GNU Name Service Switch functionality.
  2. # If you have the `glibc-doc-reference' and `info' packages installed, try:
  3. # `info libc "Name Service Switch"' for information about this file.

  4. passwd: compat
  5. group: compat
  6. shadow: compat
  7. gshadow: files

  8. hosts: files myhostname mdns4_minimal [NOTFOUND=return] dns
  9. networks: files

  10. protocols: db files
  11. services: db files
  12. ethers: db files
  13. rpc: db files

  14. netgroup: nis
怎么感觉看得不是很明白呢。

点击(此处)折叠或打开

  1. apt-get install "glibc-doc-reference" "info"
  2. info libc "Name Service Switch"
  3.    
  4. To fulfill the first goal above the ABI of the modules will be
  5. described below. For getting the implementation of a new service right
  6. it is important to understand how the functions in the modules get
  7. called. They are in no way designed to be used by the programmer
  8. directly. Instead the programmer should only use the documented and
  9. standardized functions to access the databases.

  10. The databases available in the NSS are

  11. 'aliases'
  12.      Mail aliases
  13. 'ethers'
  14.      Ethernet numbers,
  15. 'group'
  16.      Groups of users, *note Group Database::.
  17. 'hosts'
  18.      Host names and numbers, *note Host Names::.
  19. 'netgroup'
  20.      Network wide list of host and users, *note Netgroup Database::.
  21. 'networks'
  22.      Network names and numbers, *note Networks Database::.
  23. 'protocols'
  24.      Network protocols, *note Protocols Database::.
  25. 'passwd'
  26.      User passwords, *note User Database::.
  27. 'rpc'
  28.      Remote procedure call names and numbers,
  29. 'services'
  30.      Network services, *note Services Database::.
  31. 'shadow'
  32.      Shadow user passwords,

  33. There will be some more added later ('automount', 'bootparams',
  34. 'netmasks', and 'publickey').
基本上明白了怎么用getent ,getent + 这里列的每个database 都可以试试。 getent protocols , getent services, getent rpc.

点击(此处)折叠或打开

  1. root@kali:~# getent hosts kobe
  2. 127.0.0.1       localhost kobe
  3. root@kali:~# getent shadow root
  4. root:$6$RzxFAkm7$YARWPy0rwwkw1tEddHOjJ5OLhdNikknB4Noi85DbyInA220zyPqI0bQqY7TzPtVieBeBK8U7CyqE7ZLkbVqG1/:16759:0:99999:7:::
getent 这个命令挺好玩,可以多man看看。
最后strace 了一下,看的一头雾水,本来对系统调用就不是很熟。猜测是create了UDP的socket, poll对FD轮询, 对FD 3 先sendto 了堆字符串,然后又从FD 3这里receive 字符串。

点击(此处)折叠或打开

  1. socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
  2. connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, 16) = 0
  3. poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
  4. sendto(3, "h\221\1\0\0\1\0\0\0\0\0\0\4kobe\0\0\34\0\1", 22, MSG_NOSIGNAL, NULL, 0) = 22
  5. poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLIN}])
  6. ioctl(3, FIONREAD, [97]) = 0
  7. recvfrom(3, "h\221\201\203\0\1\0\0\0\1\0\0\4kobe\0\0\34\0\1\0\0\6\0\1\0\0\7\6\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("8.8.8.8")}, [16]) = 97
  8. close(3) = 0
  9. stat("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=97, ...}) = 0
  10. stat("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=97, ...}) = 0
  11. open("/etc/hosts", O_RDONLY|O_CLOEXEC) = 3
  12. fstat(3, {st_mode=S_IFREG|0644, st_size=222, ...}) = 0
  13. mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f72fc77c000
  14. read(3, "127.0.0.1\tlocalhost kobe\n127.0.1"..., 4096) = 222
  15. read(3, "", 4096) = 0




阅读(4916) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~