Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2019-11-29T15:02:20.113Z
Answers: 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?
Answers: Kyu96
Answers: CC BY-SA 4.0
Answers: 2019-11-29T20:51:17.430Z
Answers: 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.
Answers: Aliminator
Answers: CC BY-SA 4.0
Answers: 2019-11-30T02:44:11.873Z
Answers: 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.
Answers: Kyu96
Answers: CC BY-SA 4.0
Answers: 2019-12-01T14:20:24.840Z
Answers: Do you know how I can add this over the CLI?
Answers: Kyu96
Answers: CC BY-SA 4.0
Answers: 2019-12-02T15:05:17.053Z
Answers: Try it after doing "vboxmanage hostonlyif create". This creates the interface.
Answers: Aliminator
Answers: CC BY-SA 4.0
Answers: 2019-12-03T21:34:24.873Z
Answers: 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?
Answers: Kyu96
Answers: CC BY-SA 4.0
Answers: 2019-11-28T21:33:28.423Z
Answers: 2019-11-28T21:33:28.423Z
Answers: Aliminator
Body: <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>
  
Tags: <networking><packer><virtualbox>
Title: Bridged network adapter for Packer + VirtualBox?
UserDisplayName: Kyu96
ThreadText: # 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:
  
  [![enter image description here](https://i.sstatic.net/VcgYw.png)](https://i.sstatic.net/VcgYw.png)
  
  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.
  
  [![enter image description here](https://i.sstatic.net/Lre4M.png)](https://i.sstatic.net/Lre4M.png)
  
  > **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?  
  
  ---
  
  