1.最常用的方法是检查 /etc/resolv.conf 的内容:
cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 221.131.143.69
nameserver 112.4.0.55
nameserver 127.0.1.1但有时候这个文件会是空的。。
比如,在Ubuntu上,如果使用 network manager配置网络,默认的情况下, /etc/resolv.conf是空的。
运行命令 dhclient eth0/wlan0 可以刷新这个文件。
2. 使用network manager的命令行工具
$ nmcli dev list iface wlan0
GENERAL.DEVICE: wlan0
GENERAL.TYPE: 802-11-wireless
GENERAL.VENDOR: Realtek Semiconductor Co., Ltd.
GENERAL.PRODUCT: RTL8188CE 802.11b/g/n WiFi Adapter
GENERAL.DRIVER: rtl8192ce
GENERAL.DRIVER-VERSION: 3.13.0-48-generic
GENERAL.FIRMWARE-VERSION: N/A
GENERAL.HWADDR: EC:55:F9:BF:7C:16
GENERAL.STATE: 100 (connected)
GENERAL.REASON: 0 (No reason given)
GENERAL.UDI: /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/wlan0
GENERAL.IP-IFACE: wlan0
GENERAL.NM-MANAGED: yes
GENERAL.AUTOCONNECT: yes
GENERAL.FIRMWARE-MISSING: no
GENERAL.CONNECTION: /org/freedesktop/NetworkManager/ActiveConnection/1
CAPABILITIES.CARRIER-DETECT: no
CAPABILITIES.SPEED: 150 Mb/s
CONNECTIONS.AVAILABLE-CONNECTION-PATHS: /org/freedesktop/NetworkManager/Settings/{4}
CONNECTIONS.AVAILABLE-CONNECTIONS[1]: 74e041fe-c57c-4c91-b68f-3556bde60ff6 | 1201-1
WIFI-PROPERTIES.WEP: yes
WIFI-PROPERTIES.WPA: yes
WIFI-PROPERTIES.WPA2: yes
WIFI-PROPERTIES.TKIP: yes
WIFI-PROPERTIES.CCMP: yes
WIFI-PROPERTIES.AP: yes
WIFI-PROPERTIES.ADHOC: yes
IP4.ADDRESS[1]: ip = 192.168.1.102/24, gw = 192.168.1.1
IP4.DNS[1]: 221.131.143.69
IP4.DNS[2]: 112.4.0.55
DHCP4.OPTION[1]: expiry = 1428593985
DHCP4.OPTION[2]: broadcast_address = 192.168.1.255
DHCP4.OPTION[3]: dhcp_message_type = 5
DHCP4.OPTION[4]: routers = 192.168.1.1
DHCP4.OPTION[5]: dhcp_lease_time = 7200
DHCP4.OPTION[6]: ip_address = 192.168.1.102
DHCP4.OPTION[7]: subnet_mask = 255.255.255.0
DHCP4.OPTION[8]: domain_name_servers = 221.131.143.69 112.4.0.55
DHCP4.OPTION[9]: network_number = 192.168.1.0
DHCP4.OPTION[10]: dhcp_server_identifier = 192.168.1.1或者:
$ nm-tool | grep DNS
DNS: 221.131.143.69
DNS: 112.4.0.55
3. 查看文件 /var/lib/dhcp/dhclient.leases
$ cat /var/lib/dhcp/dhclient.leases
lease {
interface "wlan0";
fixed-address 192.168.1.102;
option subnet-mask 255.255.255.0;
option routers 192.168.1.1;
option dhcp-lease-time 7200;
option dhcp-message-type 5;
option domain-name-servers 221.131.143.69,112.4.0.55;
option dhcp-server-identifier 192.168.1.1;
renew 4 2015/04/09 14:51:16;
rebind 4 2015/04/09 15:41:40;
expire 4 2015/04/09 15:56:40;
}