0

I am trying to run vscode-server which currently has no functionality to change which port the server is run on.

The port its set to use by default is currently in use by another program.

Is it possible to redirect it to another port in the system outside of changing the actual program?

2
  • Can it bind only to selected interfaces? Can you bind the other program on ipv6 exclusively and vscode on ipv4 (or vice versa)? If nothing else works, you can try LD_PRELOAD and capture the library call (but this is kind of desperation measure). The best and easiest way IMHO is to run it in a container. Jun 22, 2021 at 5:58
  • 1
    A sketch, hint what to research; therefore just a comment: 1) Create a separate network namespace. 2) Connect it to the default namespace with a veth pair. You want the default namespace to behave like a home router, the new namespace to be like a device connected to its LAN. 3) Set up addresses and SNAT like you would if you were building a home router. 4) Set up DNAT. Here's where you translate unused port of your "real" IP address to the desired port inside the new network namespace. 5) Run the program inside the namespace. Useful link. Jun 22, 2021 at 6:27

1 Answer 1

0

This is a great application for the utility socat. You can listen on a specific port of your choosing and forward that back to the localhost port the vscode-server is running on, forking and re-using the original address for multiple connections to the server. The basic syntax for what you're wanting would be:

socat TCP4-LISTEN:<new_port> TCP-4:127.0.0.1:<vscode_port>

The manual page for the utility will give you more options, but that should cover the basics. A quick 'getting started' page is located at https://www.redhat.com/sysadmin/getting-started-socat

4
  • When I launch the vscode server I still receive an error saying the address already in use ":::8000"
    – Atzin
    Jun 24, 2021 at 23:43
  • You should launch the vscode server first, so that it can bind to the appropriate port, then launch the socat utility, to start the redirection.
    – Thomas N
    Jun 30, 2021 at 21:05
  • Sorry, I missed the critical part of "[the port is] currently in use by another program". Is there any way to move that program to another port?
    – Thomas N
    Jun 30, 2021 at 21:16
  • No its currently in use by a lot of other users who have their setting already configured to use that port.
    – Atzin
    Jul 2, 2021 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.