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

Fix WSL2 static IP always (test full IP string, not only begin) #7

Closed
wants to merge 1 commit into from

Conversation

ocroz
Copy link

@ocroz ocroz commented Oct 25, 2021

The script does not update the IP if starting with correct string.

Expected IP: 192.168.50.2
Current IP: 192.168.50.205

In this case, the script does not update the IP as expected.

@wikiped
Copy link
Owner

wikiped commented Oct 26, 2021

Thanks for trying to solve this.

I am not sure I understand under what conditions capturing trailing slash would help better in checking for expected IP address:

> ip_addr=172.16.0.2
> echo 172.16.0.2/24 | grep -F "$ip_addr"
172.16.0.2
> 
> echo 192.168.0.2/24 | grep -F "$ip_addr"
> 

vs:

> echo 172.16.0.2/24 | grep -qF "$ip_addr/"
172.16.0.2/
> 
> echo 192.168.0.2/24 | grep -F "$ip_addr/"
> 

@ocroz
Copy link
Author

ocroz commented Oct 27, 2021

After shutdown, wsl assigns a new IP within the selected Subnet.

Say the subnet is 192.168.50.1/24 on Windows side, wsl assigns any IP from 192.168.50.2 to 192.168.50.255.

The problem is when the assigned IP starts with the expected IP stored in /etc/wsl.conf

# Get current assigned IP
$ dev=eth0
$ ip addr show dev $dev | grep -Po "inet \K[\d\./]+" 2>/dev/null
192.168.50.205/24

# Get expected IP
$ grep static_ip /etc/wsl.conf
static_ip = 192.168.50.2

# Success
$ ip_addr=192.168.50.2
$ echo 192.168.50.105/24 | grep -F "$ip_addr" # Remove -q

# Failure
$ ip_addr=192.168.50.2
$ echo 192.168.50.205/24 | grep -F "$ip_addr" # Remove -q
192.168.50.205/24

The current algorithm bugs when assigned IP starts with expected IP.

@ocroz
Copy link
Author

ocroz commented Oct 27, 2021

PS: This module is unusable until you fix this issue.

If to have proper DNS nameserver, we need to wsl --shutdown (see #4 which you closed without fixing it).

Then we are facing this annoying problem where wsl2 machine is not configured with its expected IP half of the times (see #7).

@wikiped
Copy link
Owner

wikiped commented Nov 13, 2021

Thanks for spotting this partial match bug, it has been fixed in Version 0.7.0 using slightly different approach.

@wikiped wikiped closed this Nov 13, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants