一、windows打开cmd
wsl
sudo vim /home/guiyongkang/set-static-ip.sh
IP="192.168.100.123"
GATEWAY="192.168.100.1"
NETMASK="24"
sudo ip addr flush dev eth0
sudo ip addr add ${IP}/${NETMASK} dev eth0
sudo ip link set eth0 up
sudo ip route add default via ${GATEWAY} dev eth0
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/nullecho "【静态 IP 已设置完成】"
sudo chmod +x /home/guiyongkang/set-static-ip.sh
sudo vim /etc/wsl.conf
[boot]
command = "sh /home/your_username/set-static-ip.sh"
wsl --shutdown
netsh interface ipv4 add address "vEthernet (WSL)" 192.168.100.1 255.255.255.0