当前位置:网站首页>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
边栏推荐
- TiDB 中的视图功能
- [openairinterface5g] rrcsetupcomplete for RRC NR resolution
- Scala之偏函数Partial Function
- 分数阶PID控制
- Once spark reported an error: failed to allocate a page (67108864 bytes), try again
- 面试官:你天天用 Lombok,说说它什么原理?我竟然答不上来…
- poi导出excle
- Cloud-Native Database Systems at Alibaba: Opportunities and Challenges
- MPC control of aircraft wingtip acceleration and control surface
- 将通讯录功能设置为数据库维护,增加用户名和密码
猜你喜欢

Talk about Domain Driven Design

2022 CISP-PTE(一)文件包含

Quick realization of Bluetooth ibeacn function

Block level elements & inline elements

【OpenAirInterface5g】RRC NR解析之RrcSetupComplete

路由器和交换机的区别

解决 Win10 Wsl2 IP 变化问题

The interviewer of a large front-line factory asked: do you really understand e-commerce order development?

Assembly language - Wang Shuang Chapter 11 flag register - Notes

0.0.0.0:x的含义
随机推荐
大学数据库mysql
Transaction overview of tidb
AHB2APB桥接器设计(2)——同步桥设计的介绍
The interviewer of a large front-line factory asked: do you really understand e-commerce order development?
YOLOv6又快又准的目标检测框架 已开源
Fast realization of Bluetooth communication between MCU and mobile phone
[leetcode] day90 the element with the smallest K in the binary search tree
TiDB的使用限制
分数阶PID控制
Some settings about postfix completion code template in idea
Classical cryptosystem -- substitution and replacement
如何优雅的写 Controller 层代码?
TiDB 基本功能
NoViableAltException([email protected][2389:1: columnNameTypeOrConstraint : ( ( tableConstraint ) | ( columnNameT
面试官:大量请求 Redis 不存在的数据,从而打倒数据库,你有什么方案?
2018 mathematical modeling competition - special clothing design for high temperature operation
2022 CISP-PTE(二)SQL注入
论文阅读技巧
SQL injection bypass (I)
Assembly language - Wang Shuang Chapter 11 flag register - Notes