How do I access an Ubuntu VirtualBox guest at a static IP from an OS X host?

1

How does one configure an Ubuntu guest to use a static IP that's visible to an OS X host, and ensure that the static IP is independent of the host's network configuration? I previously used bridged networking for my guest, but I'm constantly moving my host between networks so the guest IP is always different.

First, I tried setting the guest network configuration to NAT and forwarding host port 1022 to guest port 22, so I could at least ssh to a fixed address (localhost:1022):

$ VBoxManage setextradata "Ubuntu Server" "VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/Protocol" "TCP"
$ VBoxManage setextradata "Ubuntu Server" "VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/GuestPort" 22
$ VBoxManage setextradata "Ubuntu Server" "VBoxInternal/Devices/e1000/0/LUN#0/Config/SSH/HostPort" 1022

Then,

$ ssh localhost -p 1022
ssh: connect to host localhost port 1022: Connection refused

But this didn't work (guest has no network access with NAT and OS X refused the connection, as you can see).

I'd love a general solution that would let me communicate with my guest at a fixed IP.

David Siegel

Posted 2010-12-19T22:34:16.137

Reputation: 111

Answers

0

For starters, localhost points at 127.0.0.1. That VM may be running on your machine, but it is addressed separately from it.

When you turn on a NAT bridge in VirtualBox, it creates a separate, virtual interface to act as the “router” for the NAT clients you put behind it. You can’t connect to localhost to get to the VM because localhost is your Mac, NOT the VM.

Set up the guest as NAT, then check the address of the VM from inside it. use that address (its most likely a private address, 192.168.something) and try to connect from your host.

peelman

Posted 2010-12-19T22:34:16.137

Reputation: 4 580

0

From VirtualBox Networking Manual. I use this for a Windows guest on NAT to remote desktop and works great but I havent tried from host itself.

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"

With the above example, all TCP traffic arriving on port 2222 on any host interface will be forwarded to port 22 in the guest. The protocol name tcp is a mandatory attribute defining which protocol should be used for forwarding (udp could also be used). The name guestssh is purely descriptive and will be auto-generated if omitted. The number after --natpf denotes the network card, like in other parts of VBoxManage.

Oh, I just realized how old the question was, oh well hopes it helps others.

Brandon

Posted 2010-12-19T22:34:16.137

Reputation: 551