wsl2 networking issue requires static ipaddr and route workaround
Due to a known wsl2 networking issue, some users need to create a static ip and route to establish internet access. https://github.com/microsoft/WSL/issues/4275
to fix on Ubuntu the steps are
/etc/wsl.conf
[network]
generateResolvConf = false
/etc/resolv.conf
nameserver 8.8.8.8
~/.bashrc
ip addr flush dev eth0
ip addr add 192.168.0.xxx/24 dev eth0
ip route add default via 192.168.0.1
to match this on this distro I manually verified with
/etc/wsl.conf
[network]
generateResolvConf = false
/etc/resolv.conf
nameserver 8.8.8.8
$
ip addr flush dev eth0
ip addr add 192.168.0.117/24 dev eth0
ip route add default via 192.168.0.1
this returns for ip addr // route
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:5d:57:9c:3d brd ff:ff:ff:ff:ff:ff
inet 192.168.0.117/24 scope global eth0
valid_lft forever preferred_lft forever
default via 192.168.0.1 dev eth0
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.117
and works as expected to access internet.
trying to automate it, I updated /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
IPADDR=19.168.0.117
PREFIX=24
GATEWAY=192.168.0.1
ONBOOT=yes
DNS1=192.168.0.1
DNS2=8.8.8.8
DNS3=8.8.4.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=eth0
UUID= //from $uuidgen eth0//
wsl --shutdown restart but ip addr still returns
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:5d:57:9c:3d brd ff:ff:ff:ff:ff:ff
inet 172.23.5.215/20 brd 172.23.15.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::215:5dff:fe57:9c3d/64 scope link
valid_lft forever preferred_lft forever
ip route
default via 172.23.0.1 dev eth0
172.23.0.0/20 dev eth0 proto kernel scope link src 172.23.5.215
so tried adding to .bash rc
cp /etc/skel/.bashrc ~/.bashrc
$
ip addr flush dev eth0
ip addr add 192.168.0.117/24 dev eth0
ip route add default via 192.168.0.1
source ~/.bashrc
is there a way to automate the static IP addr and route at wsl2 launch?
In my environment, I've solved the problem by adding the following to ~/.profile
ip addr flush dev eth0
ip addr add 172.25.160.10/20 dev eth0
ip route add default via 172.25.160.1
then returns
PS C:\Users\**********> wsl --shutdown
PS C:\Users\**********> wsl -d Amazon2
-bash-4.2# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 12:98:72:0a:ba:6c brd ff:ff:ff:ff:ff:ff
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether de:78:80:dc:e9:34 brd ff:ff:ff:ff:ff:ff
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:5d:30:d0:d3 brd ff:ff:ff:ff:ff:ff
inet 172.25.160.10/20 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::215:5dff:fe30:d0d3/64 scope link
valid_lft forever preferred_lft forever
5: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
link/sit 0.0.0.0 brd 0.0.0.0
-bash-4.2# ip route
default via 172.25.160.1 dev eth0
172.25.160.0/20 dev eth0 proto kernel scope link src 172.25.160.10
I hope you will try it and let me know the results. Thanks.
with 2.0.20211005.0, ip and yum command not working
-bash-4.2# ip addr show
-bash: ip: command not found
with 2.0.20211005.0, ip and yum command not working
-bash-4.2# ip addr show -bash: ip: command not found
ok it's not just me then - did you ever figure this out? Kinda hard to debug internet commands when ping, nc, route, and even ip commands are not available and you can't install anything. :)