Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wsl2 networking issue requires static ipaddr and route workaround #8

Open
vanderhoff opened this issue Oct 12, 2020 · 3 comments
Open

Comments

@vanderhoff
Copy link

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?

@vanderhoff vanderhoff changed the title wsl2 networking requires static ipaddr and route workaround wsl2 networking issue requires static ipaddr and route workaround Oct 12, 2020
@yosukes-dev
Copy link
Owner

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.

@anilsamuel
Copy link

with 2.0.20211005.0, ip and yum command not working

-bash-4.2# ip addr show
-bash: ip: command not found

@jtrutwin
Copy link

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. :)

yosukes-dev added a commit that referenced this issue Sep 14, 2022
Patch for #8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants