Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How wsl2 automatically starts the service and automatically updates the ip in the hosts file

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article analyzes how wsl2 automatically starts the service and automatically updates the ip in the hosts file. The content is detailed and easy to understand, and friends who are interested in "how wsl2 automatically starts the service and automatically updates the ip in the hosts file" can follow the editor's train of thought to read it in depth. I hope it will be helpful to you after reading. Let's follow the editor to learn more about how wsl2 automatically starts the service and automatically updates the ip in the hosts file.

Create a script in the subsystem

Vim / etc/init.wsl

The script content is as follows

#! / bin/sh/etc/init.d/ssh start/etc/init.d/httpd start/etc/init.d/mysql startexport WSLIP=$ (ip addr show eth0 | grep 'inet' | cut-f 6-d''| cut-f 1-d'/') vim "+:% s / ^\ d\ +.\ d\ +.\ d\ +\.\ d\ +\ (. * yy.com\) / $WSLIP\ 1zag"'+: wq'- E / mnt/c/Windows/System32/drivers/etc/hostsvim "+:% s / ^\ d\ +.\ d\ +\.\ d\ +\ (. * yy.com\) / $WSLIP\ 1Universe g"'+: wq'-E / etc/hosts

* .yy.com is a custom domain name I wrote in hosts for building local websites.

To create a script in Windows, enter the shortcut key WIN+R under Windows to open the run window, enter shell:startup to open the Windows startup script directory, and create a new linux-start.vbs under this directory as follows

Set ws = WScript.CreateObject ("WScript.Shell") ws.run "wsl-d Ubuntu-18.04-u root / etc/init.wsl"

The parameter after wsl-d in the above script is that the version of the subsystem you installed can be viewed through wsl-l and now you can restart Windows to verify.

So much for sharing about how wsl2 automatically starts the service and automatically updates the ip in the hosts file. I hope the above content can improve everyone. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report