1

I have a service listening on port :3000. However, I would like to change that to port :8080. Unfortunately, the program that I'm running does not allow me to change the listen port.

Is there any way that I could have localhost forward port :3000 to port :8080? So when I connect externally on :8080 it will forward that traffic to :3000?

I tried the socat commnand, but it didn't seem to work.

Edit: I tried the following command (found here). It didn't display anything, but the command kept running. When I tried to open it in Firefox, it just kept loading forever, eventually getting the connection timed out error. In chrome it said that the connection was reset. I apologize if this was me not configuring the command properly, I'm not familiar with socat or networking.

socat tcp-listen:8080,reuseaddr,fork tcp:localhost:3000

Edit 2: I ran nmap on localhost (sshing into the device), scanning for all ports. For some reason, it didn't show port :3000 as open. However, when I used its public IP address rather than localhost, port :3000 showed up. I'm hosting through Linode, if anybody knows why this is happening.

Edit 3: So the port is apparently forwarding properly, because when I use the curl command (using the public IP), it gives me the correct HTML code and an HTTP 200 OK status. But when I try to open it in a browser, I get connection timed out (Firefox) or connection was reset (Chrome). So it seems to be a browser issue. I know I'm trying to connect via HTTPS on port 8080, if that has anything to do with it.

Thanks in advance!

  • 2
    socat should be able to do this. Can you edit your answer to include details about what you tried with socat and how it failed? – satwell Mar 14 '22 at 18:03
  • @satwell I edited my post to include the details of my experience with the socat command. – Blue Herring Mar 14 '22 at 18:47
  • 1
    The socat command you're trying should work. A connection refused error from socat indicates that it can't actually connect to localhost on port 3000. So either you don't have anything listening on localhost port 3000, or localhost is not resolving the way you expect. Including an example error from socat would help. Also the output of netstat -ln | grep :3000 will help diagnose whether there's anything listening for connections on port 3000 and at what addresses. – satwell Mar 14 '22 at 18:58
  • Is it possible that a firewall is blocking this port? – mnme Mar 14 '22 at 20:06
  • 1
    @satwell My apologies, I had accidentally switched 3000's and 8080's place in the command. I put them in their proper places, and it just doesn't output anything, but the command continues to run. As for @mnme's post, I am sure there is no firewall blocking the port. I ran a test with node.js, and I could access that just fine. – Blue Herring Mar 14 '22 at 21:40
  • 1
    Just to make sure I understand correctly, socat is now running without printing errors, but Firefox is behaving as though the URL is unreachable, right? The next step would be to try curl instead of Firefox: curl -v http://<ip>:8080. Using curl will provide clearer debugging information than Firefox. – satwell Mar 15 '22 at 02:55
  • @satwell The curl command worked just fine. I got an HTTP 200 OK response and the correct HTML code. But when I open it in Firefox, it loads for several minutes before telling me that the connection timed out. – Blue Herring Mar 15 '22 at 12:10

0 Answers0