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


$ 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.


For starters, localhost points at 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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.