VirtualBox 中 Ubuntu 的远程控制常用做法有三种:SSH 命令行、VNC 图形桌面、xrdp RDP 桌面。下面给出可直接照做的配置步骤与要点,覆盖 NAT 端口转发与桥接网络两种常见场景。
sudo apt update && sudo apt install -y openssh-serversudo systemctl start ssh && sudo systemctl enable sship addr(记下如 192.168.x.x 或 10.x.x.x)ssh 用户名@虚拟机IP -p 22ssh 用户名@主机IP -p 2222ssh。sudo apt update && sudo apt install -y tightvncservervncserver(会生成 :1 会话,端口通常为 5901)vncserver -geometry 1280x800 :1虚拟机IP:5901主机IP:5901sudo apt install -y xubuntu-desktop(轻量)或 sudo apt install -y ubuntu-desktopsudo apt install -y xrdpecho "xfce4-session" > ~/.xsession,然后重启服务:sudo systemctl restart xrdpmstsc 连接 虚拟机IP:3389主机IP:3389sudo ufw allow 22,5901,3389/tcp;云主机还需在安全组放行。VBoxManage modifyvm "Ubuntu 名称" --natpf1 "tcp,2222,22,,22"(主机端口 2222 → 虚拟机 22)。删除可用 --natpf1 delete "tcp,2222,22,,22"。ip addr 或 ifconfig,确保与访问端网络可达(桥接在同一网段,NAT 需端口转发)。