Skip to content
Open
3 changes: 3 additions & 0 deletions .web-docs/components/builder/iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ used to do things such as set RAM, CPUs, etc.
does not setup forwarded port mapping for communicator (SSH or WinRM) requests and uses ssh_port or winrm_port
on the host to communicate to the virtual machine.

- `ssh_listen_on_all_interfaces` (bool) - Defaults to false. When enabled, the ssh port forwarding will be set to listen on 0.0.0.0
as opposed to 127.0.0.1

<!-- End of code generated from the comments of the CommConfig struct in builder/virtualbox/common/comm_config.go; -->


Expand Down
3 changes: 3 additions & 0 deletions .web-docs/components/builder/ovf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,9 @@ boot time.
does not setup forwarded port mapping for communicator (SSH or WinRM) requests and uses ssh_port or winrm_port
on the host to communicate to the virtual machine.

- `ssh_listen_on_all_interfaces` (bool) - Defaults to false. When enabled, the ssh port forwarding will be set to listen on 0.0.0.0
as opposed to 127.0.0.1

<!-- End of code generated from the comments of the CommConfig struct in builder/virtualbox/common/comm_config.go; -->


Expand Down
3 changes: 3 additions & 0 deletions .web-docs/components/builder/vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ boot time.
does not setup forwarded port mapping for communicator (SSH or WinRM) requests and uses ssh_port or winrm_port
on the host to communicate to the virtual machine.

- `ssh_listen_on_all_interfaces` (bool) - Defaults to false. When enabled, the ssh port forwarding will be set to listen on 0.0.0.0
as opposed to 127.0.0.1

<!-- End of code generated from the comments of the CommConfig struct in builder/virtualbox/common/comm_config.go; -->


Expand Down
3 changes: 3 additions & 0 deletions builder/virtualbox/common/comm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type CommConfig struct {
// does not setup forwarded port mapping for communicator (SSH or WinRM) requests and uses ssh_port or winrm_port
// on the host to communicate to the virtual machine.
SkipNatMapping bool `mapstructure:"skip_nat_mapping" required:"false"`
// Defaults to false. When enabled, the ssh port forwarding will be set to listen on 0.0.0.0
// as opposed to 127.0.0.1
SSHListenOnAllInterfaces bool `mapstructure:"ssh_listen_on_all_interfaces" required:"false"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could specify the listening address to be whatever we choose here instead of this flag?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lbajolet-hashicorp,

Thanks again for the comments. I have pushed a new commit.


// These are deprecated, but we keep them around for backwards compatibility
// TODO: remove later
Expand Down
17 changes: 12 additions & 5 deletions builder/virtualbox/common/step_port_forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import (
//
// Produces:
type StepPortForwarding struct {
CommConfig *communicator.Config
HostPortMin int
HostPortMax int
SkipNatMapping bool
CommConfig *communicator.Config
HostPortMin int
HostPortMax int
SkipNatMapping bool
SSHListenOnAllInterfaces bool

l *net.Listener
}
Expand Down Expand Up @@ -133,10 +134,16 @@ func (s *StepPortForwarding) Run(ctx context.Context, state multistep.StateBag)

// Create a forwarded port mapping to the VM
ui.Say(fmt.Sprintf("Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port %d)", commHostPort))

bindingAddress := "127.0.0.1"
if s.SSHListenOnAllInterfaces {
bindingAddress = "0.0.0.0"
}

command = []string{
"modifyvm", vmName,
"--natpf1",
fmt.Sprintf("packercomm,tcp,127.0.0.1,%d,,%d", commHostPort, guestPort),
fmt.Sprintf("packercomm,tcp,%s,%d,,%d", bindingAddress, commHostPort, guestPort),
}
retried := false
retry:
Expand Down
9 changes: 5 additions & 4 deletions builder/virtualbox/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,11 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
},
new(vboxcommon.StepAttachFloppy),
&vboxcommon.StepPortForwarding{
CommConfig: &b.config.CommConfig.Comm,
HostPortMin: b.config.HostPortMin,
HostPortMax: b.config.HostPortMax,
SkipNatMapping: b.config.SkipNatMapping,
CommConfig: &b.config.CommConfig.Comm,
HostPortMin: b.config.HostPortMin,
HostPortMax: b.config.HostPortMax,
SkipNatMapping: b.config.SkipNatMapping,
SSHListenOnAllInterfaces: b.config.SSHListenOnAllInterfaces,
},
&vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage,
Expand Down
4 changes: 4 additions & 0 deletions builder/virtualbox/iso/builder.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions builder/virtualbox/ovf/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
},
new(vboxcommon.StepAttachFloppy),
&vboxcommon.StepPortForwarding{
CommConfig: &b.config.CommConfig.Comm,
HostPortMin: b.config.HostPortMin,
HostPortMax: b.config.HostPortMax,
SkipNatMapping: b.config.SkipNatMapping,
CommConfig: &b.config.CommConfig.Comm,
HostPortMin: b.config.HostPortMin,
HostPortMax: b.config.HostPortMax,
SkipNatMapping: b.config.SkipNatMapping,
SSHListenOnAllInterfaces: b.config.SSHListenOnAllInterfaces,
},
&vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage,
Expand Down
4 changes: 4 additions & 0 deletions builder/virtualbox/ovf/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions builder/virtualbox/vm/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
},
new(vboxcommon.StepAttachFloppy),
&vboxcommon.StepPortForwarding{
CommConfig: &b.config.CommConfig.Comm,
HostPortMin: b.config.HostPortMin,
HostPortMax: b.config.HostPortMax,
SkipNatMapping: b.config.SkipNatMapping,
CommConfig: &b.config.CommConfig.Comm,
HostPortMin: b.config.HostPortMin,
HostPortMax: b.config.HostPortMax,
SkipNatMapping: b.config.SkipNatMapping,
SSHListenOnAllInterfaces: b.config.SSHListenOnAllInterfaces,
},
&vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage,
Expand Down
4 changes: 4 additions & 0 deletions builder/virtualbox/vm/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
does not setup forwarded port mapping for communicator (SSH or WinRM) requests and uses ssh_port or winrm_port
on the host to communicate to the virtual machine.

- `ssh_listen_on_all_interfaces` (bool) - Defaults to false. When enabled, the ssh port forwarding will be set to listen on 0.0.0.0
as opposed to 127.0.0.1

<!-- End of code generated from the comments of the CommConfig struct in builder/virtualbox/common/comm_config.go; -->