Last active
September 27, 2021 09:07
-
-
Save nufeng1999/43d25ebcbc1ade97faec93f9d029cd00 to your computer and use it in GitHub Desktop.
[Change WSL2 to bridge mode & Set fixed ip for wsl2 (Default use host WLAN)] #WSL2 #bridge #fix #ip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| ################################################ | |
| # 设置 WSL2 网络为桥接模式 (Default use host WLAN) | |
| # Change WSL to bridge mode (Default use host WLAN) | |
| ################################################ | |
| #export PATH=$PATH:/mnt/c/Windows/System32 | |
| #export PATH=$PATH:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/ | |
| #让WSL改变为网桥模式(无线使用 WLAN,有线使用 以太网 ,powershell 下使用 NetAdapter 命令查看) | |
| #Change WSL to bridge mode (Default use host WLAN) | |
| /mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/powershell.exe -command "Set-VMSwitch WSL -NetAdapterName WLAN" | |
| #改变WSL默认IP地址 192.168.0.50 | |
| #Change WSL default IP address 192.168.0.50 | |
| /usr/bin/ip a flush dev eth0 | |
| /usr/bin/ip addr add 192.168.0.50/24 broadcast 192.168.0.255 dev eth0 | |
| #添加默认网关 | |
| #Add default gateway | |
| /usr/bin/ip r add default via 192.168.0.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment