Skip to content

Commit 6a14ef8

Browse files
committed
Added dns script and policy to new hires
1 parent 0c6a20e commit 6a14ef8

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

lib/dns-resolvers.policies.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- name: Ensure Cloudflare DNS is used
2+
query: SELECT 1 FROM dns_resolvers WHERE type='nameserver' AND address = '1.1.1.1'
3+
critical: true
4+
description: This device is not using Cloudflare DNS, which may lead to slower DNS resolution times and potential security risks.
5+
resolution: Change the DNS resolver to Cloudflare at 1.1.1.1
6+
platform: darwin
7+
run_script:
8+
path: ../lib/update_dns.sh

lib/update_dns.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
PRIMARY_DNS="1.1.1.1"
4+
SECONDARY_DNS="1.0.0.1"
5+
6+
# Get the name of the current active network interface
7+
ACTIVE_INTERFACE=$(networksetup -listallnetworkservices | grep -v "An asterisk" | sed -n '2p')
8+
9+
# Check if we got a valid interface
10+
if [ -z "$ACTIVE_INTERFACE" ]; then
11+
echo "Error: Could not determine active network interface."
12+
echo "Available interfaces:"
13+
networksetup -listallnetworkservices | grep -v "An asterisk"
14+
exit 1
15+
fi
16+
17+
echo "Setting DNS servers for $ACTIVE_INTERFACE to $PRIMARY_DNS and $SECONDARY_DNS..."
18+
19+
# Set the DNS servers for the active interface
20+
sudo networksetup -setdnsservers "$ACTIVE_INTERFACE" $PRIMARY_DNS $SECONDARY_DNS
21+
22+
# Flush the DNS cache
23+
sudo dscacheutil -flushcache
24+
sudo killall -HUP mDNSResponder
25+
26+
echo "DNS servers updated successfully!"
27+
echo "Current DNS settings:"
28+
networksetup -getdnsservers "$ACTIVE_INTERFACE"

0 commit comments

Comments
 (0)