9
9
# a pod would fail.
10
10
#
11
11
# To use this,
12
- # - If this host is also a master, reconfigure master dnsConfig to listen on
13
- # 8053 to avoid conflicts on port 53 and open port 8053 in the firewall
14
12
# - Drop this script in /etc/NetworkManager/dispatcher.d/
15
13
# - systemctl restart NetworkManager
16
14
# - Configure node-config.yaml to set dnsIP: to the ip address of this
@@ -29,16 +27,8 @@ cd /etc/sysconfig/network-scripts
29
27
[ -f ../network ] && . ../network
30
28
31
29
if [[ $2 =~ ^(up| dhcp4-change| dhcp6-change)$ ]]; then
32
- # If the origin-upstream-dns config file changed we need to restart
33
30
NEEDS_RESTART=0
34
- UPSTREAM_DNS=' /etc/dnsmasq.d/origin-upstream-dns.conf'
35
- # We'll regenerate the dnsmasq origin config in a temp file first
36
- UPSTREAM_DNS_TMP=` mktemp`
37
- UPSTREAM_DNS_TMP_SORTED=` mktemp`
38
- CURRENT_UPSTREAM_DNS_SORTED=` mktemp`
39
31
NEW_RESOLV_CONF=` mktemp`
40
- NEW_NODE_RESOLV_CONF=` mktemp`
41
-
42
32
43
33
# #####################################################################
44
34
# couldn't find an existing method to determine if the interface owns the
@@ -49,52 +39,18 @@ if [[ $2 =~ ^(up|dhcp4-change|dhcp6-change)$ ]]; then
49
39
if [[ ${DEVICE_IFACE} == ${def_route_int} ]]; then
50
40
if [ ! -f /etc/dnsmasq.d/origin-dns.conf ]; then
51
41
cat << EOF > /etc/dnsmasq.d/origin-dns.conf
52
- no-resolv
53
42
domain-needed
54
- server=/cluster.local/172.30.0.1
55
- server=/30.172.in-addr.arpa/172.30.0.1
56
43
enable-dbus
44
+ bind-dynamic
45
+ except-interface=lo
46
+ dns-loop-detect
47
+ resolv-file=/etc/origin/node/resolv.conf
57
48
EOF
58
49
# New config file, must restart
59
50
NEEDS_RESTART=1
60
51
fi
61
52
62
- # If network manager doesn't know about the nameservers then the best
63
- # we can do is grab them from /etc/resolv.conf but only if we've got no
64
- # watermark
65
- if ! grep -q ' 99-origin-dns.sh' /etc/resolv.conf; then
66
- if [[ -z " ${IP4_NAMESERVERS} " || " ${IP4_NAMESERVERS} " == " ${def_route_ip} " ]]; then
67
- IP4_NAMESERVERS=` grep ' ^nameserver ' /etc/resolv.conf | awk ' { print $2 }' `
68
- fi
69
- # #####################################################################
70
- # Write out default nameservers for /etc/dnsmasq.d/origin-upstream-dns.conf
71
- # and /etc/origin/node/resolv.conf in their respective formats
72
- for ns in ${IP4_NAMESERVERS} ; do
73
- if [[ ! -z $ns ]]; then
74
- echo " server=${ns} " >> $UPSTREAM_DNS_TMP
75
- echo " nameserver ${ns} " >> $NEW_NODE_RESOLV_CONF
76
- fi
77
- done
78
- # Sort it in case DNS servers arrived in a different order
79
- sort $UPSTREAM_DNS_TMP > $UPSTREAM_DNS_TMP_SORTED
80
- sort $UPSTREAM_DNS > $CURRENT_UPSTREAM_DNS_SORTED
81
- # Compare to the current config file (sorted)
82
- NEW_DNS_SUM=` md5sum ${UPSTREAM_DNS_TMP_SORTED} | awk ' {print $1}' `
83
- CURRENT_DNS_SUM=` md5sum ${CURRENT_UPSTREAM_DNS_SORTED} | awk ' {print $1}' `
84
- if [ " ${NEW_DNS_SUM} " != " ${CURRENT_DNS_SUM} " ]; then
85
- # DNS has changed, copy the temp file to the proper location (-Z
86
- # sets default selinux context) and set the restart flag
87
- cp -Z $UPSTREAM_DNS_TMP $UPSTREAM_DNS
88
- NEEDS_RESTART=1
89
- fi
90
- # compare /etc/origin/node/resolv.conf checksum and replace it if different
91
- NEW_NODE_RESOLV_CONF_MD5=` md5sum ${NEW_NODE_RESOLV_CONF} `
92
- OLD_NODE_RESOLV_CONF_MD5=` md5sum /etc/origin/node/resolv.conf`
93
- if [ " ${NEW_NODE_RESOLV_CONF_MD5} " != " ${OLD_NODE_RESOLV_CONF_MD5} " ]; then
94
- cp -Z $NEW_NODE_RESOLV_CONF /etc/origin/node/resolv.conf
95
- fi
96
- fi
97
-
53
+ # dnsmasq not running, needs a restart
98
54
if ! ` systemctl -q is-active dnsmasq.service` ; then
99
55
NEEDS_RESTART=1
100
56
fi
103
59
if [ " ${NEEDS_RESTART} " -eq " 1" ]; then
104
60
systemctl restart dnsmasq
105
61
fi
62
+
63
+ if [ ! -f /etc/origin/node/resolv.conf ]; then
64
+ cp /etc/resolv.conf /etc/origin/node/resolv.conf
65
+ fi
106
66
107
67
# Only if dnsmasq is running properly make it our only nameserver and place
108
68
# a watermark on /etc/resolv.conf
122
82
fi
123
83
124
84
# Clean up after yourself
125
- rm -f $UPSTREAM_DNS_TMP $UPSTREAM_DNS_TMP_SORTED $CURRENT_UPSTREAM_DNS_SORTED $ NEW_RESOLV_CONF
85
+ rm -f $NEW_RESOLV_CONF
126
86
fi
0 commit comments