Skip to content
Open
2 changes: 2 additions & 0 deletions .web-docs/components/builder/iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,8 @@ 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_address` (string) - The address where the SSH port forwarding will be set to listen on. This value defaults 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
2 changes: 2 additions & 0 deletions .web-docs/components/builder/ovf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ 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_address` (string) - The address where the SSH port forwarding will be set to listen on. This value defaults 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
2 changes: 2 additions & 0 deletions .web-docs/components/builder/vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ 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_address` (string) - The address where the SSH port forwarding will be set to listen on. This value defaults 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
6 changes: 6 additions & 0 deletions builder/virtualbox/common/comm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ 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"`
// The address where the SSH port forwarding will be set to listen on. This value defaults to `127.0.0.1`.
SSHListenAddress string `mapstructure:"ssh_listen_address" required:"false"`

// These are deprecated, but we keep them around for backwards compatibility
// TODO: remove later
Expand Down Expand Up @@ -72,5 +74,9 @@ func (c *CommConfig) Prepare(ctx *interpolate.Context) []error {
errors.New("host_port_min must be less than host_port_max"))
}

if c.SSHListenAddress == "" {
c.SSHListenAddress = "127.0.0.1"
}

return errs
}
12 changes: 7 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
SSHListenAddress string

l *net.Listener
}
Expand Down Expand Up @@ -133,10 +134,11 @@ 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))

command = []string{
"modifyvm", vmName,
"--natpf1",
fmt.Sprintf("packercomm,tcp,127.0.0.1,%d,,%d", commHostPort, guestPort),
fmt.Sprintf("packercomm,tcp,%s,%d,,%d", s.SSHListenAddress, 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 @@ -431,10 +431,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,
SSHListenAddress: b.config.SSHListenAddress,
},
&vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage,
Expand Down
2 changes: 2 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,
SSHListenAddress: b.config.SSHListenAddress,
},
&vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage,
Expand Down
2 changes: 2 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,
SSHListenAddress: b.config.SSHListenAddress,
},
&vboxcommon.StepVBoxManage{
Commands: b.config.VBoxManage,
Expand Down
2 changes: 2 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,6 @@
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_address` (string) - The address where the SSH port forwarding will be set to listen on. This value defaults to `127.0.0.1`.

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