FreeBSD networking: DNS: resolv.conf(5) after taking down an interface and bringing up another interface reddit / freebsd ---------------------------------------------------------------------- grahamperrin · 2022-03-02 01:36 [resolv.conf\(5\)](https://www.freebsd.org/cgi/man.cgi?query=resolv.co nf&sektion=5&manpath=FreeBSD) ### Background My Wi-Fi configuration is, I believe, non-complicated: % grep -B 1 -A 6 iwn /etc/rc.conf wlans_iwn0="wlan0" create_args_wlan0="country GB regdomain etsi" ifconfig_wlan0="WPA DHCP" # ifconfig_wlan0="WPA DHCP NOAUTO" # ifconfig_wlan0="WPA SYNCDHCP" # ifconfig_wlan0="WPA SYNCDHCP NOAUTO" % ifconfig em0 inet em0: flags=8863 metric 0 mtu 1500 options=481249b inet 192.168.1.10 netmask 0xffffff00 broadcast 192.168.1.255 % ifconfig wlan0 inet wlan0: flags=8843 metric 0 mtu 1500 inet 192.168.1.7 netmask 0xffffff00 broadcast 192.168.1.255 % I normally have `wlan0` down: * for me to work with `em0` (with `gif0` for tunnelled IPv6). When I take down `em0` (and `gif0`) and bring up `wlan0`: * my `/etc/resolv.conf` (generated by [resolvconf\(8\)](https://www.fr eebsd.org/cgi/man.cgi?query=resolvconf&sektion=8&manpath=FreeBSD)) becomes empty. ### Question How can I **regain a resolver configuration** – in `/etc/resolv.conf` – **without** using [resolvconf.conf\(5\)](https://www.freebsd.org/cgi /man.cgi?query=resolvconf.conf&sektion=5&manpath=FreeBSD)? ---- Below, I'm struggling. root@mowa219-gjp4-8570p-freebsd:~ # ifconfig gif0 down && ifconfig em0 down && ifconfig wlan0 up root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf root@mowa219-gjp4-8570p-freebsd:~ # resolvconf -u root@mowa219-gjp4-8570p-freebsd:~ # service netif restart wlan0 Stopping wpa_supplicant. Waiting for PIDS: 434. Stopping Network: wlan0. wlan0: flags=8802 metric 0 mtu 1500 … Destroyed wlan(4) interfaces: wlan0. Created wlan(4) interfaces: wlan0. Starting wpa_supplicant. Starting Network: wlan0. wlan0: flags=8843 metric 0 mtu 1500 … root@mowa219-gjp4-8570p-freebsd:~ # resolvconf -u root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf root@mowa219-gjp4-8570p-freebsd:~ # service dhclient restart wlan0 Stopping dhclient. Waiting for PIDS: 67230. Starting dhclient. DHCPREQUEST on wlan0 to 255.255.255.255 port 67 DHCPACK from 192.168.1.1 bound to 192.168.1.7 -- renewal in 302400 seconds. root@mowa219-gjp4-8570p-freebsd:~ # resolvconf -u root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf root@mowa219-gjp4-8570p-freebsd:~ # service resolv stop root@mowa219-gjp4-8570p-freebsd:~ # service resolv start root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf root@mowa219-gjp4-8570p-freebsd:~ # resolvconf -u root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf root@mowa219-gjp4-8570p-freebsd:~ # service netif stop wlan0 Stopping wpa_supplicant. Waiting for PIDS: 67136. Stopping Network: wlan0. wlan0: flags=8802 metric 0 mtu 1500 … Destroyed wlan(4) interfaces: wlan0. root@mowa219-gjp4-8570p-freebsd:~ # service netif start wlan0 Created wlan(4) interfaces: wlan0. Starting wpa_supplicant. Starting Network: wlan0. wlan0: flags=8843 metric 0 mtu 1500 … root@mowa219-gjp4-8570p-freebsd:~ # route delete default delete net default root@mowa219-gjp4-8570p-freebsd:~ # service defaultroute restart Waiting 30s for the default route interface: ............................. root@mowa219-gjp4-8570p-freebsd:~ # route show default route: route has not been found root@mowa219-gjp4-8570p-freebsd:~ # service routing stop delete host 127.0.0.1: gateway lo0 delete host ::1: gateway lo0 delete net fe80::: gateway ::1 delete net ff02::: gateway ::1 delete net ::ffff:0.0.0.0: gateway ::1 delete net ::0.0.0.0: gateway ::1 delete net default: gateway 2001:…:…:…::1 root@mowa219-gjp4-8570p-freebsd:~ # service routing start add host 127.0.0.1: gateway lo0 add host ::1: gateway lo0 add net fe80::: gateway ::1 add net ff02::: gateway ::1 add net ::ffff:0.0.0.0: gateway ::1 add net ::0.0.0.0: gateway ::1 add net default: gateway 2001:…:…:…::1 root@mowa219-gjp4-8570p-freebsd:~ # route show default route: route has not been found root@mowa219-gjp4-8570p-freebsd:~ # route show default route: route has not been found root@mowa219-gjp4-8570p-freebsd:~ # service netif restart dhclient not running? (check /var/run/dhclient/dhclient.em0.pid). Stopping wpa_supplicant. Waiting for PIDS: 67750. Stopping Network: lo0 em0 gif0 ue0 wlan0. lo0: flags=8048 metric 0 mtu 16384 … em0: flags=8c22 metric 0 mtu 1500 … gif0: flags=8010 metric 0 mtu 1480 … ue0: flags=8802 metric 0 mtu 1500 … wlan0: flags=8802 metric 0 mtu 1500 … Destroyed wlan(4) interfaces: wlan0. Destroyed clone interfaces: gif0. Created wlan(4) interfaces: wlan0. Created clone interfaces: gif0. Starting wpa_supplicant. Starting Network: lo0 em0 ue0 wlan0 gif0. lo0: flags=8049 metric 0 mtu 16384 … em0: flags=8863 metric 0 mtu 1500 … ue0: flags=8802 metric 0 mtu 1500 … wlan0: flags=8843 metric 0 mtu 1500 … gif0: flags=8051 metric 0 mtu 1480 … root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf search lan nameserver 192.168.1.1 root@mowa219-gjp4-8570p-freebsd:~ # route show default route to: default destination: default mask: default gateway: 192.168.1.1 fib: 0 interface: em0 flags: recvpipe sendpipe ssthresh rtt,msec mtu weight expire 0 0 0 0 1500 1 0 root@mowa219-gjp4-8570p-freebsd:~ # ifconfig gif0 down && ifconfig em0 down root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf root@mowa219-gjp4-8570p-freebsd:~ # ifconfig em0 up && ifconfig gif0 up root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf search lan nameserver 192.168.1.1 root@mowa219-gjp4-8570p-freebsd:~ # date ; uname -aKU Wed Mar 2 00:50:07 GMT 2022 FreeBSD mowa219-gjp4-8570p-freebsd 14.0-CURRENT FreeBSD 14.0-CURRENT #4 main-n253343-9835900cb95-dirty: Wed Feb 23 00:14:15 GMT 2022 root@mowa219-gjp4-8570p- freebsd:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG amd64 1400053 1400053 root@mowa219-gjp4-8570p-freebsd:~ # ---------------------------------------------------------------------- walderf · 2022-03-02 03:02 if i understand the point of your post, you're tired of something overwriting your name server settings and need a work around? if so, run this with escalated privileges run `chattr +i /etc/resolv.conf` ---------------------------------------------------------------------- grahamperrin · 2022-03-02 03:21 > you're tired of something overwriting No. I need a proper configuration written to `/etc/resolv.conf`. The computer (a notebook) is used at multiple locations. >> How can I **regain a resolver configuration** – in `/etc/resolv.conf` – **without** using [resolvconf.conf\(5\)](https:// www.freebsd.org/cgi/man.cgi?query=resolvconf.conf&sektion=5&manpath=Fr eeBSD)? I want to regain a configuration. Gain, not prevent writes. ---------------------------------------------------------------------- meatmechdriver · 2022-03-02 03:44 does your dhcp lease attained by your wifi interface not include nameservers? this is what it smells like. ---------------------------------------------------------------------- walderf · 2022-03-02 03:46 okjay, uhhh.. scratch that chattr advice then, alright? heh. i don't know what to tell ya but i thought i did a few minutes ago, sorry. hopefully someone will come along with a solution for you! ---------------------------------------------------------------------- grahamperrin · 2022-03-02 03:59 > does your dhcp lease attained by your wifi interface not include nameservers? this is what it smells like. It smells that way to me, too. However – if I recall correctly – there's **no problem** if, for example, I: 1. `shutdown now` 2. disconnect the network cable 3. `exit` to multi-user mode – I'll try now, I expect DHCP to work normally … ---------------------------------------------------------------------- grahamperrin · 2022-03-02 04:40 > your wifi interface `wlan0` is fine – I do gain a resolver configuration – if I disconnect the network cable (for `em0`) before booting the OS. % date ; uptime Wed 2 Mar 2022 04:36:26 GMT 4:36a.m. up 4 mins, 5 users, load averages: 8.06, 2.32, 0.88 % cat /etc/resolv.conf # Generated by resolvconf search lan nameserver 192.168.1.1 % ifconfig wlan0 inet wlan0: flags=8843 metric 0 mtu 1500 inet 192.168.1.7 netmask 0xffffff00 broadcast 192.168.1.255 % ifconfig em0 | grep status status: no carrier % sudo ifconfig gif0 down grahamperrin's password: % cat /etc/resolv.conf # Generated by resolvconf search lan nameserver 192.168.1.1 % ping -4 freshports.org PING freshports.org (54.227.255.74): 56 data bytes 64 bytes from 54.227.255.74: icmp_seq=0 ttl=43 time=81.935 ms ^C --- freshports.org ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 81.935/81.935/81.935/0.000 ms % ---------------------------------------------------------------------- grahamperrin · 2022-03-02 04:41 :-) thanks ---------------------------------------------------------------------- meatmechdriver · 2022-03-02 05:56 So it looks like you are using resolvconf here, but I don't understand your comment about not modifying resolvconf.conf. Can you elaborate on that? If you can show your resolvconf.conf that could also be helpful. I haven't had the need to mess with multiple interfaces and resolvconf in a long while but I'll try to help if I can. It seems to me like you might actually want to disable resolvconf though, as you seem to want the most recently upped interface to control resolv.conf. ---------------------------------------------------------------------- grahamperrin · 2022-03-02 06:08 > resolvconf.conf % grep -v \# /etc/resolvconf.conf % It is, effectively, empty. (Lines that are commented out relate to non-DHCP networks that have not been used, by me, for a long time.) > … you seem to want the most recently upped interface to control resolv.conf. I want `resolv.conf` to work with the most recently upped interface. % grep resolv /etc/rc.conf % sysrc resolv_enable resolv_enable: YES % I assume that a switch from `YES` (the operating system default) to `NO` would complicate things. ---------------------------------------------------------------------- meatmechdriver · 2022-03-02 06:40 I believe you can disable resolvconf by adding `resolvconf_enable="NO"` into a new file /etc/dhclient-enter-hooks. ---------------------------------------------------------------------- grahamperrin · 2022-03-02 08:18 With [sysrc\(8\)](https://www.freebsd.org/cgi/man.cgi?query=sysrc&sekt ion=8&manpath=FreeBSD): root@mowa219-gjp4-8570p-freebsd:~ # date; uptime; sysrc -f /etc/rc.conf resolv_enable="NO" Wed Mar 2 08:17:09 GMT 2022 8:17AM up 3:45, 5 users, load averages: 1.41, 1.36, 1.41 resolv_enable: YES -> NO root@mowa219-gjp4-8570p-freebsd:~ # exit logout % exit ### Result I emptied `/etc/rc.conf`, restarted the OS, found `/etc/rc.conf` properly populated. After taking down an interface and bringing up another interface: `/etc/rc.conf` was empty; no improvement. Reverted; % sysrc resolv_enable resolv_enable: YES % ---------------------------------------------------------------------- grahamperrin · 2022-03-02 09:18 > … disable resolvconf by adding `resolvconf_enable="NO"` into a new file `/etc/dhclient-enter-hooks`. (Note to self: also .) ### Result In brief: * `resolvconf -u` *appears* to have the required effect * unfortunately, `ping: sendto: Network is down` – root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/dhclient-enter-hooks resolvconf_enable="NO" root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf search lan nameserver 192.168.1.1 root@mowa219-gjp4-8570p-freebsd:~ # ifconfig wlan0 | grep status status: no carrier root@mowa219-gjp4-8570p-freebsd:~ # ifconfig gif0 down && ifconfig em0 down && ifconfig wlan0 up root@mowa219-gjp4-8570p-freebsd:~ # ifconfig wlan0 | grep status status: associated root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf search lan nameserver 192.168.1.1 root@mowa219-gjp4-8570p-freebsd:~ # nano /etc/resolv.conf root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf root@mowa219-gjp4-8570p-freebsd:~ # ifconfig wlan0 down && ifconfig em0 up && ifconfig gif0 up root@mowa219-gjp4-8570p-freebsd:~ # ifconfig em0 inet em0: flags=8863 metric 0 mtu 1500 options=481249b inet 192.168.1.10 netmask 0xffffff00 broadcast 192.168.1.255 root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf search lan nameserver 192.168.1.1 nameserver 192.168.1.1 root@mowa219-gjp4-8570p-freebsd:~ # nano /etc/resolv.conf root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf root@mowa219-gjp4-8570p-freebsd:~ # ifconfig gif0 down && ifconfig em0 down && ifconfig wlan0 up root@mowa219-gjp4-8570p-freebsd:~ # ifconfig wlan0 | grep status status: associated root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf root@mowa219-gjp4-8570p-freebsd:~ # resolvconf -u root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/resolv.conf # Generated by resolvconf search lan nameserver 192.168.1.1 root@mowa219-gjp4-8570p-freebsd:~ # route show default route to: default destination: default mask: default gateway: 192.168.1.1 fib: 0 interface: em0 flags: recvpipe sendpipe ssthresh rtt,msec mtu weight expire 0 0 0 0 1500 1 0 root@mowa219-gjp4-8570p-freebsd:~ # ping -4 freshports.org PING freshports.org (54.227.255.74): 56 data bytes ping: sendto: Network is down ping: sendto: Network is down ping: sendto: Network is down ^C --- freshports.org ping statistics --- 3 packets transmitted, 0 packets received, 100.0% packet loss root@mowa219-gjp4-8570p-freebsd:~ # service dhclient stop wlan0 Stopping dhclient. Waiting for PIDS: 4553. root@mowa219-gjp4-8570p-freebsd:~ # service dhclient start wlan0 Starting dhclient. DHCPREQUEST on wlan0 to 255.255.255.255 port 67 DHCPACK from 192.168.1.1 bound to 192.168.1.7 -- renewal in 302400 seconds. root@mowa219-gjp4-8570p-freebsd:~ # ping -4 freshports.org PING freshports.org (54.227.255.74): 56 data bytes ping: sendto: Network is down ping: sendto: Network is down ping: sendto: Network is down ping: sendto: Network is down ^C --- freshports.org ping statistics --- 4 packets transmitted, 0 packets received, 100.0% packet loss root@mowa219-gjp4-8570p-freebsd:~ # service netif restart && wait 15 && ifconfig wlan0 down && wait 5 && ping -4 freshports.org dhclient not running? (check /var/run/dhclient/dhclient.em0.pid). Stopping wpa_supplicant. Waiting for PIDS: 428. Stopping Network: lo0 em0 wlan0 gif0 ue0. lo0: flags=8048 metric 0 mtu 16384 … em0: flags=8c22 metric 0 mtu 1500 … wlan0: flags=8802 metric 0 mtu 1500 … gif0: flags=8010 metric 0 mtu 1480 … ue0: flags=8802 metric 0 mtu 1500 … Destroyed wlan(4) interfaces: wlan0. Destroyed clone interfaces: gif0. Created wlan(4) interfaces: wlan0. Created clone interfaces: gif0. Starting wpa_supplicant. Starting Network: lo0 em0 ue0 wlan0 gif0. lo0: flags=8049 metric 0 mtu 16384 … em0: flags=8863 metric 0 mtu 1500 … ue0: flags=8802 metric 0 mtu 1500 … wlan0: flags=8843 metric 0 mtu 1500 … gif0: flags=8051 metric 0 mtu 1480 … wait: Too many arguments. root@mowa219-gjp4-8570p-freebsd:~ # service netif restart && sleep 15 && ifconfig wlan0 down && sleep 5 && ping -4 freshports.org dhclient not running? (check /var/run/dhclient/dhclient.em0.pid). Stopping wpa_supplicant. Waiting for PIDS: 5261. Stopping Network: lo0 em0 ue0 wlan0 gif0. lo0: flags=8048 metric 0 mtu 16384 … em0: flags=8c22 metric 0 mtu 1500 … ue0: flags=8802 metric 0 mtu 1500 … wlan0: flags=8802 metric 0 mtu 1500 … gif0: flags=8010 metric 0 mtu 1480 … Destroyed wlan(4) interfaces: wlan0. Destroyed clone interfaces: gif0. Created wlan(4) interfaces: wlan0. Created clone interfaces: gif0. Starting wpa_supplicant. Starting Network: lo0 em0 ue0 wlan0 gif0. lo0: flags=8049 metric 0 mtu 16384 … em0: flags=8863 metric 0 mtu 1500 … ue0: flags=8802 metric 0 mtu 1500 … wlan0: flags=8843 metric 0 mtu 1500 … gif0: flags=8051 metric 0 mtu 1480 … PING freshports.org (54.227.255.74): 56 data bytes 64 bytes from 54.227.255.74: icmp_seq=0 ttl=44 time=82.298 ms 64 bytes from 54.227.255.74: icmp_seq=1 ttl=44 time=84.259 ms ^C --- freshports.org ping statistics --- 2 packets transmitted, 2 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 82.298/83.278/84.259/0.981 ms root@mowa219-gjp4-8570p-freebsd:~ # ping -6 freshports.org ping: UDP connect: No route to host root@mowa219-gjp4-8570p-freebsd:~ # service routing stop … root@mowa219-gjp4-8570p-freebsd:~ # route delete default route: route has not been found delete net default fib 0: not in table root@mowa219-gjp4-8570p-freebsd:~ # service routing start … root@mowa219-gjp4-8570p-freebsd:~ # ping -6 freshports.org PING6(56=40+8+8 bytes) 2001:…:…:…::2 --> 2600:1f18:461f:1a17:372a:8b3e:c58e:af1b ping: sendmsg: No route to host ping6: wrote freshports.org 16 chars, ret=-1 ping: sendmsg: No route to host ping6: wrote freshports.org 16 chars, ret=-1 ping: sendmsg: No route to host ping6: wrote freshports.org 16 chars, ret=-1 ping: sendmsg: No route to host ping6: wrote freshports.org 16 chars, ret=-1 ^C --- freshports.org ping6 statistics --- 4 packets transmitted, 0 packets received, 100.0% packet loss root@mowa219-gjp4-8570p-freebsd:~ # exit logout % date ; uptime Wed 2 Mar 2022 09:27:49 GMT 9:27a.m. up 29 mins, 5 users, load averages: 0.32, 0.41, 0.64 % exit So: root@mowa219-gjp4-8570p-freebsd:~ # cat /etc/dhclient-enter-hooks # resolvconf_enable="NO" root@mowa219-gjp4-8570p-freebsd:~ # date ; service netif restart Wed Mar 2 09:35:43 GMT 2022 Stopping dhclient. … * `resolvconf_enable="NO"` is now **commented out**. ---------------------------------------------------------------------- timvandijknl · 2022-03-02 10:29 add to /etc/resolvconf.conf: resolv_conf="/dev/null" # prevent updating /etc/resolv.conf problem solved ? ---------------------------------------------------------------------- grahamperrin · 2022-03-02 12:26 > `… prevent updating /etc/resolv.conf` > > problem solved ? No, that's almost the opposite of what I want. ---- Please see [my response to the first comment](https://old.reddit.com/r /freebsd/comments/t4o91n/freebsd_networking_dns_resolvconf5_after_taki ng/hz03qz6/?context=1). Thanks. ---------------------------------------------------------------------- grahamperrin · 2022-03-13 21:53 /u/meatmechdriver thanks for your recent help. Cross-reference > … Maybe some of my problems with networking will disappear, or ease, as a result of these commits fours hours ago: …