Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

DNS for a localhost on my personal machine #44

Open
KyleJamesWalker opened this issue Sep 14, 2022 · 4 comments
Open

DNS for a localhost on my personal machine #44

KyleJamesWalker opened this issue Sep 14, 2022 · 4 comments
Assignees
Labels
enhancement New feature or request IP-routing p1

Comments

@KyleJamesWalker
Copy link

Is there a way connect to my laptop's machine running a local port?

We use StrongDM to connect to secure system, and the StrongDM node is protected by our VPC. So we need to connect to the VPN and then have StrongDM open a local port. Something like host.docker.internal does when needing to connect to your host machine.

;TLDR Add dns like host.gh-net.internal to connect to ports on your personal machine.

@KyleJamesWalker KyleJamesWalker added the enhancement New feature or request label Sep 14, 2022
@legomushroom
Copy link
Contributor

hey @KyleJamesWalker 👋 This scenario was not the main focus for the extension, but we definitely want to support this. In fact, unless you have some exotic network setup, it should work already 🤗

Given your local machine's default network interface has a distinct IP address (IP address that is not on any subnets of the network interfaces inside your Codespace), the extension should be able to find route and forward traffic to it. The missing part is the DNS name of course, but that is fix - add a {IP address} host.gh-net.internal record to the /etc/hosts file inside the Codespace 💻 I'll be working on supporting this by default and officially next tho, so would be great if you can give it a shot when it's ready 😊

Try this:

  1. Find out default gateway interface on your local machine. For me it is 192.168.86.31 on my local network. If the IP address is not unique enough compared to the network interface subnets inside a Codespace, you can add an additional IP alias to the local interface.
  2. Start a server on 0.0.0.0 host and a port, for instance 3000.
  3. Start gh-net extension and connect to a Codespace.
  4. Try to make a request from within the Codespace to the server using the default interface IP address. For instance if that is an HTTP server, wget -d 192.168.86.31:3000 would do the trick.

If this works for you, you can also add the aforementioned record to the hosts file inside Codespace to be able to make the request by the host name.

Few questions:

  • Are you on mac, windows or linux machine?
  • What transport protocols do you need? (e.g. TCP/UDP/SCTP etc)

Thanks!

@KyleJamesWalker
Copy link
Author

KyleJamesWalker commented Sep 16, 2022

Thanks for the detailed response, for some reason this isn't working here's what I did:

  1. Ran route get default | grep gateway
    • Result: 192.168.10.65
  2. Start a basic http server with: docker run --rm -it -p 0.0.0.0:8000:80 strm/helloworld-http
  3. Test locally: wget -d http://192.168.10.65:8000
DEBUG output created by Wget 1.21.3 on darwin21.3.0.

Reading HSTS entries from /Users/kyle.walker/.wget-hsts
URI encoding = ‘UTF-8’
Converted file name 'index.html' (UTF-8) -> 'index.html' (UTF-8)
--2022-09-16 11:56:09--  http://192.168.10.65:8000/
Connecting to 192.168.10.65:8000... connected.
Created socket 3.
Releasing 0x00006000038341e0 (new refcount 0).
Deleting unused 0x00006000038341e0.

---request begin---
GET / HTTP/1.1
Host: 192.168.10.65:8000
User-Agent: Wget/1.21.3
Accept: */*
Accept-Encoding: identity
Connection: Keep-Alive

---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/2.7.9
Date: Fri, 16 Sep 2022 18:56:08 GMT
Content-type: text/html
Content-Length: 102
Last-Modified: Fri, 16 Sep 2022 18:55:12 GMT

---response end---
200 OK
Registered socket 3 for persistent reuse.
Length: 102 [text/html]
Saving to: ‘index.html’

index.html                                                            100%[========================================================================================================================================================================>]     102  --.-KB/s    in 0s

2022-09-16 11:56:09 (48.6 MB/s) - ‘index.html’ saved [102/102]
  1. Start the codespace
  2. Start the extension: sudo gh net start
  3. From within the codespace run: wget -d http://192.168.10.65:8000
DEBUG output created by Wget 1.21 on linux-gnu.

Reading HSTS entries from /home/vscode/.wget-hsts
URI encoding = ‘UTF-8’
Converted file name 'index.html' (UTF-8) -> 'index.html' (UTF-8)
--2022-09-16 19:02:58--  https://192.168.10.65:8000/
Certificates loaded: 129
Connecting to 192.168.10.65:8000... ^C
  1. Try running ping: ping 192.168.10.65:
PING 192.168.10.65 (192.168.10.65): 56 data bytes
^C--- 192.168.10.65 ping statistics ---
57 packets transmitted, 0 packets received, 100% packet loss
  1. Try traceroute: traceroute 192.186.10.65
traceroute to 192.186.10.65 (192.186.10.65), 30 hops max, 60 byte packets
 1  * * *
 2  * * *
 3  * * *
...
28  * * *
29  * * *
30  * * *

I'm on a Mac M1 Max and need TCP.

  • Are you on mac, windows or linux machine?
  • What transport protocols do you need? (e.g. TCP/UDP/SCTP etc)

Edit: Additionally I tried all the ip address that came back with ifconfig | grep "inet " just to be sure one of the other was working

@legomushroom
Copy link
Contributor

legomushroom commented Sep 20, 2022

@KyleJamesWalker thanks for trying it out! Sorry I was not clear enough - you want to find out the IP address of the interface that will forward to the default gateway(aka default interface IP), not the default gateway IP itself. I usually do this:

ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' 

Given you've tried all of them, I assume you've also tried the correct one already. As I said this is not yet "officially" supported yet, so it might not work in all cases. I'm looking into adding such support at the moment.

If you need TCP only, you can go a bit simpler route to unblock yourself meanwhile. The approach based on using reverse port forwarding capabilities of the SSH.

  1. Set the 127.0.0.1 local record in the /etc/hosts file on your local machine.
  2. Use GH CLI to SSH into a Codespace and reverse port-forward:
gh codespace ssh -- -R 3000:local:3000

Of course you can use the host.gh-net.internal or similar instead of the local above.

@KyleJamesWalker
Copy link
Author

Fantastic this worked perfectly for me! Thank you so much!!!!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request IP-routing p1
Projects
None yet
Development

No branches or pull requests

2 participants