Configure NAT interface before forwarded port mapping

This commit is contained in:
Moss 2019-12-19 17:03:31 +01:00
parent 9eda2031d2
commit 9216f43463
1 changed files with 14 additions and 1 deletions

View File

@ -63,9 +63,22 @@ func (s *StepForwardSSH) Run(ctx context.Context, state multistep.StateBag) mult
s.l.Listener.Close() // free port, but don't unlock lock file
sshHostPort = s.l.Port
// Make sure to configure the network interface to NAT
command := []string{
"modifyvm", vmName,
"--nic1",
"nat",
}
if err := driver.VBoxManage(command...); err != nil {
err := fmt.Errorf("Failed to configure NAT interface: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
// Create a forwarded port mapping to the VM
ui.Say(fmt.Sprintf("Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port %d)", sshHostPort))
command := []string{
command = []string{
"modifyvm", vmName,
"--natpf1",
fmt.Sprintf("packercomm,tcp,127.0.0.1,%d,,%d", sshHostPort, guestPort),