
我的目標是讓 nmap 在沒有 --system-dns 標誌或 --dns-servers 選項的情況下將 IP 解析為主機名稱。
當我在不帶 --system-dns 標誌或 --dns-servers 選項的情況下發出以下 nmap 命令時,192.168.0.16 被解析為主機名稱 server1.example.com。 192.168.0.17 未解析為主機名稱。我理解這種情況正在發生,因為根據https://nmap.org/book/host-discovery-dns.html,“Nmap 使用自訂存根解析器”,這意味著 nmap 有自己的 DNS 解析器,而不是我們的本機 DNS 伺服器。有趣的。
[root@client1]# nmap -sn 192.168.0.0/24 -vvv
Initiating Parallel DNS resolution of 256 hosts. at 11:22
Completed Parallel DNS resolution of 256 hosts. at 11:22, 0.02s elapsed
DNS resolution of 18 IPs took 0.02s. Mode: Async [#: 2, OK: 5, NX: 13, DR: 0, SF: 0, TR: 18, CN: 0]
Nmap scan report for server1.example.com (192.168.0.16)
Host is up (0.00063s latency).
Nmap scan report for 192.168.0.17
Host is up (0.00059s latency).
--system-dns
使用該標誌時不會出現此問題。
[root@client1]# nmap -sn 192.168.0.0/24 --system-dns
Nmap scan report for server1.example.com (192.168.0.16)
Host is up (0.00029s latency).
Nmap scan report for server2.example.com (192.168.0.17)
Host is up (0.00026s latency).
--dns-servers
當使用該選項聲明應使用我們的主 DNS 伺服器 (192.168.0.6)時,不會發生此問題。
[root@client1]# nmap -sn 192.168.0.0/24 --dns-servers 192.168.0.6
Nmap scan report for server1.example.com (192.168.0.16)
Host is up (0.00039s latency).
Nmap scan report for server2.example.com (192.168.0.17)
Host is up (0.00036s latency).
nslookup 顯示兩個 IP 都可以解析為其適當的主機名稱。
[root@client1]# nslookup 192.168.0.16
16.0.168.192.in-addr.arpa name = server1.example.com.
[root@client1]# nslookup 192.168.0.17
17.0.168.192.in-addr.arpa name = server2.example.com.
我們使用 CentOs 7 作為我們的作業系統。/etc/resolv.conf
包含以下內容,這表示 192.168.0.6 是我們的主 DNS 伺服器。
[root@client1]# cat /etc/resolv.conf
nameserver 192.168.0.6
nameserver 8.8.8.8
192.168.0.6(我們的主 DNS 伺服器)使用 Bind 版本 9 作為 DNS 服務。
[root@dns1]# named -v
BIND 9.9.4-RedHat-9.9.4-51.el7 (Extended Support Version)
這是 的相關片段/var/named/forward.example.com
。
[root@dns1]# cat /var/named/forward.example.com
$ORIGIN example.com.
$TTL 1D
@ IN SOA ns1.example.com. hostmaster.example.com. (
2016032200 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ; minimum
)
;name used for the nameserver
IN NS ns1.example.com.
;ip address of the nameserver
ns1 IN A 192.168.0.6
;hostname to ip address resolutions
server1 IN A 192.168.0.16
server2 IN A 192.168.0.17
這是 的一個片段/var/named/reverse.example.com
。
[root@client1]# cat /var/named/reverse.example.com
$TTL 1D
@ IN SOA ns1.example.com. root.example.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ; minimum
)
0.168.192.in-addr.arpa. IN NS ns1.example.com.
@ IN NS ns1.example.com.
ns1 IN A 192.168.0.6
16 IN PTR server1.example.com.
17 IN PTR server2.example.com.
答案1
你的問題的根源在於你的/etc/resolv.conf
以及 nmap 如何解析它。
# /etc/resolv.conf nameserver 192.168.0.6 nameserver 8.8.8.8
只有第一個名稱伺服器條目才有資格回答對本機網域和網路的查詢。
第二個名稱伺服器是公用解析器,無法回應私人 IP 範圍的反向 DNS 查詢。
與系統解析器不同,系統解析器預設使用第一個名稱伺服器條目,/etc/resolv.conf
並且僅在第一個名稱伺服器不回應時才使用下一個條目, Nmap 使用找到的所有名稱伺服器條目/etc/resolv.conf
在平行下(隱含的假設是它們都是等價的)。
由於在您的情況下,不同的名稱伺服器並不等效,因此只有一些反向DNS 查詢成功,並且您會看到一些IP 位址被解析為主機名稱(當查詢您的第一個名稱伺服器時) ,而其他IP 位址則不會(使用您的第二個名稱伺服器時) )。
刪除或註解掉第二個名稱伺服器,應該得到與和nmap -sn 192.168.0.0/24 -vvv
相同的結果nmap -sn 192.168.0.0/24 -vvv --system-dns
nmap -sn 192.168.0.0/24 -vvv --dns-servers 192.168.0.6