腾讯云单网卡机器如何恢复默认路由

2024-03-21 11:14:07 浏览数 (1)

执行ipconfig /all 看下默认网关,一会儿也要用

执行route print -4,找到网卡,一般是Tencent VirtIO Ethernet Adapter,最左边...前面的数字就是一会儿要用的网卡号

下面cmd代码里的%gwip%、%idx1%就是网关IP和网卡号,批量替换%gwip%、%idx1%为上面查到的具体值后,打开控制台VNC在cmd命令行执行即可

代码语言:bash复制
route delete 10.0.0.0/8 2>nul 1>nul
route -p add 10.0.0.0/8 %gwip% IF %idx1% 2>nul 1>nul
route delete 100.64.0.0/10 2>nul 1>nul
route -p add 100.64.0.0/10 %gwip% IF %idx1% 2>nul 1>nul
route delete 172.16.0.0/12 2>nul 1>nul
route -p add 172.16.0.0/12 %gwip% IF %idx1% 2>nul 1>nul
route delete 192.168.0.0/16 2>nul 1>nul
route -p add 192.168.0.0/16 %gwip% IF %idx1% 2>nul 1>nul
route delete 169.254.0.0 2>nul 1>nul
route -p add 169.254.0.0/16 %gwip% IF %idx1% 2>nul 1>nul
route delete 183.60.83.19 2>nul 1>nul
route delete 183.60.82.98 2>nul 1>nul
route -p add 183.60.83.19 %gwip% IF %idx1% 2>nul 1>nul
route -p add 183.60.82.98 %gwip% IF %idx1% 2>nul 1>nul
route delete 255.255.255.255 2>nul 1>nul
route -p add 255.255.255.255 %gwip% IF %idx1% 2>nul 1>nul
route delete 0.0.0.0/0 2>nul 1>nul
route -p add 0.0.0.0/0 %gwip% IF %idx1% 2>nul 1>nul

如果是一些特殊的内网IP,比如9打头、11打头……,总之,不是172和192打头的,打开控制台VNC在powershell执行如下代码

如果前2句执行有问题没获取到正确的值,后面的批量替换就有问题了,为了确保万无一失,建议还是手动查看下网关IP和网卡号,然后批量替换后再执行

$gw=(Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'").defaultipgateway

$idx=(Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'").InterfaceIndex

代码语言:powershell复制
#注意这里是字符串,千万别忘记加双引号,仅仅是示例,手动查完指定具体值,别无脑copy例子中的值,一定别忘记具体化
$gw="10.255.4.1"   
代码语言:powershell复制
#注意这里是数字,不是字符串,不要加双引号,仅仅是示例,手动查完指定具体值,别无脑copy例子中的值,一定别忘记具体化
$idx=15 

route delete 10.0.0.0 mask 255.0.0.0 2>$null

route add -p 10.0.0.0 mask 255.0.0.0 $gw metric 1 IF $idx 2>$null

route delete 100.64.0.0 mask 255.192.0.0 2>$null

route add -p 100.64.0.0 mask 255.192.0.0 $gw metric 1 IF $idx 2>$null

route delete 172.16.0.0 mask 255.240.0.0 2>$null

route add -p 172.16.0.0 mask 255.240.0.0 $gw metric 1 IF $idx 2>$null

route delete 192.168.0.0 mask 255.255.0.0 2>$null

route add -p 192.168.0.0 mask 255.255.0.0 $gw metric 1 IF $idx 2>$null

route delete 169.254.0.0 2>$null

route -p add 169.254.0.0/16 $gw metric 1 IF $idx 2>$null

route delete 183.60.83.19 2>$null

route delete 183.60.82.98 2>$null

route -p add 183.60.83.19 $gw metric 1 IF $idx 2>$null

route -p add 183.60.82.98 $gw metric 1 IF $idx 2>$null

route delete 9.0.0.0 mask 255.0.0.0 2>$null

route add -p 9.0.0.0 mask 255.0.0.0 $gw metric 1 IF $idx 2>$null

route delete 11.0.0.0 mask 255.0.0.0 2>$null

route add -p 11.0.0.0 mask 255.0.0.0 $gw metric 1 IF $idx 2>$null

route delete 30.0.0.0 mask 255.0.0.0 2>$null

route add -p 30.0.0.0 mask 255.0.0.0 $gw metric 1 IF $idx 2>$null

route delete 255.255.255.255 2>$null

route -p add 255.255.255.255 $gw metric 1 IF $idx 2>$null

route delete 0.0.0.0 mask 0.0.0.0 2>$null; route add -p 0.0.0.0 mask 0.0.0.0 $gw metric 1 IF $idx 2>$null;

route print -4

上面9.0.0.0/8 、11.0.0.0/8 、30.0.0.0/8 这3段如果你的vpc不涉及,可以不要相关的命令,普通公有云可以不加这3段路由。

0 人点赞