为Windows10新增物理⽹卡⼦接⼝
为 Windows 10 新增物理⽹卡⼦接⼝
在进⾏⽹络设备调试时常常会使⽤到多 IP ,Linux 上可以很⽅便的为物理⽹卡配置⼦接⼝解决,但是在 Windows 上如果物理⽹卡必须使⽤ DHCP 就⽆法再配置多 IP 了,只能暂时的使⽤ USB 转⽹卡解决。近期突然灵机⼀动,能不能使⽤ Windows 10 天然⽀持的 WSL 来解决这个问题,经过本⼈实测,是可以的,⽅法也很简单。
环境为 Win 10 专业版,安装了 WSL Ubuntu,具体安装⽅法请⾃⾏百度。
安装完毕后进⼊ WSL, CMD ⾥输⼊ ubuntu 即可,使⽤ ifconfig 先看⼀下当前的⽹卡:
ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 30.30.253.241  netmask 255.255.255.240  broadcast 30.30.253.255
inet6 fe80::5d98:1dfb:7083:f7ed  prefixlen 64  scopeid 0xfd<compat,link,site,host>
ether 6c:4b:90:d4:a9:20  (Ethernet)
RX packets 0  bytes 0 (0.0 B)
RX errors 0  dropped 0  overruns 0  frame 0
ubuntu网络配置TX packets 0  bytes 0 (0.0 B)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
其中的 eth0 就是对应的 win10 物理⽹卡在 WSL 中的映射。
使⽤以下命令为该⽹卡配置⼀个⼦接⼝:
sudo ip addr add 192.168.8.123/24 dev eth0 label eth0:1
此时使⽤ ifconfig 看不到这个⼦接⼝,但是实际上已经⽣效:
可以发现在 Win10 上ping ⼀个该⽹段 IP ,配置该⼦接⼝后⽴刻就通了,说明配置完成。
疑难解答
如果您配置时得到下⾯报错:
RTNETLINK answers: Permission denied
使⽤管理员权限打开CMD,运⾏ ubuntu 或 wsl ,之后再配置即可成功。(感谢 GITHUB 社区)
拓展阅读