<p>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. </p>

<p>I'd also specify in your configuration that your cable is connected as so:</p>

<pre><code>VBoxManage modifyvm "VM" --cableconnected1 on
</code></pre>

<p>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.</p>

<p>To forward port 22 to 2222 you would do as so: </p>

<pre><code>VBoxManage modifyvm "VM" --nic1 nat
VBoxManage modifyvm "VM" --natpf1 "guestssh,tcp,,2222,,22"
VBoxManage modifyvm "VM" --cableconnected1 on
</code></pre>

<p>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.</p>

<p><a href="https://i.sstatic.net/Lre4M.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Lre4M.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2019-11-29T15:02:20.113Z
Yeah, that's the problem. Despite adding a bridged adapter it does not automatically get a ip assigned. I do have to add a hostonly-adapter over the UI that is configured so that the VM can get a proper IP. Is there a way to do this over the commandline too?
Kyu96
CC BY-SA 4.0
2019-11-29T20:51:17.430Z
For creating a hostonly-adapter, you would do the following: VBoxManage modifyvm "VM name" --nic1 hostonly. More on this can be found at: https://www.virtualbox.org/manual/ch06.html. I'd need more information on the setup to be able to help you.
Aliminator
CC BY-SA 4.0
2019-11-30T02:44:11.873Z
When adding `[ "modifyvm", "{{.Name}}", "--nic1", "hostonly"]` I am prompted with the following exception: `VBoxManage: error: Nonexistent host networking interface, name '' (VERR_INTERNAL_ERROR)`.
When I manually configure the hostonly adapter over the UI I have added a new one and selected to automatically configure the DHCP server. I am sure this can be done over the command line as well.
Kyu96
CC BY-SA 4.0
2019-12-01T14:20:24.840Z
Do you know how I can add this over the CLI?
Kyu96
CC BY-SA 4.0
2019-12-02T15:05:17.053Z
Try it after doing "vboxmanage hostonlyif create". This creates the interface.
Aliminator
CC BY-SA 4.0
2019-12-03T21:34:24.873Z
That does not seem to work either. I'll get prompted the usage information for vboxmanage. 
Do you mind showing me the three lines that are required to add the hostonly and brdige adapter correctly?
Kyu96
CC BY-SA 4.0
2019-11-28T21:33:28.423Z
2019-11-28T21:33:28.423Z
Aliminator
<p>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. </p>

<p>So I tried adding a bridged adapter one during the build process:</p>

<pre><code>"vboxmanage": [[ "modifyvm", "{{.Name}}", "--nic2", "bridged", "--bridgeadapter2","enp0s31f6" ]]
</code></pre>

<p>However the machine is still not reachable. 
This is how it looks on the VM:</p>

<p><a href="https://i.sstatic.net/VcgYw.png" rel="noreferrer"><img src="https://i.sstatic.net/VcgYw.png" alt="enter image description here"></a></p>

<p>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</p>

<networking><packer><virtualbox>
Bridged network adapter for Packer + VirtualBox?
Kyu96
# Bridged network adapter for Packer + VirtualBox?

(Asked by: username_0 on 2019-11-23)

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:
"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

**Tags:** networking, packer, virtualbox


---

## 1 answers

### Answer by username_1 on 2019-11-28. Score: 4

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:
VBoxManage modifyvm "VM" --cableconnected1 on

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: 
VBoxManage modifyvm "VM" --nic1 nat
VBoxManage modifyvm "VM" --natpf1 "guestssh,tcp,,2222,,22"
VBoxManage modifyvm "VM" --cableconnected1 on

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.

> **Comments:**
> **username_0**: Yeah, that's the problem. Despite adding a bridged adapter it does not automatically get a ip assigned. I do have to add a hostonly-adapter over the UI that is configured so that the VM can get a proper IP. Is there a way to do this over the commandline too?  
> **username_1**: For creating a hostonly-adapter, you would do the following: VBoxManage modifyvm "VM name" --nic1 hostonly. More on this can be found at: https://www.virtualbox.org/manual/ch06.html. I'd need more information on the setup to be able to help you.  
> **username_0**: When adding `[ "modifyvm", "{{.Name}}", "--nic1", "hostonly"]` I am prompted with the following exception: `VBoxManage: error: Nonexistent host networking interface, name '' (VERR_INTERNAL_ERROR)`. When I manually configure the hostonly adapter over the UI I have added a new one and selected to automatically configure the DHCP server. I am sure this can be done over the command line as well.  
> **username_0**: Do you know how I can add this over the CLI?  
> **username_1**: Try it after doing "vboxmanage hostonlyif create". This creates the interface.  
> **username_0**: That does not seem to work either. I'll get prompted the usage information for vboxmanage.  Do you mind showing me the three lines that are required to add the hostonly and brdige adapter correctly?  

---

