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

wrong ip result #37

Open
derik007 opened this issue Oct 4, 2020 · 4 comments
Open

wrong ip result #37

derik007 opened this issue Oct 4, 2020 · 4 comments

Comments

@derik007
Copy link

derik007 commented Oct 4, 2020

I'm pretty sure that I have done everything right to install the tool. However, the result of this tool seems to be incorrect.

In my wsl2, I run

cat /etc/resolv.conf

then I got message below:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.17.60.225

However, when I check hosts file, the result is

172.17.60.228 ubuntu1604.wsl    # managed by wsl2-host

So obviously, 172.17.60.228 is not 172.17.60.225. I think this tool just gives a wrong answer.

my version of go-wsl2-host is v0.3.5.

@derik007 derik007 changed the title wrong ip wrong ip result Oct 4, 2020
@derik007
Copy link
Author

derik007 commented Oct 6, 2020

The tool is all right. I provide with another simple solution below.

#!/bin/sh
export WINIP=$(cat /etc/resolv.conf | grep 'nameserver' | cut -f 2 -d ' ') 
export WSLIP=$(ip addr show eth0 | grep 'inet ' | cut -f 6 -d ' ' | cut -f 1 -d '/')
echo WINIP $WINIP
echo WSLIP $WSLIP

echo <Your Password> | sudo -S sed -i "/winip/c $WINIP\twinip" /etc/hosts
echo <Your Password> | sudo -S sed -i "/wslip/c $WSLIP\twslip" /etc/hosts

vim "+:%s/^.*winip/$WINIP\t\twinip/g" "+:%s/^.*wslip/$WSLIP\t\twslip/g" '+:wq' -E /mnt/c/Windows/System32/drivers/etc/hosts 

Run this script in ~/.bashrc can set hosts both in win and wsl.

@rnwolf
Copy link

rnwolf commented Oct 7, 2020

This line give me an error, about not being writeable.

vim "+:%s/^.*winip/$WINIP\t\twinip/g" "+:%s/^.*wslip/$WSLIP\t\twslip/g" '+:wq' -E /mnt/c/Windows/System32/drivers/etc/hosts

@derik007
Copy link
Author

derik007 commented Oct 8, 2020

This line give me an error, about not being writeable.

vim "+:%s/^.*winip/$WINIP\t\twinip/g" "+:%s/^.*wslip/$WSLIP\t\twslip/g" '+:wq' -E /mnt/c/Windows/System32/drivers/etc/hosts

@rnwolf right click to hosts file and reset your logging user to full authority in property-security-advanced.

@rnwolf
Copy link

rnwolf commented Oct 8, 2020

@derik007 Thanks that worked great. I use zsh, which automatically runs, ~/.zlogin script on login. Rather than Users as picture below, I ended up adding modify & write permissions to just my logging in user.
Screenshot 2020-10-08 105803

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

2 participants