下面是设置和复原网络规则的完整命令集合。你可以直接按照以下步骤运行每条命令,快速实现配置和清理。
以下命令将指定设备 192.168.1.6
的流量通过 USB 网口 eth4
(网关 192.168.88.1
) 出网。
将路由表名称 usb_route
写入 /etc/iproute2/rt_tables
文件:
@ECHO OFF | |
wsl -d Ubuntu-20.04 -u root ip addr del $(ip addr show eth0 ^| grep 'inet\b' ^| awk '{print $2}' ^| head -n 1) dev eth0 | |
wsl -d Ubuntu-20.04 -u root ip addr add 192.168.50.2/24 broadcast 192.168.50.255 dev eth0 | |
wsl -d Ubuntu-20.04 -u root ip route add 0.0.0.0/0 via 192.168.50.1 dev eth0 | |
wsl -d Ubuntu-20.04 -u root echo nameserver 192.168.50.1 ^> /etc/resolv.conf | |
powershell -c "Get-NetAdapter 'vEthernet (WSL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-NetIPAddress -IPAddress 192.168.50.1 -PrefixLength 24 -InterfaceAlias 'vEthernet (WSL)'; Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 192.168.50.0/24;" |
@echo off | |
title Bluetooth Device Restart Tool | |
echo Restarting Bluetooth devices... | |
:: Check for admin privileges | |
NET SESSION >nul 2>&1 | |
if %ERRORLEVEL% neq 0 ( | |
echo ERROR: Please run this script as administrator! | |
echo Right-click the script and select "Run as administrator" | |
pause |