Answers:
通常,dhclient.leases文件位于/var/lib/dhcp3/dhclient.leases
,键入以下命令:
less /var/lib/dhcp3/dhclient.leases
要么
cat /var/lib/dhcp3/dhclient.leases
要么
您可以只使用grep命令来获取DHCP服务器地址,输入:
grep dhcp-server-identifier /var/lib/dhcp3/dhclient.leases
要么
dhclient eth0
ps aux | grep dhclient
,发现我的租约文件已设置为/var/run/dhclient.eth0.leases
带有该-lf
选项。
我发现我的DHCP租约信息是/var/lib/dhclient/dhclient-eth0.leases
为了防止有人在以下位置找到它/var/lib/dhcp3/dhclient.leases
好吧,为什么不简单地挖那个呢?
marcus@marcus ~ $ dig google.de
; <<>> DiG 9.4.3-P3 <<>> google.de
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27579
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 6, ADDITIONAL: 0
;; QUESTION SECTION:
;google.de. IN A
;; ANSWER SECTION:
google.de. 1785 IN A 209.85.229.104
google.de. 1785 IN A 216.239.59.104
google.de. 1785 IN A 74.125.77.104
;; AUTHORITY SECTION:
de. 23431 IN NS L.DE.NET.
de. 23431 IN NS Z.NIC.de.
de. 23431 IN NS F.NIC.de.
de. 23431 IN NS C.DE.NET.
de. 23431 IN NS S.DE.NET.
de. 23431 IN NS A.NIC.de.
;; Query time: 1 msec
;; SERVER: 192.168.1.15#53(192.168.1.15)
;; WHEN: Thu Sep 17 19:33:39 2009
;; MSG SIZE rcvd: 181
看最后几行:服务器:192.168.1.15#53(192.168.1.15)
此命令显示网络上的DNS服务器
挖| grep服务器:awk -F#'{print $ 1}'| awk -F:“ {print $ 2}”
172.17.0.1
/etc/resolv.conf
。毕竟,挖掘也要从中读取/etc/resolv.conf
,然后(尝试)与服务器通信,然后再产生任何输出。
阅读/etc/resolv.conf
。就这样。
man resolv.conf
也很有用
在现代发行版中,
ps aux | grep dhcli | grep -v grep
root 367 0.0 0.0 16128 3076 ? S Apr30 0:00 /sbin/dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /var/run/dhclient-enp3s0.pid -lf /var/lib/NetworkManager/dhclient-324caec3-58f9-3f00-bff4-2f8bd7d2aafa-enp3s0.lease -cf /var/lib/NetworkManager/dhclient-enp3s0.conf enp3s0
tail -16 /var/lib/NetworkManager/dhclient-324caec3-58f9-3f00-bff4-2f8bd7d2aafa-enp3s0.lease
lease {
interface "enp3s0";
fixed-address 10.191.104.3;
option subnet-mask 255.255.255.0;
option routers 10.191.104.254;
option dhcp-lease-time 86400;
option dhcp-message-type 5;
option domain-name-servers 91.193.220.3,91.193.220.7;
option dhcp-server-identifier 91.193.220.3;
option ntp-servers 91.193.220.6;
option broadcast-address 10.191.104.255;
option domain-name "myISP.ru";
renew 1 2017/05/01 12:56:02;
rebind 2 2017/05/02 00:27:11;
expire 2 2017/05/02 03:27:11;
}
其中91.193.220.7是我的ISP的DNS服务器
nslookup serverfault.com 91.193.220.7
Server: 91.193.220.7
Address: 91.193.220.7#53
Non-authoritative answer:
Name: serverfault.com
Address: 151.101.1.69
Name: serverfault.com
Address: 151.101.65.69
Name: serverfault.com
Address: 151.101.193.69
Name: serverfault.com
Address: 151.101.129.69
查询DHCP服务器的另一种解决方案:
sudo nmap --script broadcast-dhcp-discover
输出告诉您DHCP服务器提供的名称服务器:
Starting Nmap 7.60 ( https://nmap.org ) at 2019-12-12 23:50 UTC
Pre-scan script results:
| broadcast-dhcp-discover:
| Response 1 of 1:
| IP Offered: 144.123.211.44
| DHCP Message Type: DHCPOFFER
| Server Identifier: 144.123.99.200
| IP Address Lease Time: 5m00s
| Subnet Mask: 255.255.0.0
| Router: 144.123.99.200
| Domain Name Server: 144.123.99.200
|_ Domain Name: localdomain