Hi, I have setup a lab environment with virtualbox on a fedora 41 VM, I did a
vagrant init
in a new directory, then updated vagrant file to create 3 boxes, 1 ubuntu and 2 centos 6.6. using private_network as follows
Vagrant.configure("2") do |config|
config.vm.define "acs" do |acs|
acs.vm.box = "ubuntu/trusty64"
acs.vm.hostname = "acs"
acs.vm.network "private_network", ip: "192.168.56.10"
end
I am able to ssh to the boxes when I am inside the directory but I need from time to time to to ssh from the fedora host command line. Is this possible or should I use a different network model?
Thanks for your help
you can add forwarded ports. By the way, Vagrant automatically sets up a port for SSH, which can be queryed using vagrant port command. If you want to explicitly specify a port, you can use acs.vm.network "forwarded_port", guest: 80, host:8080 and this way you can acces your guest’s http port on the host’s 8080. I think the default SSH forward port is 2222, so you can run ssh -p 2222 yourname@127.0.0.1 to access your VM.
Also you can run vagrant ssh-config acs and it will give you a config stanza that you can use in your host machine to access your host. Like this:
Vagrant_lab_env> vagrant ssh-config control
Host control
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile D:/RedHat_lab/.vagrant/machines/control/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
PubkeyAcceptedKeyTypes +ssh-rsa
HostKeyAlgorithms +ssh-rsa
This config also includes the ssh key that Vagrant created for you on box creation, so you can access your box without password.