Skip to content

Instantly share code, notes, and snippets.

@ilwsm
Last active June 6, 2021 09:28
Show Gist options
  • Save ilwsm/28eb6459c12857e60d80753d16b929b0 to your computer and use it in GitHub Desktop.
Save ilwsm/28eb6459c12857e60d80753d16b929b0 to your computer and use it in GitHub Desktop.
Configure WSL2 network inerfaces
# in sudo visudo
username ALL=(ALL:ALL) NOPASSWD: /usr/sbin/ip
# in ~/.bashrc
# 192.168.1.10 - my gateway
# 192.168.1.199 - my WSL2 static ip
EXIST=`ip ro show default via 192.168.1.10 dev eth0 | wc -l`
if ! [ $EXIST -eq 1 ]
then
echo Configure interfaces
sudo ip addr flush dev eth0
sudo ip addr add 192.168.1.199/24 dev eth0
sudo ip ro add default via 192.168.1.10 dev eth0
echo
ip a show eth0
ip ro
fi