Skip to content

Instantly share code, notes, and snippets.

@shoesCodeFor
Last active December 12, 2023 23:31
Show Gist options
  • Save shoesCodeFor/95f0acc5d4834c5ba410511540cd6415 to your computer and use it in GitHub Desktop.
Save shoesCodeFor/95f0acc5d4834c5ba410511540cd6415 to your computer and use it in GitHub Desktop.
dnyes.sh
#!/bin/bash
# Define the network service. Replace "Wi-Fi" with your actual network service name, e.g., "Ethernet", if needed.
NETWORK_SERVICE="Wi-Fi"
# Safe DNS list
GOOGLE_DNS="8.8.8.8"
GOOGLE_DNS_ALT="8.8.4.4"
CLOUDFLARE_DNS="1.1.1.1"
CLOUDFLARE_DNS_ALT="1.0.0.1"
# Get the current network service's UUID
SERVICE_UUID=$(networksetup -listallnetworkservices | grep -A1 "${NETWORK_SERVICE}" | tail -1 | awk '{print $NF}')
# Wipe out existing DNS entries
sudo scutil <<EOF
d.init
set State:/Network/Service/${SERVICE_UUID}/DNS
quit
EOF
# Set new DNS entries
sudo scutil <<EOF
d.init
d.add ServerAddresses * ${GOOGLE_DNS} ${GOOGLE_DNS_ALT} ${CLOUDFLARE_DNS} ${CLOUDFLARE_DNS_ALT}
set State:/Network/Service/${SERVICE_UUID}/DNS
quit
EOF
echo "DNS settings updated to Google and Cloudflare DNS. FU Nord 😒"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment