Do I need port-forwarding to communicate from host to guest?

12 views
Skip to first unread message

zveratko

unread,
Mar 6, 2020, 6:17:45 AM3/6/20
to Vagrant
I have set up some vagrant box and I want to connect to some services running on it. I used this to set up the networking

 config.vm.network "private_network", ip: "192.168.10.101"


I checked in VirtualBoxUI and the machine has two interfaces NAT with port forwarding 2222->22(probably the eth0) and HOST_ONLY(eth1?) 

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet
10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80
::a00:27ff:fec2:4a97  prefixlen 64  scopeid 0x20<link>
        ether
08:00:27:c2:4a:97  txqueuelen 1000  (Ethernet)
        RX packets
27643  bytes 24238095 (23.1 MiB)
        RX errors
0  dropped 0  overruns 0  frame 0
        TX packets
11304  bytes 1136140 (1.0 MiB)
        TX errors
0  dropped 0 overruns 0  carrier 0  collisions 0


eth1
: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet
192.168.10.101  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80
::a00:27ff:fe19:fc5  prefixlen 64  scopeid 0x20<link>
        ether
08:00:27:19:0f:c5  txqueuelen 1000  (Ethernet)
        RX packets
3053  bytes 278689 (272.1 KiB)
        RX errors
0  dropped 0  overruns 0  frame 0
        TX packets
2380  bytes 683097 (667.0 KiB)
        TX errors
0  dropped 0 overruns 0  carrier 0  collisions 0


Do I need port forwarding to access some service running inside on port ie.80? I have just tested that I can putty in by localhost:2222 or 192.168.10.101:22

In which setting I can ommit port forwarding and just call guest with its ip? I have some problems connecting to another service and I am not sure whather it just listen to localhost only or something else is wrong.

Is this sentence I noted some time ago correct

port forwarding is not needed when using private network and accessing guest from host with guest private ip, port forwarding is used to access guest with localhost/127.0.0.1 the ports are then forwarded

Alvaro Miranda Aguilera

unread,
Mar 7, 2020, 6:59:34 AM3/7/20
to vagra...@googlegroups.com
hello

if you want to access something on port 80 then you can use 192.168.10.101:80

http://192.168.10.101


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/63a27481-91a3-42b4-a93a-4aa7c49a424f%40googlegroups.com.


--
Alvaro

zveratko

unread,
Mar 9, 2020, 5:27:08 AM3/9/20
to Vagrant
I am asking because I am not sure how those public/bridged etc. networking between host/guest works. Sometime I cannot see the port on the host. Maybe it is because the app in the VM is restricted to accept localhost connection only, but I always strugling to find the exact place of the error.

Are those option equal ?
call 192.168.10.101:80 on host machine
make port-forward 80:80 and call localhost:80 on host machine

Is the first option using NAT while the second is not?


On Saturday, March 7, 2020 at 12:59:34 PM UTC+1, Alvaro Miranda Aguilera wrote:
hello

if you want to access something on port 80 then you can use 192.168.10.101:80

http://192.168.10.101


To unsubscribe from this group and stop receiving emails from it, send an email to vagra...@googlegroups.com.


--
Alvaro

Alvaro Miranda Aguilera

unread,
Mar 9, 2020, 12:49:32 PM3/9/20
to vagra...@googlegroups.com
Hello

On a technical side both are similar.

However in Linux/MacOS, only root or elevated process can open port under 1024

So people usually do port forwarding like 8080 -> VM:80

using the private ip:80 feels more like working with your own server over the network

of course there is nothing bad using one or the other, as both do the same.

on same high traffic task, sometimes port forward / nat can be slower than hitting private_ip:80

Alvaro.

To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/679b3a9b-72e1-4d42-99ca-08860553bc23%40googlegroups.com.


--
Alvaro

Reply all
Reply to author
Forward
0 new messages