当前位置:网站首页>How to solve the problem that after Tencent cloud sets static DNS, restarting the machine becomes dynamic DNS acquisition

How to solve the problem that after Tencent cloud sets static DNS, restarting the machine becomes dynamic DNS acquisition

2022-06-24 06:21:00 shawyang

Set-ExecutionPolicy Unrestricted -force

while((powershell -c {(get-process|findstr powershell).length}) -ne 2)

{

get-date -format HH:mm:ss:fffffff >> c:\aaa.txt;

start-sleep 1;

}

if((powershell -c {(get-process|findstr powershell).length}) -eq 2)

{

(get-wmiobject -class win32_networkadapterconfiguration -filter ipenabled=true).SetDNSServerSearchOrder(('10.123.119.98','10.12.216.180')) 2>$null;

exit

}

Code to be fine tuned , Put it in C:\Program Files\Cloudbase Solutions\Cloudbase-Init\LocalScripts\setdns.ps1

dns Adjust the agent according to your own needs dns, You can add 、 reduce dns, for example :

Add

(get-wmiobject -class win32_networkadapterconfiguration -filter ipenabled=true).SetDNSServerSearchOrder(('10.123.119.98','10.12.216.180','114.114.114.114','8.8.8.8')) 2>$null;

reduce

(get-wmiobject -class win32_networkadapterconfiguration -filter ipenabled=true).SetDNSServerSearchOrder(('180.76.76.76')) 2>$null;

This script is written by me to set the static DNS Of , For some machines , The value in the code is 2 You can set dns, No machine handle 2 Change to 3 You can set dns success ( The concrete is 2 still 3 Or a bigger number , I watched the background after the restart powershell Number of processes )

2 On behalf of others powershell It's all done , Is executed setdns.ps1 In itself , Set up dns In the last step

and 3 The situation is , I have observed that there are always 1 individual powershell, There has always been , This situation ,3 On behalf of others that should be completed powershell It's all done , Next, we will carry out setdns.ps1 In itself

In code 2 and 3 I have encountered both situations , because cloudbase-init By calling powershell The code works , I guess the logic 2 and 3 The difference may be that the user-defined image has a resident boot plan task, which is weak powershell The process is placed in the background , If that's the case , Excepting 2 and 3, There may be 4、5、6 , etc. , Specifically, it depends on the background after startup powershell How many processes are there

原网站

版权声明
本文为[shawyang]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/07/20210722212204031w.html