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:


If I try to ping the marked address I get a reply (from windows). But somehow I cant access 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*               LISTEN      3087/java           
tcp        0      0 *               LISTEN      -                   
tcp        0      0 *               LISTEN      -                   
tcp        0      0*               LISTEN      3378/node           
tcp        0      0*               LISTEN      -                   
tcp        0      0*               LISTEN      3087/java           
tcp6       0      0 ::1:631                 :::*                    LISTEN   
  • 1
    Are you sure your service listen on 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. – Mr Shunz Apr 15 at 10:02
  • Okay thanks for the feedback! Yeah I updated my question with the netstat -tlnp result. – creep-story Apr 15 at 10:17

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

tcp        0      0*               LISTEN      3378/node           

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 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 --dport 3000 -j DNAT --to-destination

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.

  • 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... – creep-story Apr 15 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. – Mr Shunz Apr 15 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 – creep-story Apr 15 at 13:43

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.