如何通过网络访问Raspberry PI QEMU VM [英] How to access Raspberry PI QEMU VM via network

查看:83
本文介绍了如何通过网络访问Raspberry PI QEMU VM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过QEMU在Mac OS X上成功设置了Raspberry PI VM.现在,我想从Mac访问该VM的文件系统.

I have successfully setup a Raspberry PI VM on my Mac OS X via QEMU. Now I want to access the filesystem of this VM from my Mac.

当我在VM上调用ifconfig时,我得到了这个.

When I call ifconfig on my VM I get this.

这是我的/etc/network/interfaces文件的内容

And here the content of my /etc/network/interfaces file

在我的Mac上

en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
    ether 3c:07:54:65:da:50 
    inet6 fe80::3e07:54ff:fe65:da50%en0 prefixlen 64 scopeid 0x4 
    inet6 fdbf:a879:6730::3e07:54ff:fe65:da50 prefixlen 64 autoconf 
    inet6 fdbf:a879:6730::401e:56f5:f2f9:a236 prefixlen 64 autoconf temporary 
    inet 192.168.1.119 netmask 0xffffff00 broadcast 192.168.1.255
    nd6 options=1<PERFORMNUD>
    media: autoselect (1000baseT <full-duplex,flow-control>)
    status: active

我认为原因是VM使用某种共享网络. VM是否可以通过我的路由器获取IP地址?

I think the reason is, that the VM uses some kind of Shared Network. Is there a way that the VM get the IP address from my router?

推荐答案

更简单的方法-灵活性较差,但您不需要花很多钱

您配置qemu的方式似乎是默认的主机NAT网络(也称为qemu -net nic -net user配置)

The easier method - less flexible but you don't need to muck around so much

They way you have configured qemu appears to be the default host NAT network (aka. qemu -net nic -net user configuration)

默认情况下,从来宾访问主机时(在本例中为Mac)会在10.0.2.2上找到.从来宾内部,您可以在10.0.2.2上连接到主机上的服务(您的MAC).但这是使用NAT的,因此您无法轻松地以其他方式返回.

By default, your host (your Mac in this case) will be found on 10.0.2.2 when accessed from your guest. From inside your guest you can connect to services on your host (your MAC) at 10.0.2.2. But this is using NAT, so you can't go back the other way as easily.

例如,如果您决定要连接到SSH服务和来宾内部运行的Web服务器,则需要使用以下修改的选项启动qemu:

For example, if you decide to you want to connect to the SSH service and a web server running inside your guest, you will need to start qemu with modified options like the following:

qemu -net nic -net user,hostfwd=tcp::2222-:22,hostfwd=tcp::22280-:80

这将是从主机(您的MAC)上的端口22280到qemu来宾内部的端口80的路由连接(与来宾中的端口2222->端口22相同)

What this will do is route connections from port 22280 on your host (your MAC) to port 80 inside your qemu guest, (same for port 2222 --> port 22 in the guest)

这意味着您可以浏览到Mac上的http://localhost:22280,以访问虚拟Raspberry Pi中的Web服务器,等等.

Which means you can browse to http://localhost:22280 on your Mac, to get to the web server in your virtual Raspberry Pi, etc.

由于使用的端口不同以及使用它们的方式不同,因此以这种方式设置FTP和SMB将更加复杂.尽管如果将FTP设置为使用PASV模式也不会有太大问题.

FTP and SMB will be more complicated to setup this way because of the different ports used and they way they are used, etc. although if you setup FTP to use PASV mode it wont be too much of a problem.

这涉及到执行您建议的操作,配置虚拟机任务以能够从路由器获取IP地址.在这种情况下,您需要在虚拟机与主机网络之间架起一座桥梁.

This involves doing what you suggested, configuring the virtual machine quest to be able to get an IP address from your router. In this case, you need to make a bridge from your virtual machine onto your hosts network.

这需要比这里可以快速解释的更多的设置,但是从本质上讲,您需要将NIC分配给vlan并添加tap接口,例如:

This requires a lot more setup than can be quickly explained here, but essentially, you need to assign your NIC to a vlan and add a tap interface, for example:

qemu -net nic,vlan=0 -net tap,ifname=tap0

但是,这需要在主机上进行更多设置(起初,您可以根据自己的情况手动设置,但可以编写脚本)以创建桥接和分接界面-通常,除了简单运行. Googling带来了多种方法来执行此操作,因为根据您的设置,它的变化更大. (我在这里找到了一个示例安装脚本: https://gist.github.com/EmbeddedAndroid/6572715 )

This however requires more setup on the host (initially, manual, as you figure out your own situation, but then, scriptable) to create a bridge and tap interface - which usually requires root access beyond that needed to simply run qemu. A bit of Googling brings up a variety of methods to do this, because it varies more depending on your setup. (I found an example setup script here: https://gist.github.com/EmbeddedAndroid/6572715 )

  • 注意-为清楚起见,省略了网络MAC地址,网卡型号等和其他qemu选项.

注意:我只在Linux下尝试过

Note: I have only tried this under Linux

您可以在qemu中启用samba服务器:

You can enable a samba server inside qemu:

qemu -smb /path/to/files

这会创建一个SMB共享,​​该共享可从来宾内部的\ 10.0.2.4 \ qemu访问,该主机从主机上的/path/to/files映射.

This creates a SMB share accessible from inside the guest at \10.0.2.4\qemu mapped from /path/to/files on the host.

这篇关于如何通过网络访问Raspberry PI QEMU VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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