当前位置:网站首页>Solve the problem of win10 wsl2 IP change
Solve the problem of win10 wsl2 IP change
2022-06-27 06:53:00 【Twenty one grams of sunshine!】
At present Win10 User add modify hosts File permissions
open C:\Windows\System32\drivers\etc Folder found hosts file , Right click to select Properties , Locate the security tab ;
Click Edit to find the current user group , Add full control permission to it ;


Click ok , Select Yes in the pop-up prompt box ;
At this point, the current user should be able to modify hosts The file .
Write a script
#!/usr/bin/bash
# start-up ssh service
/etc/init.d/ssh start
# start-up mysql service
/etc/init.d/mysql start
# start-up docker service
/etc/init.d/docker start
# set wsl host for Windows
# win hosts file path
win_hosts_path="/mnt/c/Windows/System32/drivers/etc/hosts"
# by wsl2 Set the domain name
wsl_domain="ubuntu"
# obtain wsl2 Of ip
wsl_ip=$(ifconfig eth0 | grep -w inet | awk '{print $2}')
# Judge whether there is wsl2 Domain name of , Modify... If it exists , Otherwise, add
if grep -wq "$wsl_domain" $win_hosts_path
then
# There is no direct use here because of permission problems sed modify hosts file
win_hosts=$(sed -s "s/.* $wsl_domain/$wsl_ip $wsl_domain/g" $win_hosts_path)
echo "Windows In the system wsl Domain name exists , Reset mapping "
echo "$win_hosts" > $win_hosts_path
else
echo "Windows In the system wsl The domain name doesn't exist , Add... Directly ${wsl_ip} ${wsl_domain}"
echo "$wsl_ip $wsl_domain" >> $win_hosts_path
fi
# by wsl Set up win host
wsl_hosts_path="/etc/hosts"
win_domain="win"
win_ip=$(cat /etc/resolv.conf | grep "nameserver" | awk '{print $2}')
if grep -wq "$win_domain" $wsl_hosts_path
then
wsl_hosts=$(sed -s "s/.* $win_domain/$win_ip $win_domain/g" $wsl_hosts_path)
echo "Linux In the system windows Domain name exists , Reset mapping "
echo $wsl_hosts > $wsl_hosts_path
else
echo "Linux In the system windows The domain name doesn't exist , Add... Directly ${win_ip} ${win_domain}"
echo "$win_ip $win_domain" >> $wsl_hosts_path
fi
Boot up configuration
routine
Usually in Linux You can start the machine by
1. edit /etc/rc.loacl
2. stay /etc/init.d/ Add startup script under
3. To configure systemd
But these methods are in the subsystem Can't use , We can go through Windows Indirectly start the services in the subsystem .
Set executable
sudo chmod +x /etc/init.sh
stay Windows Create scripts in
stay Windows Next Enter the shortcut key WIN+R Open the run window
Input shell:startup
open Windows Startup script directory
Create a new linux-start.vbs
The contents are as follows
Set ws = WScript.CreateObject("WScript.Shell")
ws.run "wsl -d Ubuntu-18.04 -u root /etc/init.wsl"
In the script above wsl -d The following parameters are the version of the subsystem you installed Can pass wsl -l see
边栏推荐
猜你喜欢

Memory barrier store buffer, invalid queue

Cloud-Native Database Systems at Alibaba: Opportunities and Challenges

vs怎么配置OpenCV?2022vs配置OpenCV详解(多图)

聊聊领域驱动设计

Classical cryptosystem -- substitution and replacement

面试官:用分库分表如何做到永不迁移数据和避免热点问题?

浅谈GPU:历史发展,架构

On gpu: historical development and structure

winow10安装Nexus nexus-3.20.1-01

Interviewer: you use Lombok every day. What is its principle? I can't answer
随机推荐
聊聊领域驱动设计
mssql如何使用语句导出并删除多表数据
The fourth question of the 299th weekly match 6103 Minimum fraction of edges removed from the tree
An Empirical Evaluation of In-Memory Multi-Version Concurrency Control
mysql关于自增和不能为空
Ora-00909: invalid number of parameters, caused by concat
建模竞赛-光传送网建模与价值评估
记一次Spark报错:Failed to allocate a page (67108864 bytes), try again.
[leetcode] day90 the element with the smallest K in the binary search tree
内存屏障今生之Store Buffer, Invalid Queue
Idea one click log generation
Optimistic and pessimistic affairs
Compatibility comparison between tidb and MySQL
云服务器配置ftp、企业官网、数据库等方法
TiDB的使用限制
OPPO面试整理,真正的八股文,狂虐面试官
Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand
Restrictions on the use of tidb
Cloud-Native Database Systems at Alibaba: Opportunities and Challenges
2022 cisp-pte (I) document contains