Azure VM DNS 自动化修改Linux配置

背景:

Azure 虚拟机修改DNS 推荐使用Azure 门户来修改DNS,如下:

https://docs.azure.cn/zh-cn/virtual-network/virtual-networks-name-resolution-for-vms-and-role-instances#specify-dns-servers

Azure VM DNS 自动化修改Linux配置_第1张图片

但是,可用性集当中的虚拟机在完成配置的时候,全部都会被Azure 平台重启,使配置生效。为了避免可用性集当中的虚拟机全部重启。需要为Azure VM 设置OS 层面的DNS服务器配置。并设置开机自动配置。

说明如下:

Azure VM DNS 自动化修改Linux配置_第2张图片

因此,可以参阅如下的方案来为OS 层面配置DNS服务器。具体步骤如下:

可以专门创建一个目录,来存放相关文件,以及shell 脚本,专门来完成我们当前的需求:

[root@AZ-CLI usertest]# pwd
/home/usertest
[root@AZ-CLI usertest]# ls
azurelogin.txt  overwritednsconfiguration.sh  resolv.conf
[root@AZ-CLI usertest]# 

首先在该目录下创建一个resolv.conf,来存放您所需的DNS 配置,如下:

[root@AZ-CLI ~]# cat /home/usertest/resolv.conf 
# Generated by NetworkManage
search shaobosupport.sha3.internal.chinacloudapp.cn
nameserver 8.8.8.8

 

接下来创建一个shell 脚本overwritednsconfiguration.sh,将上述的resolv.conf替换系统的/etc/resolv.conf,如下:

[root@AZ-CLI usertest]# cat overwritednsconfiguration.sh 
#!/bin/bash
\cp -rf /home/usertest/resolv.conf /etc/resolv.conf

 

将此shell 文件添加到开机启动执行脚本/etc/rc.d/rc.local当中,如下:

/home/usertest/overwritednsconfiguration.sh

[root@AZ-CLI usertest]# cat /etc/rc.d/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/home/usertest/overwritednsconfiguration.sh
[root@AZ-CLI usertest]#

 

设置可执行权限chmod +x /home/usertest/overwritednsconfiguration.sh

chmod +x /home/usertest/overwritednsconfiguration.sh

[root@AZ-CLI usertest]# chmod +x /home/usertest/overwritednsconfiguration.sh 
[root@AZ-CLI usertest]# 

继续设置可执行权限chmod +x /etc/rc.d/rc.local

[root@AZ-CLI usertest]# chmod +x /etc/rc.d/rc.local
[root@AZ-CLI usertest]# 

以上。谢谢。

 

你可能感兴趣的:(windows,azure,cloud,dns服务器,linux,shell)