Getting IPv6 working in VirtualBox with SSH.
2/14/2025
I had a pretty aggravating experience trying to get IPv6 connections working in VirtualBox recently, which was preventing me from getting anything done with Composer. It turns out that if you use a bridged network adapter while using a Wifi card, IPv6 simply doesn’t work. I had been running VMs from my desktop until recently, so I didn’t notice until now.
It took me awhile to figure out how to do this and get SSH working. It’s actually not complicated, but I got a lot of incompatible sources telling me different things, and I had to do one thing that no sources told me to do, so I thought I’d write it here, mostly for future reference for myself, honestly.
As a quick sidenote, I am aware that QEMU is the recommended virtualization software these days, but I couldn’t get that to work at all.
So, the solution seems to be to set up a NAT Network.
From the VBoxManager (not the VM itself), go to File -> Preferences -> Network. Click the + icon on the right to create a new Nat network. Name the network whatever you like and enable all of the Network Options– Supports DHCP, Supports IPv6, and Advertise Default IPv6 Route.
We’ll come back to this page later. It’s a slightly convoluted process and there’s one thing we can’t do yet.
Next, create your VM if you haven’t already, then go to the VM’s settings. I don’t think it needs to be turned off to do this, but I could be wrong. Go to the Network panel and for “Attached to”, select “NAT Network”, then under “Name”, select the NAT Network that you just created.
Then expand the Advanced options and change “Promiscuous Mode” to “Allow All”.
Now boot the machine, log in, and get the ip address with “ip addr show” (assuming it’s a Linux machine). The address for my AlmaLinux machine was 10.0.2.15, so I assume it’ll be something similar on yours.
On the NAT network, the VM doesn’t have its own IP address on the local network like it would for the bridged adapters, so we have to set up port forwarding almost like it’s a router. Make note of that IP address.
I don’t think you’ll need to shut down the VM for this next part, but go back to that File -> Preferences -> Network in the VBoxManager (not the VM itself) and double-click the nat network, then click “Port Forwarding”.
There are two tabs– IPv6 and IPv6. We’re not doing anything with IPv6 right now because we’re dealing with the local network to set up both SSH and web viewing, so stay in the IPv4 tab.
Click the plus icon to the right and create the following rule:
Name: “SSH”
Protocol: “TCP”
Host IP: leave blank
Host Port: “2222”
Guest IP: The IP that you found inside the vm.
Guest Port: “22”
You should now be able to log in by SSH with ssh -p 2222 yourusername@localhost
.
Add another rule with these rules:
Name: “Web”
Protocol: “TCP”
Host IP: leave blank
Host Port: “8080”
Guest IP: The ip that you found inside the vm.
Guest Port: 80
Now if you have a web server set up like Apache, you should be able to view it by directing the browser to localhost:8080.