Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

DHCP, Vagrant, nao consigo acessar nginx pelo ip na maquina host

Segue o passo a passo do que eu fiz.

Seguindo a aula escrevi meu Vagrantfile;

Vagrant.configure("2")  do  |config|

config.vm.box =  "ubuntu/bionic64"

config.vm.network :forwarded_port,  guest:  80,  host:  8089

config.vm.network "private_network",  type:  "dhcp"

end

No terminal;

$ vagrant up 
$ vagrant ssh

Conexão ssh;

Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-88-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun Mar  1 01:34:44 UTC 2020

  System load:  0.0               Processes:             97
  Usage of /:   11.7% of 9.63GB   Users logged in:       0
  Memory usage: 13%               IP address for enp0s3: 10.0.2.15
  Swap usage:   0%                IP address for enp0s8: 172.28.128.1

 * Multipass 1.0 is out! Get Ubuntu VMs on demand on your Linux, Windows or
   Mac. Supports cloud-init for fast, local, cloud devops simulation.

     https://multipass.run/

 * Latest Kubernetes 1.18 beta is now available for your laptop, NUC, cloud
   instance or Raspberry Pi, with automatic updates to the final GA release.

     sudo snap install microk8s --channel=1.18/beta --classic

0 packages can be updated.
0 updates are security updates.


Last login: Sun Mar  1 00:55:58 2020 from 10.0.2.2

ifconfig host;

vboxnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.28.128.1  netmask 255.255.255.0  broadcast 172.28.128.255
        inet6 fe80::800:27ff:fe00:0  prefixlen 64  scopeid 0x20<link>
        ether 0a:00:27:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 147  bytes 24966 (24.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ifconfig guest;

enp0s3: 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::33:ecff:fef4:7d44  prefixlen 64  scopeid 0x20<link>
        ether 02:33:ec:f4:7d:44  txqueuelen 1000  (Ethernet)
        RX packets 519  bytes 55898 (55.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 378  bytes 53876 (53.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.28.128.1  netmask 255.255.255.0  broadcast 172.28.128.255
        inet6 fe80::a00:27ff:fe27:2141  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:27:21:41  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 18  bytes 1396 (1.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

RESULTADO: não consigo acessar nginx pelo ip 172.28.128.1

OBS. O acesso via http://localhost:8089/ esta funcionando corretamente e com IP fixo também.

Consegui fazer funcionar alterando meu Vagrantfile para;

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.network "private_network", type: "dhcp",
    ip: "172.28.128.5",
    netmask: "255.255.255.0"
end

desta forma consigo acessar tanto pelo ip 172.28.128.5 com 172.28.128.1

Porque não estava funcionando ? Porque agora funciona ?

1 resposta
solução!

Olá Marcelo, tudo bem? Você verificou qual a faixa de IP da sua rede local? Outro problema que pode está acontecendo é a questão da destruição da máquina, você executou o comando vagrant destroy -f na máquina antes de colocar essa nova configuração de "dhcp"? E realizou a instalação do "nginx" após a criação da máquina com "dhcp"? Temos que verificar esses pontos, porque era para você conseguir acessar normalmente pelo 172.28.128.1 sendo obtido por meio do DHCP do VirtualBox.