我运行 Ubuntu Desktop 16.04 作为主机。我使用 Virtual Box 运行 Ubuntu Server。我使用带端口转发的 NAT 网络通过 SSH 连接到我的 Ubuntu Server 虚拟机。
通过这些设置,我可以在无需实际 Internet 连接的情况下使用 SSH,但在关闭调制解调器的情况下无法使用 SSH。
问题是我住的地方经常“停电”(基本上就是电力局切断电源)。所以当电源断电时,虽然我的笔记本电脑可以用电池供电,但我的调制解调器会关闭,这会断开 VirtualBox 和主机之间的连接。我使用 D-link 调制解调器。
以下是“ip addr show”的输出:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 34:e6:d7:80:7d:f2 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.3/24 brd 192.168.1.255 scope global dynamic enp7s0
valid_lft 85636sec preferred_lft 85636sec
inet6 fe80::a9a6:c6a7:8e7:86fd/64 scope link
valid_lft forever preferred_lft forever
3: wlp6s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether e4:f8:9c:1a:66:48 brd ff:ff:ff:ff:ff:ff
4: vboxnet0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff
我设置了仅主机网络,但仍然无法通过 SSH 连接到虚拟机。这是我收到的错误:
ssh: connect to host 192.168.56.10 port 22: No route to host
请参阅下面的图片以获得更好的理解:
这是来自 HOST MACHINE 的 pastebinit这里和这里:
Name: ubuntu-13.10-server-amd64
Groups: /
Guest OS: Ubuntu (64-bit)
UUID: eef457f6-5500-4fb5-beae-a2048003eb16
Config file: /home/hemanth/VirtualBox VMs/ubuntu-13.10-server-amd64/ubuntu-13.10-server-amd64.vbox
Snapshot folder: /home/hemanth/VirtualBox VMs/ubuntu-13.10-server-amd64/Snapshots
Log folder: /home/hemanth/VirtualBox VMs/ubuntu-13.10-server-amd64/Logs
Hardware UUID: eef457f6-5500-4fb5-beae-a2048003eb16
Memory size: 1024MB
Page Fusion: off
VRAM size: 16MB
CPU exec cap: 100%
HPET: off
Chipset: piix3
Firmware: BIOS
Number of CPUs: 1
PAE: off
Long Mode: on
Triple Fault Reset: off
APIC: on
X2APIC: on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode: message and menu
Boot Device (1): Floppy
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI: on
IOAPIC: on
BIOS APIC mode: APIC
Time offset: 0ms
RTC: UTC
Hardw. virt.ext: on
Nested Paging: on
Large Pages: off
VT-x VPID: on
VT-x unr. exec.: on
Paravirt. Provider: Default
Effective Paravirt. Provider: KVM
State: powered off (since 2017-01-20T13:01:04.880000000)
Monitor count: 1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address:
Teleporter Password:
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration:
Autostart Enabled: off
Autostart Delay: 0
Default Frontend:
Storage Controller Name (0): IDE
Storage Controller Type (0): PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0): 2
Storage Controller Port Count (0): 2
Storage Controller Bootable (0): on
Storage Controller Name (1): SATA
Storage Controller Type (1): IntelAhci
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1): 30
Storage Controller Port Count (1): 1
Storage Controller Bootable (1): on
IDE (1, 0): Empty
SATA (0, 0): /media/hemanth/1f8872a7-c976-429e-b9a4-5ff4611ce1b6/Virtual_harddisk/ubuntu-13.10-server-amd64.vdi (UUID: 78d9d5a9-8aa1-4fc0-b756-69f4f9b193ae)
NIC 1: MAC: 080027074B42, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 2: MAC: 08002796592D, Attachment: Host-only Interface 'vboxnet0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 3: disabled
NIC 4: disabled
NIC 5: disabled
NIC 6: disabled
NIC 7: disabled
NIC 8: disabled
Pointing Device: USB Tablet
Keyboard Device: PS/2 Keyboard
UART 1: disabled
UART 2: disabled
UART 3: disabled
UART 4: disabled
LPT 1: disabled
LPT 2: disabled
Audio: enabled (Driver: PulseAudio, Controller: AC97, Codec: AD1980)
Clipboard Mode: disabled
Drag and drop Mode: disabled
VRDE: disabled
USB: enabled
EHCI: disabled
XHCI: disabled
USB Device Filters:
<none>
Bandwidth groups: <none>
Shared folders: <none>
Video capturing: not active
Capture screens: 0
Capture file: /home/hemanth/VirtualBox VMs/ubuntu-13.10-server-amd64/ubuntu-13.10-server-amd64.webm
Capture dimensions: 1024x768
Capture rate: 512 kbps
Capture FPS: 25
Guest:
Configured memory balloon size: 0 MB
Name: ubuntu-16.04.1-server-amd64
Groups: /
Guest OS: Ubuntu (64-bit)
UUID: 985fda5c-3f3b-4046-a3e7-7b0f3636870e
Config file: /home/hemanth/VirtualBox VMs/ubuntu-16.04.1-server-amd64/ubuntu-16.04.1-server-amd64.vbox
Snapshot folder: /home/hemanth/VirtualBox VMs/ubuntu-16.04.1-server-amd64/Snapshots
Log folder: /home/hemanth/VirtualBox VMs/ubuntu-16.04.1-server-amd64/Logs
Hardware UUID: 985fda5c-3f3b-4046-a3e7-7b0f3636870e
Memory size: 1024MB
Page Fusion: off
VRAM size: 16MB
CPU exec cap: 100%
HPET: off
Chipset: piix3
Firmware: BIOS
Number of CPUs: 1
PAE: off
Long Mode: on
Triple Fault Reset: off
APIC: on
X2APIC: on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode: message and menu
Boot Device (1): Floppy
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI: on
IOAPIC: on
BIOS APIC mode: APIC
Time offset: 0ms
RTC: UTC
Hardw. virt.ext: on
Nested Paging: on
Large Pages: off
VT-x VPID: on
VT-x unr. exec.: on
Paravirt. Provider: Default
Effective Paravirt. Provider: KVM
State: running (since 2017-01-20T13:01:35.359000000)
Monitor count: 1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address:
Teleporter Password:
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration:
Autostart Enabled: off
Autostart Delay: 0
Default Frontend:
Storage Controller Name (0): IDE
Storage Controller Type (0): PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0): 2
Storage Controller Port Count (0): 2
Storage Controller Bootable (0): on
Storage Controller Name (1): SATA
Storage Controller Type (1): IntelAhci
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1): 30
Storage Controller Port Count (1): 1
Storage Controller Bootable (1): on
IDE (1, 0): Empty
SATA (0, 0): /media/hemanth/1f8872a7-c976-429e-b9a4-5ff4611ce1b6/Virtual_harddisk/ubuntu-16.04.1-server-amd64.vdi (UUID: 52e25a62-bef7-41df-a04b-06b90d2f36e5)
NIC 1: MAC: 0800276260D8, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 1 Rule(0): name = ssh, protocol = tcp, host ip = 192.168.1.3, host port = 2000, guest ip = 10.0.2.15, guest port = 22
NIC 2: MAC: 080027354E37, Attachment: Host-only Interface 'vboxnet0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 3: disabled
NIC 4: disabled
NIC 5: disabled
NIC 6: disabled
NIC 7: disabled
NIC 8: disabled
Pointing Device: USB Tablet
Keyboard Device: PS/2 Keyboard
UART 1: disabled
UART 2: disabled
UART 3: disabled
UART 4: disabled
LPT 1: disabled
LPT 2: disabled
Audio: enabled (Driver: PulseAudio, Controller: AC97, Codec: AD1980)
Clipboard Mode: disabled
Drag and drop Mode: disabled
Session name: GUI/Qt
VRDE: disabled
USB: enabled
EHCI: disabled
XHCI: disabled
USB Device Filters:
<none>
Bandwidth groups: <none>
Shared folders: <none>
Video capturing: not active
Capture screens: 0
Capture file: /home/hemanth/VirtualBox VMs/ubuntu-16.04.1-server-amd64/ubuntu-16.04.1-server-amd64.webm
Capture dimensions: 1024x768
Capture rate: 512 kbps
Capture FPS: 25
Guest:
Configured memory balloon size: 0 MB
IP4.ADDRESS[1]: 192.168.1.3/24
IP4.ADDRESS[1]: 192.168.56.1/24
IP4.ADDRESS[1]: 127.0.0.1/8
这是来自 GUEST MACHINE 的 pastebinit这里:
IP4.ADDRESS[1]: 10.0.2.15/24
IP4.ADDRESS[1]: 127.0.0.1/8