如何通过ssh从Mac主机连接KVM guest虚拟机? [英] How to connect KVM guest vm from mac hosts by ssh?

查看:174
本文介绍了如何通过ssh从Mac主机连接KVM guest虚拟机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Macbook上使用KVM.所以我启动kvm的方法是:

I want to use KVM on Macbook. So what I did to start the kvm is:

qemu-system-x86_64 -m 2G ./bastion-rhel7.qcow2 -accel hvf

VM启动正常.但是我不能ssh root@10.0.2.15这是默认的vm网络接口.它仅包含默认的vm接口,如下所示:

The VM starts ok. But I can't ssh root@10.0.2.15 which is the default vm network interface. it only contains a default vm interface, looks like this:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic ens3
       valid_lft 86353sec preferred_lft 86353sec
    inet6 fec0::caa4:e2ac:1cf9:230e/64 scope site noprefixroute dynamic
       valid_lft 86354sec preferred_lft 14354sec
    inet6 fe80::393b:a23c:2981:6282/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

在阅读这之后文章,我知道如果我使用virtualbox可以解决此问题,则可以附加仅主机的网络.

After read this article, I know I can attach host-only network if I use virtualbox to fix this problem.

这让我知道,如果可以从qemu-system_x86_64命令行为KVM连接仅主机的网络,则可以将ssh绑定到我的kvm来宾.但是我不知道这对于kvm如何或是否可行.

It makes me that if I can attach host-only network for KVM from qemu-system_x86_64 commandline, then I can ssh to my kvm guest. But I don't know how or if this is feasible for kvm.

我感谢任何评论和解决方案,我要做的就是从Mac主机通过ssh连接来宾vm.

I appreciate any comments and solutions, all I want to do is to connect the guest vm via ssh from mac hosts.

(我的Macbook仅具有wifi连接,因此我认为桥接"模式对我来说不是一种选择.)

(My macbook only have wifi connection, so I think "bridge" mode is not an option to me.)

推荐答案

您正在使用的默认QEMU网络类型是用户模式",即用户模式".联网.来宾VM在此设置中看到的IP地址在VM外部是不可见的(有点像VM在NAT路由器后面).因此,尽管guest虚拟机可以向外连接,但除非在QEMU命令行上配置端口转发,否则您无法连接到guest虚拟机.(网络上的QEMU Wiki页面包括用于SSH的语法示例端口.)

The default QEMU networking type, which is what you're using, is "user-mode" networking. The IP address the guest VM sees in this setup is not visible outside the VM (it's a little bit like the VM being behind a NAT router). So while the guest can connect outwards, you cannot connect in to the guest unless you configure port forwarding on your QEMU command line. (The QEMU wiki page on networking includes an example of the syntax for this for an SSH port.)

如果您需要访客拥有世界其他地方(包括主机)可以公开看到的IP地址,则需要使用其他网络后端,例如"tap";但是,设置起来要复杂得多.

If you need the guest to have an IP address that is publicly visible to the rest of the world (including to the host machine) you need to use a different network backend, like "tap"; that's a lot more complicated to set up, though.

这篇关于如何通过ssh从Mac主机连接KVM guest虚拟机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆