Is there a way to make the WSL2 ip static? I read about it and I was told there was no way to make the IP static, then is there a way to make a SecureCRT connection to WSL2 without having to change the IP adddress in the configs so I don't have to re-enter the ip every time?
Make a SecureCRT connection to connect to WSL2 without having to change the IP every time
securecrtsshwsl2
Related Solutions
The IP address of a WSL2 machine cannot be made static, however it can be determined using wsl hostname -I
Based on this I was able to create the following powershell script that will start sshd on my WSL machine and route traffic to it.
wsl.exe sudo /etc/init.d/ssh start
$wsl_ip = (wsl hostname -I).trim()
Write-Host "WSL Machine IP: ""$wsl_ip"""
netsh interface portproxy add v4tov4 listenport=22 connectport=22 connectaddress=$wsl_ip
I added the following to my sudoers file via visudo to avoid needing a password to start sshd
%sudo ALL=(ALL) NOPASSWD: /etc/init.d/ssh
Finally, from an administrative powershell terminal, I scheduled my script to run at startup
$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:15
Register-ScheduledJob -Trigger $trigger -FilePath C:\route_ssh_to_wsl.ps1 -Name RouteSSHtoWSL
Short answer:
Assuming that you are using Ubuntu:
sudo apt install gvfs
dbus-launch evince <file.pdf>
Scroll to a location in the PDF, then exit Evince and:
dbus-launch evince <file.pdf>
It should now open to the previous location.
More detail:
You are absolutely right that Evince uses GVfs (the Gnome Virtual File System) to store its bookmarks.
There are a few reasons why this doesn't work (by default) on WSL:
GVfs isn't installed by default on most WSL distributions.
GVfs requires a user-session D-Bus instance. D-Bus is, to take the simple definition from a much more complicated page:
a simple way for applications to talk to one another
makes it simple and reliable to code a "single instance" application or daemon, and to launch applications and daemons on demand when their services are needed
So Evince uses D-Bus to launch-or-attach-to a single instance of the GVfs daemon, and then uses GVfs to store the bookmark.
But that D-Bus instance is normally set up for you by Systemd (and/or PAM) on login.
And WSL doesn't really have the concept of a "login" (you typically never need to enter a password when starting WSL). WSL also doesn't support Systemd out of the box.
All of this combines to mean that (in a default WSL installation) Evince isn't going to keep track of your last location/bookmark.
Installing GVfs is the first step.
Then, you have two options:
dbus-launch evince
each time you start, as in the example above.Or, when you start WSL, use:
wsl ~ -e dbus-launch bash # Or your preferred shell
That will start your Bash shell in a D-Bus user session, and then simply doing
evince <file.pdf>
will open to the last location.
You can see some of what is happening by running ps -efH
between each command. You'll see that dbus-launch bash
will start a D-Bus process, but not much else. Then running evince
will also start up on-demand GVfs processes.
Best Answer
The solution to not redo again everything with a new IP address is found in the post
WSL 2 NIC Bridge mode #4150.
Unfortunately, the solution is only to relegate the work to a script that is run automatically after each login.
Description of the problem:
The solution is to write a PowerShell script that does :
The script also removes unwanted firewall rules.
Here is the script as copied from that post:
You need to schedule the script to run after login, as follows: