Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual box vagrant do not set /etc/hosts correctly #169

Open
rrameshbtech opened this issue Sep 4, 2024 · 1 comment
Open

Virtual box vagrant do not set /etc/hosts correctly #169

rrameshbtech opened this issue Sep 4, 2024 · 1 comment

Comments

@rrameshbtech
Copy link

I am setting up cluster using /virtualbox/ folder. But it does not set the /etc/hosts/. The output of vagrant up below

    Setting /etc/hosts on nodes...
Uploading hosts.tmp to /tmp/hosts.tmp
Upload has completed successfully!

  Source: hosts.tmp
  Destination: /tmp/hosts.tmp
	  controlplane
  node01
  node02
Uploading hosts.tmp to /tmp/hosts.tmp
Upload has completed successfully!

  Source: hosts.tmp
  Destination: /tmp/hosts.tmp
	  controlplane
  node01
  node02
Uploading hosts.tmp to /tmp/hosts.tmp
Upload has completed successfully!

  Source: hosts.tmp
  Destination: /tmp/hosts.tmp
	  controlplane
  node01
  node02

VM build complete!

Use either of the following to access any NodePort services you create from your browser
replacing "port_number" with the number of your NodePort.

  http://:port_number
  http://:port_number

Though I set it manually and set ssh. after vagrant halt & vagrant up then all the ssh settings were lost.
I am using BRIDGE mode.
Any help appriciated.

@lurodrig
Copy link

lurodrig commented Sep 13, 2024

Hello @rrameshbtech and others,

I am suffering this issue too. It looks like the the root cause can be in the setup-hosts.sh script:

MY_IP="$(ip route | grep default | grep -Pv '10\.\d+\.\d+\.\d+' | awk '{ print $9 }')"

When setup-hosts.sh is executed, above returns "", not informing the MY_IP var. This value is used in the public-ip script which is invoked by the Vagrantfile to complete the creation of the /etc/hosts file in the VMs

If you still want to use the bridge mode a quick, dirty and temporary workaround can be to setup these IPs manually in the /etc/hosts file, inform the PRIMARY_IP env var and set its value in the /etc/environment file.

Funny thing is that couple of weeks ago this bridge mode was working fine for me, it seems that the setup_dns function was being executed "too early" 😅 when the VM networking (IP, gateway...) is not yet ready 🤔

Good news are that NAT mode works like a charm 🙌, so maybe this could be an option for you.

Hope it helps,

Luis

ps: nevertheless it would be nice if BRIDGE mode would work for me too (as it is the default one). My stack looks like this:

virtualbox --help
Oracle VM VirtualBox VM Selector v7.0.16_Ubuntu

$ vagrant version
Installed Version: 2.4.1
Latest Version: 2.4.1

$ cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.1 LTS"

ip -c route
default via 192.168.1.1 dev wlp2s0 proto dhcp src 192.168.1.33 metric 600 
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown 
192.168.1.0/24 dev wlp2s0 proto kernel scope link src 192.168.1.33 metric 600 
192.168.56.0/24 dev vboxnet0 proto kernel scope link src 192.168.56.1

With this conf my VMs are running with these IPs:

vagrant@controlplane:~$ ip -c a | grep -w inet | grep -v 127
    inet 10.0.2.15/24 metric 100 brd 10.0.2.255 scope global dynamic enp0s3
    inet 192.168.56.11/24 brd 192.168.56.255 scope global enp0s8

vagrant@node01:~$ ip -c a | grep -w inet | grep -v 127
    inet 10.0.2.15/24 metric 100 brd 10.0.2.255 scope global dynamic enp0s3
    inet 192.168.56.21/24 brd 192.168.56.255 scope global enp0s8

vagrant@node02:~$ ip -c a | grep -w inet | grep -v 127
    inet 10.0.2.15/24 metric 100 brd 10.0.2.255 scope global dynamic enp0s3
    inet 192.168.56.22/24 brd 192.168.56.255 scope global enp0s8

Thank you in advance 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants