title: Vagrant - Port forwarding behavior with private networks
body: <p>I am testing nginx setup with vagrant but I seem to be missing some minute detail because of which when I try to reach nginx from host on a static ip, the connection times out. My Vagrant file:</p>
  
  <pre><code>   # -*- mode: ruby -*-
     # vi: set ft=ruby :
     $script = &lt;&lt;-SCRIPT
       sudo apt-get -y update
       sudo apt-get install -y nginx
     SCRIPT
  
     ###################################
     Vagrant.configure("2") do |config|
     # webserver server
     config.vm.define "webserver" do |webserver|
        webserver.vm.box = "bento/ubuntu-16.04"
        webserver.ssh.insert_key = false
        webserver.vm.network "private_network", ip: "192.168.10.101"
        webserver.vm.network "forwarded_port", guest: 80 , host: 4000, host_ip: "127.0.0.1"
        webserver.vm.hostname = "webserver"
        webserver.vm.provision "shell", inline: "sed 's/127\.0\.0\.1.*webserver.*/192\.168\.10\.101 webserver/' -i /etc/hosts"
        webserver.vm.provider "virtualbox" do |vb|
        # Customize VM
         vb.name = "webserver"
         vb.memory = "1024"
         vb.cpus = "2"
        end
     end
   end
  </code></pre>
  
  <p>I am able to reach nginx vi localhost:4000 but if I do <a href="http://192.168.10.101:4000" rel="nofollow noreferrer">http://192.168.10.101:4000</a>, the connection times out. I have also tried to stop firewall as below:</p>
  
  <pre><code> vagrant@webserver:~$ sudo ufw disable
   Firewall stopped and disabled on system startup
  </code></pre>
  
  <p>Does not help. Any guidance on this please?</p>
  
  <p>EDIT - 1</p>
  
  <p>I removed the virtualbox private network after reading documentation at <a href="https://www.vagrantup.com/docs/virtualbox/networking.html" rel="nofollow noreferrer">https://www.vagrantup.com/docs/virtualbox/networking.html</a>. However, the issue is bit confusing because now I can access nginx test page at :
  <a href="http://192.168.10.101" rel="nofollow noreferrer">http://192.168.10.101</a> but not at <a href="http://192.168.10.101:4000" rel="nofollow noreferrer">http://192.168.10.101:4000</a>. Although I can access <a href="http://localhost:4000" rel="nofollow noreferrer">http://localhost:4000</a>. May be I am missing something. </p>
  
  <p>EDIT - 2</p>
  
  <p>Ran a python simplehttpserver in the vm and forwarded port:</p>
  
  <pre><code>   python -m SimpleHTTPServer 8000
  </code></pre>
  
  <p>Vagrantfile</p>
  
  <pre><code>   dbserver.vm.network "forwarded_port", guest: 8000 , host: 5000, host_ip: "127.0.0.1"
  </code></pre>
  
  <p>But I can access my test page :</p>
  
  <p><a href="http://192.168.10.102:8000/" rel="nofollow noreferrer">http://192.168.10.102:8000/</a></p>
  
  <p>but not as </p>
  
  <p><a href="http://192.168.10.102:5000/" rel="nofollow noreferrer">http://192.168.10.102:5000/</a></p>
  
  <p>So this makes me think that there is some rule that allows me to access my virtualbox ports without actual port forwarding on private networks. </p>
  
  <pre><code>  $&gt; netstat -nr
    Routing tables
  
    Internet:
    Destination        Gateway            Flags        Refs      Use   Netif Expire
    default            192.168.0.1        UGSc           40        0     en0
    127                127.0.0.1          UCS             0        0     lo0
    127.0.0.1          127.0.0.1          UH              4    57934     lo0
    169.254            link#4             UCS             0        0     en0
    192.168.0          link#4             UCS             0        0     en0
    192.168.0.1/32     link#4             UCS             1        0     en0
    192.168.0.1        c0:a0:bb:c6:f5:58  UHLWIir        48     6051     en0   1188
    192.168.0.101/32   link#4             UCS             0        0     en0
    192.168.10         link#17            UC              2        0 vboxnet
    192.168.10.102     8:0:27:1b:d5:98    UHLWI           0       73 vboxnet    586
    224.0.0/4          link#4             UmCS            2        0     en0
    224.0.0.251        1:0:5e:0:0:fb      UHmLWI          0        0     en0
    239.255.255.250    1:0:5e:7f:ff:fa    UHmLWI          0     1067     en0
    255.255.255.255/32 link#4             UCS             0        0     en0
  </code></pre>