2

I'm running Ubuntu 20.04 under Windows Subsystem for Linux. I have a VPN running inside Ubuntu to access an API on a remote system.

This VPN only works with a Linux client app. I want to try the API using Postman in Windows, but this is "outside" WSL2 and the VPN network.

Since I can't install my VPN in Windows and Postman does not work under Linux/WSLg, how can I re-route my Windows Postman request traffic to WSL2?

2
  • When you are connected to the VPN inside WSL2, does it take over all networking traffic? Or can you still access devices on your local (to Windows) network? Does a ping $(hostname).local work? Jun 10, 2022 at 1:54
  • @NotTheDr01ds i can still access devices from my local and ping $(hostname).local works and vice-versa pinging wsl from windows
    – heydude101
    Jun 10, 2022 at 3:12

2 Answers 2

0

I think I'm probably going to answer your question twice. This one is an orthogonal answer. The other, when I figure it out (or if someone else does) will address the actual networking question.

But for this answer, let me suggest that you might not actually need Postman on Ubuntu/WSL2 if your API is REST-based. Your needs might be met (and potentially better served) in Ubuntu with actual Linux tools.

I've used Postman in the past, but since using WSL, I really haven't found a need for it personally. That's not to say that your use-case might be different, or that you might just prefer Postman since you are familiar with it. Nothing wrong with that, and we'll still see if we can come up with answer for that.

But you might consider:

  • HTTPie for the REST operations that interact with your API. It's a much richer alternative to curl or wget.
  • jq -- the standard and powerful tool for parsing JSON data.
  • Nushell for parsing JSON and many other structured data types. Highly recommended -- I recently used it several times working with the Stack Exchange API, and I'm not sure I'll ever need jq again.

However , if your API is GraphQL-based, then I'm not sure I can offer up a better alternative than Postman at the moment. Altair looks promising, but it appears to be typically installed on Linux as a Snap (which doesn't work well under WSL2).

0

I typically prefer using ssh to tunnel/forward traffic for situations like this. Since you answered in the comments that you can connect from WSL to Windows while the VPN is active, the easiest way to do this is to set up the OpenSSH server in Windows.

You'll find the full instructions here, but it's typically just a matter of (from an Admin PowerShell):

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
    Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
    New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
    Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}

Let's assume for the sake of this next command that:

  • Your API server is 10.0.0.5 (accessible only from the VPN)
  • Your API is running on port 8000 on the remote server
  • You want the API to be accessible on port 80 in Postman
  • Your Windows username is heydude101

With that in place, in Ubuntu/WSL2 (assuming Bash), issue the following command:

ssh -R 80:10.0.0.5:8000 heydude101@$(hostname).local

Log in with your Windows password.

  • The `$(hostname).local will find the correct address for the Windows SSH server using mDNS as I explain more thoroughly in this answer.

  • The -R sets up remote forwarding so that the Windows OpenSSH server will start forwarding connections:

    • from localhost:80
    • through Ubuntu
    • to the remote API server

So now, connecting Postman to localhost:80 should allow you to access the API.

If the API server has a requirement for a particular hostname, then you can set that up in your Windows hosts file. Just map the hostname to 127.0.0.1 so that it resolves locally.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .