在不少ubuntu開啓wifi熱點的教程中,配置比較繁瑣的是hostapd+dnsmasq,不少教程都給出了dnsmasq的安裝過程,其實在ubuntu桌面版系統下,已經集成到NetworkManager了,不過這個軟件包叫dnsmasq-base。如下內容中的dnsmasq指的是dnsmasq-base。html
若是你用sudo apt-get install dnsmasq會把這兩個軟件包都安上。ubuntu
結果vim
- 指望狀態=未知(u)/安裝(i)/刪除(r)/清除(p)/保持(h)
- | 狀態=未安裝(n)/已安裝(i)/僅存配置(c)/僅解壓縮(U)/配置失敗(F)/不徹底安裝(H)/觸發器等待(W)/觸發器未決(T)
- |/ 錯誤?=(無)/須重裝(R) (狀態,錯誤:大寫=故障)
- ||/ 名稱 版本 Architecture 描述
- +++-==============-============-============-=================================
- un dnsmasq <none> <none> (無可用描述)
- ii dnsmasq-base 2.68-1 i386 Small caching DNS proxy and DHCP/
能夠看到集成到NetworkManager的dnsmasq安裝包是dnsmasq-base,不是dnsmasq緩存
這裏再引用官網的一段話https://help.ubuntu.com/community/Dnsmasq服務器
Note that the package "dnsmasq" interferes with Network Manager which can use "dnsmasq-base" to provide DHCP services when sharing an internet connection. Therefore, if you use network manager (fine in simple set-ups only), then install dnsmasq-base, but not dnsmasq. If you have a more complicated set-up, uninstall network manager, use dnsmasq, or similar software (bind9, dhcpd, etc), and configure things by hand.網絡
簡單的翻譯一下吧dom
Network Manager下使用的dnsmasq軟件包名字爲dnsmasq-base,用來提供DHCP服務和網絡共享。所以若是你使用Network Manager,那麼你應該安裝dnsmasq-base,而不是dnsmasq。若是你須要完整的配置,那麼你須要卸載Network Manager,使用dnsmasq或相似的軟件如bind9,dhcpd等來手動配置它
這裏涉及到NetworkManager和network兩種網絡配置管理的問題,因爲hostapd須要禁用Network Manager,因此network管理的方式下dnsmasq-base不知道還能不能用ide
不少教程給出的配置文件是/etc/dnsmasq.conf,若是沒有這個配置文件,也能夠經過命令來配置它,kde-nm-connection-editor和自帶的ap-hoc模式都沒有/etc/dnsmasq.conf,都是經過命令來配置的spa
查看如下dnsmasq能幹什麼吧翻譯
dnsmasq - A lightweight DHCP and caching DNS server.
dnsmasq is a lightweight DNS, TFTP, PXE, router advertisement and DHCP
server. It is intended to provide coupled DNS and DHCP service to a
LAN.
dnsmasq是一個輕量級的DHCP和DNS緩存服務器。
dnsmasq是一個輕量級的DNS, TFTP, PXE, 通告路由器和DHCP服務器。它的目的是提供局域網內DNS服務器和DHCP服務器的耦合。
一個簡單的配置文件
例子
- default-lease-time 600; #默認的租約時間,單位秒
- max-lease-time 7200; #最大的租約時間,單位秒
- subnet 10.10.10.0 netmask 255.255.255.0 { #設置子網聲明
- range 10.10.10.10 10.10.10.100; #設置分配的地址池範圍
- option routers 10.10.10.1; #路由器地址
- option domain-name-servers 8.8.8.8; #DNS服務器地址
- option broadcast-address 10.10.10.255; #路由器的廣播地址
- }
打印的系統日誌信息看看dnsmasq的工做過程
- Sep 20 15:19:23 Lenovo-B470 NetworkManager[734]: <info> Starting dnsmasq...
- Sep 20 15:19:23 Lenovo-B470 NetworkManager[734]: <info> (wlan1): device state ch
- ange: ip-config -> secondaries (reason 'none') [70 90 0]
- Sep 20 15:19:23 Lenovo-B470 NetworkManager[734]: <info> Activation (wlan1) Stage
- 5 of 5 (IPv4 Commit) complete.
- Sep 20 15:19:23 Lenovo-B470 dnsmasq[15540]: started, version 2.68 cachesize 150
- Sep 20 15:19:23 Lenovo-B470 dnsmasq[15540]: compile time options: IPv6 GNU-getop
- t DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth
- Sep 20 15:19:23 Lenovo-B470 dnsmasq-dhcp[15540]: DHCP, IP range 10.42.0.10 -- 10
- .42.0.100, lease time 1h
- Sep 20 15:19:23 Lenovo-B470 dnsmasq[15540]: reading /etc/resolv.conf
- Sep 20 15:19:23 Lenovo-B470 dnsmasq[15540]: using nameserver 202.199.128.6#53
- Sep 20 15:19:23 Lenovo-B470 dnsmasq[15540]: using nameserver 202.96.64.68#53
- Sep 20 15:19:23 Lenovo-B470 dnsmasq[15540]: 清除緩存
上面這段能夠看出來,NetworkManager裏的dnsmasq並無讀取/etc/dnsmasq.conf,而是經過命令指定了地址範圍爲10.42.0.10 -- 10
.42.0.100,租約時間爲1小時
下面是DHCP分配IP地址的過程
- Sep 20 15:20:14 Lenovo-B470 dnsmasq-dhcp[15540]: DHCPDISCOVER(wlan1) 80:e6:50:74:2e:d4
- Sep 20 15:20:14 Lenovo-B470 dnsmasq-dhcp[15540]: DHCPOFFER(wlan1) 10.42.0.70 80:e6:50:74:2e:d4
- Sep 20 15:20:14 Lenovo-B470 dnsmasq-dhcp[15540]: DHCPDISCOVER(wlan1) 80:e6:50:74:2e:d4
- Sep 20 15:20:14 Lenovo-B470 dnsmasq-dhcp[15540]: DHCPOFFER(wlan1) 10.42.0.70 80:e6:50:74:2e:d4
- Sep 20 15:20:15 Lenovo-B470 dnsmasq-dhcp[15540]: DHCPREQUEST(wlan1) 10.42.0.70 80:e6:50:74:2e:d4
- Sep 20 15:20:15 Lenovo-B470 dnsmasq-dhcp[15540]: DHCPACK(wlan1) 10.42.0.70 80:e6:50:74:2e:d4 iPad
- Sep 20 15:20:16 Lenovo-B470 dnsmasq-dhcp[15540]: DHCPREQUEST(wlan1) 10.42.0.70 80:e6:50:74:2e:d4
- Sep 20 15:20:16 Lenovo-B470 dnsmasq-dhcp[15540]: DHCPACK(wlan1) 10.42.0.70 80:e6:50:74:2e:d4 iPad
dnsmasq如何禁用呢
方法一.刪除NetworkManager配置信息
- sudo vim /etc/NetworkManager/NetworkManager.conf
刪除下面的內容,而後保存
方法二.卸載dnsmasq-base軟件包
- sudo apt-get remove dnsmasq-base