patternMinor
Bridged network adapter for Packer + VirtualBox?
Viewed 0 times
virtualboxpackeradapterbridgedfornetwork
Problem
So,
I load an .ova image with packer of a minimal ubuntu linux installation.
I realized after everything went through (Provisioners etc) and it successfully exported the output file. However, when loading the output image with VirtualBox I can't communicate with the box, because the box doesn't have a valid network adapter that allows me to ping it etc.
So I tried adding a bridged adapter one during the build process:
However the machine is still not reachable.
This is how it looks on the VM:
How can I ensure that my box is always reachable from the outside?
Is adding a network bridge adapter even the right way? What am I doing wrong?
I think I need the VM to have an IP like 192.168.x.x
I load an .ova image with packer of a minimal ubuntu linux installation.
I realized after everything went through (Provisioners etc) and it successfully exported the output file. However, when loading the output image with VirtualBox I can't communicate with the box, because the box doesn't have a valid network adapter that allows me to ping it etc.
So I tried adding a bridged adapter one during the build process:
"vboxmanage": [[ "modifyvm", "{{.Name}}", "--nic2", "bridged", "--bridgeadapter2","enp0s31f6" ]]However the machine is still not reachable.
This is how it looks on the VM:
How can I ensure that my box is always reachable from the outside?
Is adding a network bridge adapter even the right way? What am I doing wrong?
I think I need the VM to have an IP like 192.168.x.x
Solution
With a bridged adapter, your VM would get its IP from the host machine's network DHCP server. This would allow it to be pinged from your internal network.
I'd also specify in your configuration that your cable is connected as so:
Port forwarding in the VM's configuration would also work. It would allow access from the host machine's IP by just specifying the forwarded port.
To forward port 22 to 2222 you would do as so:
If you want it to be accessible by the internet, you would need do port forwarding on your router to route access from your public ip:port to your internal ip:port.
I'd also specify in your configuration that your cable is connected as so:
VBoxManage modifyvm "VM" --cableconnected1 onPort forwarding in the VM's configuration would also work. It would allow access from the host machine's IP by just specifying the forwarded port.
To forward port 22 to 2222 you would do as so:
VBoxManage modifyvm "VM" --nic1 nat
VBoxManage modifyvm "VM" --natpf1 "guestssh,tcp,,2222,,22"
VBoxManage modifyvm "VM" --cableconnected1 onIf you want it to be accessible by the internet, you would need do port forwarding on your router to route access from your public ip:port to your internal ip:port.
Code Snippets
VBoxManage modifyvm "VM" --cableconnected1 onVBoxManage modifyvm "VM" --nic1 nat
VBoxManage modifyvm "VM" --natpf1 "guestssh,tcp,,2222,,22"
VBoxManage modifyvm "VM" --cableconnected1 onContext
StackExchange DevOps Q#9909, answer score: 3
Revisions (0)
No revisions yet.