@@ -105,7 +105,8 @@ NOTICE:
105
105
After this operation you won't be able to access SSH service at port $current_port anymore.
106
106
The SSH port will be changed to $DEFAULT_SSH_PORT
107
107
108
-
108
+
109
+
109
110
110
111
"
111
112
set -x;
@@ -141,3 +142,67 @@ function snmpd_initial_conf () {
141
142
set -x
142
143
fi
143
144
}
145
+
146
+ function disable_stop_systemd_resolved () {
147
+
148
+ systemctl disable systemd-resolved
149
+ systemctl stop systemd-resolved
150
+ }
151
+
152
+ function save_current_nameserver_conf_and_disable_resolved () {
153
+
154
+ # This function enables django to be able to change the
155
+ # nameservers by simply editing /etc/resolv.conf .
156
+
157
+ nameserver1=" 1.1.1.1"
158
+ nameserver2=" 9.9.9.9"
159
+ current_etc_resolv_conf=` cat /etc/resolv.conf | grep nameserver | awk ' {print $2}' `
160
+ netplan_conf_file=` ls /etc/netplan/* .y* ml | head -1`
161
+ if [[ $current_etc_resolv_conf == " 127.0.0.53" ]]
162
+ then
163
+ nameserver1_temp=` cat ${netplan_conf_file} | yq -e ' .network.*.*.nameservers.addresses[]' | head -1 `
164
+ nameserver2_temp=` cat ${netplan_conf_file} | yq -e ' .network.*.*.nameservers.addresses[]' | head -2 | tail -1`
165
+
166
+ if [[ -n $nameserver1_temp ]]
167
+ then
168
+ nameserver1=` echo $nameserver1_temp `
169
+ if [[ -n $nameserver1_temp ]]
170
+ then
171
+ nameserver2=` echo $nameserver2_temp `
172
+ fi
173
+ fi
174
+ else
175
+ if [[ -n $current_etc_resolv_conf ]]
176
+ then
177
+ nameserver1_temp=` cat /etc/resolv.conf | grep nameserver | awk ' {print $2}' | head -1 `
178
+ nameserver2_temp=` cat /etc/resolv.conf | grep nameserver | awk ' {print $2}' | head -2 | tail -1`
179
+ if [[ -n $nameserver1_temp ]]
180
+ then
181
+ nameserver1=` echo $nameserver1_temp `
182
+ if [[ -n $nameserver1_temp ]]
183
+ then
184
+ nameserver2=` echo $nameserver2_temp `
185
+ fi
186
+ fi
187
+ fi
188
+ fi
189
+
190
+ chattr -i /etc/resolv.conf
191
+ rm /etc/resolv.conf
192
+ disable_stop_systemd_resolved
193
+ echo " nameserver $nameserver1 " > /etc/resolv.conf
194
+ echo " nameserver $nameserver2 " >> /etc/resolv.conf
195
+ set +x
196
+
197
+ echo " PLEASE NOTE:
198
+ The following servers are set as your DNS servers.
199
+ you can change this configuration by editing /etc/resolv.conf
200
+
201
+ "
202
+ cat /etc/resolv.conf
203
+
204
+ set -x
205
+
206
+ }
207
+
208
+
0 commit comments