0

I use Ubuntu in my virtual machine and start from there my code projects. These project when active can be run under localhost:3000.

Now when i execute in Ubuntu ifconfig I get following result:

screen

If I try to ping the marked address I get a reply (from windows). But somehow I cant access http://192.168.145.129:3000 from my browser I also tried the hostname http://ubuntu:3000. I assume this is because of some firewall settings in my windows.


I am workin behind a coporate proxy. So to be able to browse in the internet in the VM. As of my VM-Network-Settings I use NAT (Used to shar the hosts IP address).

Does someone know how to access localhost from VM?

I also checked with tcpdump -i ens33 port 3000 if i receive any packages and I do.

EDIT Result of netstat -tnlp

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:63342         0.0.0.0:*               LISTEN      3087/java           
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN      3378/node           
tcp        0      0 127.0.0.1:3128          0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:6942          0.0.0.0:*               LISTEN      3087/java           
tcp6       0      0 ::1:631                 :::*                    LISTEN   
2
  • 1
    Are you sure your service listen on 192.168.145.129 too, and not on localhost only? Can you edit your question and add the output of netstat -tlnp or ss -tlnp? Also, please copy/paste the results as you should avoid posting pictures of text. Pictures can be hard to read. Text is easier to read in different screen formats, can be copied and pasted, as well as is search engine addressable, making it easier for people to reach this post who may have a similar issue. Apr 15, 2019 at 10:02
  • Okay thanks for the feedback! Yeah I updated my question with the netstat -tlnp result.
    – MarcoLe
    Apr 15, 2019 at 10:17

1 Answer 1

2

As you can see from the netstat output, your service is listening on localhost only!

[snip]
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN      3378/node           
[snip]

You will never reach it from "the outside".

The best way to address this is surely service-dependent. For example, for a simple PHP server, you can use php -S 0.0.0.0:3000 to make it listen on all interfaces and not on localhost only.

But as a fast workaround you can forward the port with iptables, for example:

iptables -t nat -I PREROUTING -p tcp -i ens33 -d 192.168.145.129 --dport 3000 -j DNAT --to-destination 127.0.0.1:3000

Don't forget to enable routing to the localhost with:

sysctl -w net.ipv4.conf.ens33.route_localnet=1

I've used ens33 as looks like (from the screenshot) that it's your "external" network interface, please udpate the rules accordingly if not.

3
  • That worked liked a charm! thanks! But im asking myself why does it not work if the VM Connection is set to NAT and accessing it directly via localhost:3000 does not work...
    – MarcoLe
    Apr 15, 2019 at 13:11
  • 1
    @creep-story well, the "NAT" part of the VM configuration usually means that the host behaves like a NAT-router, i.e. it masquerades the internal VM network with it's own IP address when the VMs need to access the external network(s). It has little to do with the reverse (i.e. you need to access the internal VM network from the outside), which is a different kind of NAT, it's more port forwarding than Network Address Translation. Apr 15, 2019 at 13:29
  • 1
    Okay network engineering is not my strengh. But thanks for beeing so kind to explain me some basics. Btw. I figured out how to make the server accesible via external IP I am using webpack (a JS-Library) and I just needed to add this config webpack-dev-server --port 3000 --host 0.0.0.0
    – MarcoLe
    Apr 15, 2019 at 13:43

You must log in to answer this question.

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