Sample Header Ad - 728x90

Update /etc/resolv.conf without removing old entries? Upon network connection?

0 votes
0 answers
49 views
Is there a script hook that's invoked when connecting to a network after or during /etc/resolv.conf being updated (usually with DNS entries from DHCP server)? I'm running a bind name server on localhost so I can serve DNS to my VirtualBox HostOnly network. I want to update /etc/resolv.conf, however if the network connection changes to a different WIFI network, I want to ensure /etc/resolv.conf has correct entries in it. For instance, when bind starts update /etc/resolv.conf and also when the network service changes update it as well. I have the following script so far: $ cat bind-start.sh #!/bin/bash # TODO # Which interface to choose? # More subnets? networksetup -setdnsservers $( networksetup -getdnsservers Wi-Fi | sed '/127.0.0.1/d' | tr '\n' ' ' ) "127.0.0.1" networksetup -setsearchdomains $( networksetup -getsearchdomains Wi-Fi | sed '/p0.mac/d' | tr '\n' ' ' ) "p0.mac" $ cat bind-stop.sh #!/bin/bash # TODO # Which interface to choose? # More subnets? networksetup -setdnsservers $( networksetup -getdnsservers Wi-Fi | sed '/127.0.0.1/d' | tr '\n' ' ' ) networksetup -setsearchdomains $( networksetup -getsearchdomains Wi-Fi | sed '/p0.mac/d' | tr '\n' ' ' )
Asked by atod (77 rep)
Jan 28, 2025, 02:52 AM
Last activity: Jan 28, 2025, 03:36 AM