Network-Manager, dhcp-client et dnsmasq

Salut
Un petit point de configuration pour faire fonctionner l’ensemble Network-Manager, dhcp-client, dnsmasq pour profiter du cache dnsmasq en utilisant les dns que je veux

apt list *dhcp* | grep install
isc-dhcp-client/testing,stable,now 4.3.5-3 amd64  [installé]
isc-dhcp-common/testing,stable,now 4.3.5-3 amd64  [installé]

apt list *dns* | grep install

dns-root-data/testing,testing,now 2017072601 all  [installé]
dnsmasq/testing,testing,now 2.78-1 all  [installé]
dnsmasq-base/testing,now 2.78-1 amd64  [installé]
dnsutils/testing,now 1:9.10.3.dfsg.P4-12.6 amd64  [installé]
libapache2-mod-dnssd/testing,stable,oldstable,now 0.6-3.1 amd64  [installé]
libdns-export162/testing,now 1:9.10.3.dfsg.P4-12.6 amd64  [installé, automatique]
libdns162/testing,now 1:9.10.3.dfsg.P4-12.6 amd64  [installé, automatique]
libnet-dns-perl/testing,testing,now 1.10-2 all  [installé]
libnss-mdns/testing,stable,now 0.10-8 amd64  [installé]
python-dnspython/testing,testing,stable,stable,now 1.15.0-1 all  [installé, automatique]

Merci au wiki archlinux https://wiki.archlinux.org/index.php/Dnsmasq

Modifications dans les fichiers conf:

/etc/dnsmasq.conf (tout est commenté à l’origine)

port=0
listen-address=127.0.0.1

/etc/dhcp/dhclient.conf

supersede domain-name-servers 64.6.64.6,80.67.188.188,198.153.192.1;
prepend domain-name-servers 127.0.0.1;

/etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile
dns=dnsmasq

[ifupdown]
managed=false

Après son démarrage Network-manager initialise resolv.conf ainsi

 cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 127.0.0.1
systemctl status  NetworkManager.service -l
● NetworkManager.service - Network Manager
   Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2017-10-07 15:42:47 CEST; 23min ago
     Docs: man:NetworkManager(8)
 Main PID: 594 (NetworkManager)
    Tasks: 5 (limit: 4915)
   CGroup: /system.slice/NetworkManager.service
           ├─594 /usr/sbin/NetworkManager --no-daemon
           ├─770 /sbin/dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /run/dhclient-wlan0.pid -lf /var/lib/Network
           └─782 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/run/NetworkManager/d

oct. 07 15:42:55 debian dnsmasq[782]: attention : aucun serveur amont n'est configuré
oct. 07 15:42:55 debian dnsmasq[782]: cache vidé
oct. 07 15:42:55 debian NetworkManager[594]: <info>  [1507383775.6323] dnsmasq[0x556578832cc0]: dnsmasq appeared as :1.22
oct. 07 15:42:55 debian dnsmasq[782]: configuration des serveurs amonts à partir de DBus
oct. 07 15:42:55 debian dnsmasq[782]: ignore le serveur de nom 127.0.0.1 - interface locale
oct. 07 15:42:55 debian dnsmasq[782]: utilise le serveur de nom 64.6.64.6#53 (via wlan0)
oct. 07 15:42:55 debian dnsmasq[782]: utilise le serveur de nom 80.67.188.188#53 (via wlan0)
oct. 07 15:42:55 debian dnsmasq[782]: utilise le serveur de nom 198.153.192.1#53 (via wlan0)
oct. 07 15:42:55 debian dnsmasq[782]: cache vidé
oct. 07 15:42:56 debian NetworkManager[594]: <info>  [1507383776.1971] manager: startup complete

Donc au fur et à mesure les réponses DNS sont mises en cache de dnsmasq ce qui accélère la navigation

root@debian:/# dig archlinux.org

; <<>> DiG 9.10.3-P4-Debian <<>> archlinux.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20407
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;archlinux.org.			IN	A

;; ANSWER SECTION:
archlinux.org.		3600	IN	A	138.201.81.199

;; Query time: 75 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Oct 07 15:55:15 CEST 2017
;; MSG SIZE  rcvd: 58

root@debian:/#  dig archlinux.org

 <<>> DiG 9.10.3-P4-Debian <<>> archlinux.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2488
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;archlinux.org.			IN	A

;; ANSWER SECTION:
archlinux.org.		3594	IN	A	138.201.81.199

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Oct 07 15:55:21 CEST 2017
;; MSG SIZE  rcvd: 58


je passe de 75 msec à 0 msec :sunglasses:

Autres exemple

root@debian:/# dig lemonde.fr

; <<>> DiG 9.10.3-P4-Debian <<>> lemonde.fr
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8428
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;lemonde.fr.			IN	A

;; ANSWER SECTION:
lemonde.fr.		3600	IN	A	93.184.220.20

;; Query time: 71 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Oct 07 16:26:25 CEST 2017
;; MSG SIZE  rcvd: 55

root@debian:/# dig lemonde.fr

; <<>> DiG 9.10.3-P4-Debian <<>> lemonde.fr
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35757
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;lemonde.fr.			IN	A

;; ANSWER SECTION:
lemonde.fr.		3594	IN	A	93.184.220.20

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Oct 07 16:26:31 CEST 2017
;; MSG SIZE  rcvd: 55

Graphique de la séquence de démarrage

Network-Manager gère ses données dans /var/lib/NetworkManager par exemple dans un fichier

-rw-r--r--  1 root root 1128 oct.   8 09:53 dhclient-272730a3-b1a3-4383-bc11-7f2832de355d-wlan0.lease

lease {
  interface "wlan0";
  fixed-address 192.168.1.68;
  option subnet-mask 255.255.255.0;
  option routers 192.168.1.1;
  option dhcp-lease-time 86400;
  option dhcp-message-type 5;
  option domain-name-servers 127.0.0.1,64.6.64.6,64.6.65.6;
  option dhcp-server-identifier 192.168.1.1;
  option dhcp-renewal-time 43200;
  option ntp-servers 192.168.1.1;
  option broadcast-address 192.168.1.255;
  option dhcp-rebinding-time 75600;
  option host-name "debian";
  renew 0 2017/10/08 17:34:47;
  rebind 1 2017/10/09 04:53:22;
  expire 1 2017/10/09 07:53:22;

Remarques et commentaires bienvenus