New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore dns on unclean shutdown #1494
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lixmal
force-pushed
the
restore-dns-on-unclean-shutdown
branch
from
January 23, 2024 15:58
64bd7ef
to
2b12336
Compare
pappz
reviewed
Jan 26, 2024
pappz
reviewed
Jan 26, 2024
pappz
approved these changes
Jan 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe your changes
When the Netbird agent terminates ungracefully (kill, power outage, panic, etc.), the system DNS settings are not restored.
This can result in broken DNS resolution (e.g. a DNS server provided by a peer), in which case the agent won't be able to connect to the management server.
To fix this issue we create an indicator file after adjusting the system DNS settings.
This file is deleted once the settings are restored.
If the agent terminates ungracefully it won't be able to delete this file. Therefore when it is started again it will detect the existence of this file and restore the previous DNS state.
On Linux
/var/lib/netbird/resolv.conf
, contains the old/etc/resolv.conf
/var/lib/netbird/manager
, contains the name of the previous host manager and last netbird IP addressmanager
file
DNS settings are restored by copying the
/var/lib/netbird/resolv.conf
back to/etc/resolv.conf
Test:
systemd-resolved
,openresolv
/resolvconf
echo nameserver 9.9.9.9 | sudo tee /etc/resolv.conf
/var/log/netbird/client.log
for restore message and/etc/resolv.conf
killall -9 netbird
manager
resolvconf
DNS settings are restored by running
restoreHostDNS()
(runsresolvconf -d <interface>
)Test:
systemd-resolved
openresolv
packageecho "nameserver 9.9.9.9" | sudo resolvconf -x -a <physical int>
/var/log/netbird/client.log
for restore message and/etc/resolv.conf
killall -9 netbird
manager
systemd
DNS settings are restored by running
restoreHostDNS()
(runs dbus methods`)Test:
/var/log/netbird/client.log
for restore message andresolvectl status
killall -9 netbird
manager
networkManager
DNS settings are restored by running
restoreHostDNS()
(runs dbus methods`)Test:
systemd-resolved
/etc/NetworkManager/NetworkManager.conf
, adddns=dnsmasq
in the main sectionsudo nmcli general reload
orsudo nmcli networking off; sudo nmcli networking on
/var/log/netbird/client.log
for restore message andnmcli device show | grep -i dns
killall -9 netbird
On Windows
%PROGRAMDATA%\Netbird\unclean_shutdown_dns.txt
, contains the interfaceguid
that is required to set up the host manager.DNS settings are restored by running
restoreHostDNS()
(removes registry keys)Test:
%PROGRAMDATA%\Netbird\client.log
for restore message andSYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsPolicyConfig\NetBird-Match
registryGet-Process -Name netbird | Stop-Process -Force
On macOS
/var/lib/netbird/unclean_shutdown_dns
, emptyDNS settings are restored by running
restoreHostDNS()
(runsscutil remove
).Test:
/var/log/netbird/client.log
for restore message andscutil --dns
for DNS settingssudo killall -9 netbird
mobile should not be affected
Moves the
restore DNS
logic before theremove interface
logic so we don't get errors for missing interfacesImproves error handling and error messages for debugging
Checklist