-
Notifications
You must be signed in to change notification settings - Fork 0
/
setdns.sh
executable file
·38 lines (30 loc) · 908 Bytes
/
setdns.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# Add the localhost dnsmasq server to the head of the nameserver list, if it
# is running
# http://wizardmode.com/2012/06/apache-php-mysql-dev-on-os-x-lion-with-a-minimum-of-pain/
# short-circuits
if [ ! -f /etc/resolv.conf ]; then exit; fi
DNSMASQ_RUNNING=`ps auxw | grep [d]nsmasq`
if [ -z "$DNSMASQ_RUNNING" ]; then
exit
fi
NAMESERVERS=$(cat /etc/resolv.conf | grep ^nameserver | cut -d' ' -f2- | xargs echo -n)
if echo $NAMESERVERS | /usr/bin/egrep -q '127\.0\.0\.1' ; then
exit
fi
logger -s setdns: adding 127.0.0.1 before existing list of nameservers $NAMESERVERS
# Find the device ID for the priamry internet interface
PSID=$( (scutil | grep PrimaryService | sed -e 's/.*PrimaryService : //')<< EOF
open
get State:/Network/Global/IPv4
d.show
quit
EOF
)
scutil << EOF
open
d.init
d.add ServerAddresses * 127.0.0.1 $NAMESERVERS
set State:/Network/Service/$PSID/DNS
quit
EOF