You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VirtualBox下三台Ubuntu虚拟机SSH互连失败问题求助

Hey there, let's troubleshoot this SSH connectivity issue together. You've already knocked out the foundational steps (installing SSH, enabling the service, whitelisting it in UFW), so let's dive into the common roadblocks when static IPs are set but VM-to-VM SSH still fails.

1. Double-Check Your Static IP Setup

First, confirm each VM has a unique, valid static IP that's on the same subnet:

  • Run ip a on every VM and look for the IP under your primary network interface (usually enp0s3 for VirtualBox). Make sure no two VMs share the same IP, and all use the same subnet mask (e.g., 255.255.255.0) and gateway (typically 192.168.56.1 for VirtualBox's Host-Only adapter).
  • If you edited /etc/netplan/*.yaml or /etc/network/interfaces to set static IPs, double-check for typos (like missing colons in Netplan, or incorrect gateway addresses).
2. Validate VirtualBox Network Adapter Settings

VM-to-VM communication relies on the right network adapter type:

  • Ensure all three VMs are using a Host-Only Adapter (this is designed for VM-to-VM and VM-to-host communication without external network access). Go to each VM's settings > Network > Adapter 1:
    • Check "Enable Network Adapter".
    • Set "Attached to:" to "Host-Only Adapter".
    • Pick the correct host-only interface (usually vboxnet0).
  • Avoid using NAT for VM-to-VM connections—NAT isolates VMs from each other by default.
3. Test Basic Network Connectivity First

Before debugging SSH, confirm the VMs can see each other:

  • From one VM, run ping <VM2-IP> and ping <VM3-IP>. If ping fails, the problem is with network connectivity, not SSH itself.
    • If ping works but SSH doesn't, move to SSH-specific checks below.
    • If ping fails, revisit your static IP subnet and VirtualBox adapter settings.
4. Troubleshoot the SSH Service and Config

Let's make sure SSH is set up correctly on the target VM:

  • Verify the SSH service is running: sudo systemctl status ssh. You should see "active (running)" in the output. If it's stopped, start it with sudo systemctl start ssh and enable it on boot again with sudo systemctl enable ssh.
  • Check the SSH daemon config for restrictive rules: Open /etc/ssh/sshd_config with sudo nano /etc/ssh/sshd_config and confirm:
    • PasswordAuthentication yes (if you're using password login—skip this if you're using SSH keys).
    • PermitRootLogin yes only if you're trying to log in as root; otherwise, ensure your regular user has access.
    • AllowUsers doesn't list specific users unless your username is included (comment this line out if you're unsure).
  • After editing the config, restart SSH to apply changes: sudo systemctl restart ssh.
5. Confirm Firewall Rules Are Working

Even though you ran sudo ufw allow ssh, double-check:

  • Run sudo ufw status on the target VM. You should see a rule allowing 22/tcp from your network (or anywhere, for testing).
  • If you're using iptables directly, run sudo iptables -L to ensure there are no DROP/REJECT rules blocking port 22.
6. Verify Your SSH Command Details

Small mistakes here can cause failures:

  • Make sure you're using the correct username for the target VM (it's easy to mix up usernames across multiple VMs).
  • If you get a "Connection refused" error, check if SSH is listening on the right interface: Run sudo ss -tulpn | grep ssh on the target VM. You should see it listening on 0.0.0.0:22 (all interfaces) or your static IP.

Work through these steps in order—starting with the ping test will quickly rule out basic network issues. Let me know which step uncovers the problem!

内容的提问来源于stack exchange,提问作者Amr Eldeeb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 20:22:44