6

I am running a local AEM server in my Windows machine. The server is running on localhost:4502. I am using Ubuntu distro running in WSL2 for my development. I want to access the localhost:4502 running in the Windows machine in my WSL2 Ubuntu.

Is there any way to do that or is it not possible ?

Ganesh A.S
  • 63
  • 1
  • 4
  • Your Windows's machine IP plus the 4502 should be enough, though you would like to check that the firewall is allowing the connection, – ronnyfm Nov 10 '20 at 12:12

3 Answers3

1

Windows 10 considers localhost as ::1 Ubuntu considers localhost as 127.0.0.1

So solution is to create a mapping

create a file called .wslconfig in C:\Users<your_username>.wslconfig

add the following to it.

[wsl2]
localhostForwarding=true

PS: I dont know if it mess up anything else but it helped me run django servers which were broken after upgrading to wsl2

Vipin Mohan
  • 1,529
  • 10
  • 21
  • 1
    `localhostForwarding` should already [default to `true`](https://docs.microsoft.com/en-us/windows/wsl/wsl-config#wsl-2-settings) on WSL2, but sometimes it seems to break down, and I haven't been able to identify a cause. Usually just doing a `wsl --shutdown` and restarting the session will restore it for most people. – NotTheDr01ds Jan 27 '21 at 00:56
  • This answer really needs at least one correction. ::1 vs 127.0.0.1 has absolutely nothing to do with Windows 10 vs. Ubuntu. Windows 10 understands 127.0.0.1 just fine, and Ubuntu understands ::1 just fine, too. The real difference is that ::1 is the IPv6 address, and 127.0.0.1 (or any IP address starting with 127, really) is IPv4. – Kevin Keane Apr 24 '21 at 20:05
  • so please do explain exactly why this fixed my issue? because as far i'm concerned it fixed the issue. and apparently for the users as well. – Vipin Mohan Apr 26 '21 at 06:44
-1

This really belongs on another forum, but I suspect you could do this.

  1. Step 1. Run your AEM server on your actual IP address (or all addresses) instead of binding to just localhost.

  2. Step 2. Your Ubuntu WSL client instance won't share localhost with the host machine, but it will share the local IP address your machine actually has (e.g. 10.0.0.2). Just have your client connect to that IP address instead of localhost.

  3. I don't know anything about AEM, but you might need to secure it if you are exposing it to a larger network. Block port 4502 on the upstream firewall or use a Windows Firewall rule to only allow incoming on port 4502 from your own IP address. This certainly appears possible.

selbie
  • 82,148
  • 13
  • 83
  • 154
-1

This is simple, you just need to do 2 things. set ip address to localhost in hosts file and allow windows firewall to allow incoming connections. Here are steps by step instructions:

  1. Get IP address, open cmd type ipconfig /all, note down ip address 172.22.16.1 image
  2. Open notepad as administrator, File->open , browse to C:\Windows\System32\drivers\etc\hosts , add line 172.22.16.1 localhost, save and close.
  3. Last option is to allow Firewall rules to accept public connections, for this open control panel > System and Security > Windows Defender Firewall > Advanced Settings > Inbound Rules > 'New Rule`
  4. Rule Type : choose Port , click next
  5. Protocol and Ports : type *Specific local port: 4502 , click next
  6. Action : Allow the connection , click next
  7. Profile : check Public , click next
  8. Name : type AEM server , click finish
  9. close other windows, again open cmd , type wsl --shutdown for shutdown ubuntu subsystem.
  10. open ubuntu again.
  11. testing connection type curl localhost:4502 in command prompt. if it returns something means you are good to go.
sorabh86
  • 343
  • 3
  • 15