当前位置:网站首页>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
边栏推荐
- One year's experience of technical personnel in Entrepreneurship
- 大学数据库mysql
- Mathematical modeling contest for graduate students - optimal application of UAV in rescue and disaster relief
- HTAP in depth exploration Guide
- [QT notes] basic use of qregularexpression in QT
- Memory barrier store buffer, invalid queue
- 获取地址url中的query参数指定参数方法
- sql sever列名或所提供值的数目与表定义不匹配
- [graduation season] graduation is the new beginning of your life journey. Are you ready
- Tidb basic functions
猜你喜欢

Ahb2apb bridge design (2) -- Introduction to synchronous bridge design

面试官:大量请求 Redis 不存在的数据,从而打倒数据库,你有什么方案?

路由器和交换机的区别

【OpenAirInterface5g】RRC NR解析之RrcSetupComplete

The fourth question of the 299th weekly match 6103 Minimum fraction of edges removed from the tree

Classical cryptosystem -- substitution and replacement

Configuring FTP, enterprise official website, database and other methods for ECS

Xiaomi Interviewer: let's talk about the proficient Registration Center for three days and three nights

Idea one click log generation

内存屏障今生之Store Buffer, Invalid Queue
随机推荐
multiprocessing. Detailed explanation of pool
2018 mathematical modeling competition - special clothing design for high temperature operation
multiprocessing.pool详解
内存屏障今生之Store Buffer, Invalid Queue
Machine learning
Assembly language - Wang Shuang Chapter 9 Principles of transfer instructions - Notes
Process termination (have you really learned recursion? Test your recursion Foundation)
观测电机转速转矩
0.0.0.0:x的含义
MPC control of aircraft wingtip acceleration and control surface
From 5 seconds to 1 second, the system flies
Cloud-Native Database Systems at Alibaba: Opportunities and Challenges
C# 请问怎么在更新数据库时候调用line与rows
网关状态检测 echo request/reply
Visual studio vs shortcut key usage
[leetcode] day90 the element with the smallest K in the binary search tree
可扩展哈希
win10远程连接云服务器
Oppo interview sorting, real eight part essay, abusing the interviewer
Interviewer: please introduce cache penetration, cache null value, cache avalanche and cache breakdown, which are easy to understand