Auto write wslhost ip into /etc/hosts file
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
I am using wsl2 latest on windows 11.
the current wsl2 won't write right host ip address into /etc/hosts
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
The right solution is add scripts into ~/.bashrc to make sure write wslhost into /etc/hosts
if grep -q "wslhost" /etc/hosts; then
# echo " wsl host already set"
true
else
export PROXY_HOST=$(cat /etc/resolv.conf | grep nameserver | cut -d ' ' -f 2)
echo "$PROXY_HOST wslhost" | sudo tee -a /etc/hosts
fi
Once user login into wsl2 linux, it will load and exec the script to check if wslhost is set
172.23.32.1 wslhost
It is exactly what it was
/etc/resolv.conf
# 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.23.32.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the WSL2 behavior described around /etc/hosts and the generated /etc/resolv.conf, then review the /etc/wsl.conf settings for generateHosts and generateResolvConf. Reproduce the issue by logging into WSL2 and checking whether the nameserver address is available as wslhost in /etc/hosts. Done means the host entry is written automatically with the current address without requiring a ~/.bashrc script.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, shell
- Domain
- networking, operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100