大量更新
This commit is contained in:
39
997-项目VPN虚拟机/0-虚拟IP内容.md
Normal file
39
997-项目VPN虚拟机/0-虚拟IP内容.md
Normal file
@@ -0,0 +1,39 @@
|
||||
192.168.11.158
|
||||
192.168.11.159
|
||||
192.168.11.160
|
||||
192.168.11.161
|
||||
192.168.11.162
|
||||
192.168.11.163
|
||||
192.168.11.164
|
||||
192.168.11.169
|
||||
192.168.11.170
|
||||
192.168.11.171
|
||||
|
||||
|
||||
#!/usr/bin/env bash
|
||||
|
||||
IPS=(
|
||||
192.168.11.158
|
||||
192.168.11.159
|
||||
192.168.11.160
|
||||
192.168.11.161
|
||||
192.168.11.162
|
||||
192.168.11.163
|
||||
192.168.11.164
|
||||
192.168.11.169
|
||||
192.168.11.170
|
||||
192.168.11.171
|
||||
)
|
||||
|
||||
for ip in "${IPS[@]}"; do
|
||||
echo "检测 $ip ..."
|
||||
|
||||
# -c 3 表示发送3个包,-W 1 表示单个包超时1秒
|
||||
if ping -c 3 -W 1 "$ip" >/dev/null 2>&1; then
|
||||
echo "[$ip] ✅ 连通"
|
||||
else
|
||||
echo "[$ip] ❌ 不通"
|
||||
fi
|
||||
|
||||
echo "------------------------"
|
||||
done
|
||||
40
997-项目VPN虚拟机/1-window虚拟机模板.sh
Normal file
40
997-项目VPN虚拟机/1-window虚拟机模板.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
qemu-img create -f qcow2 /vm/sys/windows/win-server-2022-template-sys.qcow2 60G
|
||||
|
||||
|
||||
virt-install \
|
||||
--name win-server-2022-template \
|
||||
--virt-type kvm \
|
||||
--machine q35 \
|
||||
--vcpus 8 \
|
||||
--ram 16384 \
|
||||
--cpu mode=host-passthrough \
|
||||
--os-variant win10 \
|
||||
--disk path=/vm/sys/windows/win-server-2022-template-sys.qcow2,format=qcow2,bus=sata,cache=none,discard=unmap \
|
||||
--cdrom /vm/data/iso/windows-server-2022.iso \
|
||||
--disk path=/vm/data/iso/virtio-win-0.1.285.iso,device=cdrom,bus=sata,readonly=on \
|
||||
--network bridge=br0,model=virtio \
|
||||
--graphics vnc,listen=127.0.0.1 \
|
||||
--video vga \
|
||||
--channel unix,target_type=virtio,name=org.qemu.guest_agent.0 \
|
||||
--sound none \
|
||||
--noautoconsole \
|
||||
--autostart
|
||||
|
||||
|
||||
virsh shutdown win-server-2022-template
|
||||
virsh domstate win-server-2022-template
|
||||
|
||||
virsh dumpxml --inactive win-server-2022-template > /root/win-server-2022-template.xml
|
||||
|
||||
virsh edit win-server-2022-template
|
||||
|
||||
virsh start win-server-2022-template
|
||||
|
||||
|
||||
virsh destroy win-server-2022-template
|
||||
|
||||
python3 vm_manager.py clone-windows \
|
||||
--template win-server-2022-template \
|
||||
--name ws2022-192-168-11-160 \
|
||||
--ip 192.168.11.160
|
||||
58
997-项目VPN虚拟机/2-openEuler2203虚拟机模板.sh
Normal file
58
997-项目VPN虚拟机/2-openEuler2203虚拟机模板.sh
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
qemu-img create -f qcow2 /vm/sys/linux/open-euler-2203-sp4-template-sys.qcow2 30G
|
||||
|
||||
|
||||
virt-install \
|
||||
--name open-euler-2203-sp4-template \
|
||||
--virt-type kvm \
|
||||
--machine q35 \
|
||||
--vcpus 8 \
|
||||
--ram 16384 \
|
||||
--cpu mode=host-passthrough \
|
||||
--os-variant openeuler22.03 \
|
||||
--disk path=/vm/sys/linux/open-euler-2203-sp4-template-sys.qcow2,format=qcow2,bus=virtio,cache=none,discard=unmap \
|
||||
--cdrom /vm/data/iso/openEuler-22.03-LTS-SP4-x86_64-dvd.iso \
|
||||
--network bridge=br0,model=virtio \
|
||||
--graphics vnc,listen=127.0.0.1 \
|
||||
--video vga \
|
||||
--channel unix,target_type=virtio,name=org.qemu.guest_agent.0 \
|
||||
--sound none \
|
||||
--noautoconsole \
|
||||
--autostart
|
||||
|
||||
|
||||
virsh shutdown open-euler-2203-sp4-template
|
||||
virsh domstate open-euler-2203-sp4-template
|
||||
|
||||
virsh dumpxml --inactive open-euler-2203-sp4-template > /root/open-euler-2203-sp4-template.xml
|
||||
|
||||
virsh edit open-euler-2203-sp4-template
|
||||
|
||||
virsh start open-euler-2203-sp4-template
|
||||
|
||||
|
||||
virsh destroy open-euler-2203-sp4-template
|
||||
|
||||
python3 vm_manager.py clone-linux \
|
||||
--template open-euler-2203-sp4-template\
|
||||
--name-prefix open-euler-2203 \
|
||||
--ip 192.168.11.171 \
|
||||
--prefix 24 \
|
||||
--gateway 192.168.11.1 \
|
||||
--dns 192.168.34.40,223.5.5.5 \
|
||||
--vcpus 4 \
|
||||
--memory 8192 \
|
||||
--data-size 300G \
|
||||
--autostart
|
||||
|
||||
python3 vm_manager.py clone-linux \
|
||||
--template open-euler-2203-sp4-template\
|
||||
--name-prefix open-euler-2203 \
|
||||
--ip 192.168.11.227 \
|
||||
--prefix 24 \
|
||||
--gateway 192.168.11.1 \
|
||||
--dns 192.168.34.40,223.5.5.5 \
|
||||
--vcpus 4 \
|
||||
--memory 8192 \
|
||||
--data-size 300G \
|
||||
--autostart
|
||||
58
997-项目VPN虚拟机/3-ubuntu2204虚拟机模板.sh
Normal file
58
997-项目VPN虚拟机/3-ubuntu2204虚拟机模板.sh
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
qemu-img create -f qcow2 /vm/sys/linux/ubuntu2204-vm-sys.qcow2 30G
|
||||
|
||||
|
||||
virt-install \
|
||||
--name ubuntu2204-vm \
|
||||
--virt-type kvm \
|
||||
--machine q35 \
|
||||
--vcpus 8 \
|
||||
--ram 16384 \
|
||||
--cpu mode=host-passthrough \
|
||||
--os-variant ubuntu21.04 \
|
||||
--disk path=/vm/sys/ubuntu2204-vm-sys.qcow2,format=qcow2,bus=sata,cache=none,discard=unmap \
|
||||
--network bridge=br0,model=virtio \
|
||||
--graphics vnc,listen=127.0.0.1 \
|
||||
--video vga \
|
||||
--channel unix,target_type=virtio,name=org.qemu.guest_agent.0 \
|
||||
--sound none \
|
||||
--noautoconsole \
|
||||
--autostart
|
||||
|
||||
|
||||
virsh shutdown ubuntu2204-vm
|
||||
virsh domstate ubuntu2204-vm
|
||||
|
||||
virsh dumpxml --inactive ubuntu2204-vm > /root/ubuntu2204-vm.xml
|
||||
|
||||
virsh edit ubuntu2204-vm
|
||||
|
||||
virsh start ubuntu2204-vm
|
||||
|
||||
|
||||
virsh destroy ubuntu2204-vm
|
||||
|
||||
|
||||
python3 vm_manager.py clone-linux \
|
||||
--template ubuntu2204-vm\
|
||||
--name-prefix ubuntu2204 \
|
||||
--ip 192.168.11.170 \
|
||||
--prefix 24 \
|
||||
--gateway 192.168.11.1 \
|
||||
--dns 192.168.34.40,223.5.5.5 \
|
||||
--vcpus 4 \
|
||||
--memory 8192 \
|
||||
--data-size 300G \
|
||||
--autostart
|
||||
|
||||
python3 vm_manager.py clone-linux \
|
||||
--template ubuntu2204-vm\
|
||||
--name-prefix ubuntu2204 \
|
||||
--ip 192.168.11.226 \
|
||||
--prefix 24 \
|
||||
--gateway 192.168.11.1 \
|
||||
--dns 192.168.34.40,223.5.5.5 \
|
||||
--vcpus 4 \
|
||||
--memory 8192 \
|
||||
--data-size 300G \
|
||||
--autostart
|
||||
40
997-项目VPN虚拟机/4-win-10-ltsc虚拟机模板.sh
Normal file
40
997-项目VPN虚拟机/4-win-10-ltsc虚拟机模板.sh
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
qemu-img create -f qcow2 /vm/sys/windows/win10-ltsc-template-sys.qcow2 60G
|
||||
|
||||
|
||||
virt-install \
|
||||
--name win10-ltsc-template \
|
||||
--virt-type kvm \
|
||||
--machine q35 \
|
||||
--vcpus 8 \
|
||||
--ram 16384 \
|
||||
--cpu mode=host-passthrough \
|
||||
--os-variant win10 \
|
||||
--disk path=/vm/sys/windows/win10-ltsc-template-sys.qcow2,format=qcow2,bus=virtio,cache=none,discard=unmap \
|
||||
--cdrom /vm/data/iso/win10-ltsc-19044.7058.260311-zh-cn.iso \
|
||||
--disk path=/vm/data/iso/virtio-win-0.1.285.iso,device=cdrom,bus=sata,readonly=on \
|
||||
--network bridge=br0,model=virtio \
|
||||
--graphics vnc,listen=127.0.0.1 \
|
||||
--video vga \
|
||||
--channel unix,target_type=virtio,name=org.qemu.guest_agent.0 \
|
||||
--sound none \
|
||||
--noautoconsole \
|
||||
--autostart
|
||||
|
||||
|
||||
virsh shutdown win10-ltsc-template
|
||||
virsh domstate win10-ltsc-template
|
||||
|
||||
virsh dumpxml --inactive win10-ltsc-template > /root/win10-ltsc-template.xml
|
||||
|
||||
virsh edit win10-ltsc-template
|
||||
|
||||
virsh start win10-ltsc-template
|
||||
|
||||
|
||||
virsh destroy win10-ltsc-template
|
||||
|
||||
python3 vm_manager.py clone-windows \
|
||||
--template win10-ltsc-template \
|
||||
--name win10-ltsc-192-168-11-164 \
|
||||
--ip 192.168.11.164
|
||||
154
997-项目VPN虚拟机/init-ip-change.ps1
Normal file
154
997-项目VPN虚拟机/init-ip-change.ps1
Normal file
@@ -0,0 +1,154 @@
|
||||
# ================================
|
||||
# Windows 主机名 / IP 配置脚本
|
||||
# 使用方法:
|
||||
# 1. 先修改下面的配置区
|
||||
# 2. 用管理员权限运行 PowerShell
|
||||
# 3. 执行本脚本
|
||||
# 4. 执行完成后重启系统
|
||||
# ================================
|
||||
|
||||
# ===== 配置区开始 =====
|
||||
$NewComputerName = "win10-ltsc-192-168-11-162"
|
||||
$IPAddress = "192.168.11.162"
|
||||
$PrefixLength = 24
|
||||
$Gateway = "192.168.11.1"
|
||||
$DnsServers = @("192.168.34.40","223.5.5.5")
|
||||
# 如需指定网卡名,可填写,例如 "以太网"
|
||||
# 留空则自动选择当前状态为 Up 的第一块物理/虚拟以太网卡
|
||||
$PreferredAdapterName = ""
|
||||
# ===== 配置区结束 =====
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Info($msg) {
|
||||
Write-Host "[INFO] $msg" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
function Write-Ok($msg) {
|
||||
Write-Host "[ OK ] $msg" -ForegroundColor Green
|
||||
}
|
||||
|
||||
function Write-WarnMsg($msg) {
|
||||
Write-Host "[WARN] $msg" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
function Write-Fail($msg) {
|
||||
Write-Host "[FAIL] $msg" -ForegroundColor Red
|
||||
}
|
||||
|
||||
try {
|
||||
Write-Info "开始执行主机名与网络配置"
|
||||
|
||||
# 1. 检查管理员权限
|
||||
$currentIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$principal = New-Object Security.Principal.WindowsPrincipal($currentIdentity)
|
||||
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
if (-not $isAdmin) {
|
||||
throw "请使用管理员权限运行 PowerShell"
|
||||
}
|
||||
Write-Ok "管理员权限检查通过"
|
||||
|
||||
# 2. 校验 IP
|
||||
[void][System.Net.IPAddress]::Parse($IPAddress)
|
||||
[void][System.Net.IPAddress]::Parse($Gateway)
|
||||
foreach ($dns in $DnsServers) {
|
||||
[void][System.Net.IPAddress]::Parse($dns)
|
||||
}
|
||||
if ($PrefixLength -lt 0 -or $PrefixLength -gt 32) {
|
||||
throw "PrefixLength 必须在 0 到 32 之间"
|
||||
}
|
||||
Write-Ok "IP 参数校验通过"
|
||||
|
||||
# 3. 选择网卡
|
||||
if ($PreferredAdapterName -and $PreferredAdapterName.Trim() -ne "") {
|
||||
$nic = Get-NetAdapter -Name $PreferredAdapterName -ErrorAction Stop
|
||||
}
|
||||
else {
|
||||
$nic = Get-NetAdapter |
|
||||
Where-Object {
|
||||
$_.Status -eq "Up" -and
|
||||
$_.InterfaceDescription -notmatch "Bluetooth|Wireless|Wi-Fi|VPN" -and
|
||||
$_.Name -notmatch "Bluetooth|无线|Wi-Fi|VPN"
|
||||
} |
|
||||
Sort-Object InterfaceMetric, ifIndex |
|
||||
Select-Object -First 1
|
||||
}
|
||||
|
||||
if (-not $nic) {
|
||||
throw "未找到可用网卡,请手工指定 `$PreferredAdapterName"
|
||||
}
|
||||
|
||||
Write-Info "选中的网卡: Name=$($nic.Name), ifIndex=$($nic.ifIndex), Status=$($nic.Status)"
|
||||
Write-Ok "网卡选择完成"
|
||||
|
||||
# 4. 删除旧 IPv4 地址
|
||||
$oldIPs = Get-NetIPAddress -InterfaceIndex $nic.ifIndex -AddressFamily IPv4 -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.IPAddress -ne "127.0.0.1" }
|
||||
|
||||
foreach ($item in $oldIPs) {
|
||||
Write-Info "删除旧 IP: $($item.IPAddress)"
|
||||
Remove-NetIPAddress `
|
||||
-InterfaceIndex $nic.ifIndex `
|
||||
-IPAddress $item.IPAddress `
|
||||
-Confirm:$false `
|
||||
-ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# 5. 删除旧默认路由
|
||||
$oldRoutes = Get-NetRoute -InterfaceIndex $nic.ifIndex -AddressFamily IPv4 -DestinationPrefix "0.0.0.0/0" -ErrorAction SilentlyContinue
|
||||
foreach ($route in $oldRoutes) {
|
||||
Write-Info "删除旧默认路由: NextHop=$($route.NextHop)"
|
||||
Remove-NetRoute `
|
||||
-InterfaceIndex $nic.ifIndex `
|
||||
-DestinationPrefix "0.0.0.0/0" `
|
||||
-NextHop $route.NextHop `
|
||||
-Confirm:$false `
|
||||
-ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
Write-Ok "旧 IP 和默认路由清理完成"
|
||||
|
||||
# 6. 配置新 IP / 网关
|
||||
Write-Info "写入新 IP: $IPAddress/$PrefixLength, Gateway=$Gateway"
|
||||
New-NetIPAddress `
|
||||
-InterfaceIndex $nic.ifIndex `
|
||||
-IPAddress $IPAddress `
|
||||
-PrefixLength $PrefixLength `
|
||||
-DefaultGateway $Gateway `
|
||||
-AddressFamily IPv4 `
|
||||
-ErrorAction Stop | Out-Null
|
||||
|
||||
Write-Ok "静态 IP 配置完成"
|
||||
|
||||
# 7. 配置 DNS
|
||||
Write-Info "写入 DNS: $($DnsServers -join ', ')"
|
||||
Set-DnsClientServerAddress `
|
||||
-InterfaceIndex $nic.ifIndex `
|
||||
-ServerAddresses $DnsServers `
|
||||
-ErrorAction Stop
|
||||
|
||||
Write-Ok "DNS 配置完成"
|
||||
|
||||
# 8. 修改主机名
|
||||
if ($env:COMPUTERNAME -ne $NewComputerName) {
|
||||
Write-Info "当前主机名: $env:COMPUTERNAME"
|
||||
Write-Info "目标主机名: $NewComputerName"
|
||||
Rename-Computer -NewName $NewComputerName -Force -ErrorAction Stop
|
||||
Write-Ok "主机名修改完成,重启后生效"
|
||||
}
|
||||
else {
|
||||
Write-WarnMsg "主机名已经是目标值,无需修改"
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Ok "全部配置已完成"
|
||||
|
||||
# 新增:直接执行重启
|
||||
Write-Host "系统将在 5 秒后自动重启..." -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 5
|
||||
Restart-Computer -Force
|
||||
}
|
||||
catch {
|
||||
Write-Fail $_.Exception.Message
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user