Skip to content

wsl2 networking issue requires static ipaddr and route workaround #8

@vanderhoff

Description

@vanderhoff

Due to a known wsl2 networking issue, some users need to create a static ip and route to establish internet access.
microsoft/WSL#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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions