You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

前提开启hyper-V
1. 获取所有网卡信息
```shell
Get-NetAdapter
```
![[Snipaste_2023-04-01_17-47-48.png]]
2. 启动WSL打开powershell(管理员模式),选择网卡桥接
这里桥接到WLAN
```shell
Set-VMSwitch WSL -NetAdapterName WLAN
# 中文
Set-VMSwitch WSL -NetAdapterName "以太网 3"
```
3. 查看宿主机网关
```shell
ipconfig
```
找到IP段和网关
![[Snipaste_2023-04-01_17-47-48 1.png]]
4. 修改WSL IP地址及网关
```shell
# 绑定到eth0网卡
sudo ip addr del $(ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | head -n 1) dev eth0
# 设置IP段
sudo ip addr add 192.168.0.150/24 broadcast 192.168.0.255 dev eth0
# 设置网关
sudo ip route add 0.0.0.0/0 via 192.168.0.1 dev eth0
```
5. 更新名称解析服务器地址
```shell
vim /etc/resolv.conf
```
修改其中内容为 `nameserver 网关地址`
## 快速设置
```shell
# powershell 管理员,注意修改网卡名称
Set-VMSwitch WSL -NetAdapterName WLAN
# 在wsl中执行
sh /home/zr/setnet.sh
```
## 取消桥接
powershell管理员执行即可恢复
```shell
Set-VMSwitch WSL -SwitchType Internal
```