How to access Raspberry PI QEMU VM via network
Asked 7 years, 5 months ago
Active 2 years, 7 months ago
Viewed 17k times
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.
When I call ifconfig on my VM I get this.

讯享网
And here the content of my /etc/network/interfaces file

On my 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
media: autoselect (1000baseT <full-duplex,flow-control>)
status: active
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?
asked Apr 16 '14 at 9:56
How do you want to be able to access files and on which part (or all) of the filesystem? e.g. by using a web browser, or by FTP, or using scp, pr webdav, or (etc …) ? –
6EQUJ5
Apr 16 '14 at 12:00
SMB or FTP. I think the problem is the network configuration. I can’t reach (ping) the VM from my Mac Host. –
Andi
Apr 16 '14 at 17:22
related unix.stackexchange.com/questions//… –
Ciro Santilli
Aug 27 '16 at 9:48
Add a comment
Start a bounty
2 Answers
14
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.
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:
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 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.

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:
Note - network MAC addresses, network card models, etc. and other qemu options omitted for clarity.
The SAMBA method
Note: I have only tried this under Linux
You can enable a samba server inside qemu:
6EQUJ5
2,95611 gold badge1717 silver badges2727 bronze badges
Add a comment
1
If you are happy to use SFTP/SCP then IMO the easiest thing to do is to install openssh-server on your Pi guest:
sudo apt-get update && sudo apt-get install openssh-server
When you launch your Pi VM use the -redir switch when your launch your QEMU guest to redirect port 22 (SSH/SFTP/SCP) e.g.
qemu -redir tcp:2222::22
You can then connect to your VM SFTP/SCP (or SSH) via port 2222 on your host machine. So from your host you can use localhost; from other machines on your LAN you can use :2222
[update 2019] As noted by @ChristophBimminger in a comment, in newer versions of QEMU the -redir switch has been deprecated/removed. The way to achieve this same thing is now via the -net or -netdev switches. Please check the man page, e.g. Debian testing (I don’t currently have a QEMU running so can’t give a definitive example).
The -redir option of QEMU was a parameter in elder versions of QEMU. Current versions (e.g. QEMU 3.x) require to use -net or -netdev and do no longer support the -redir parameter. –
Christoph Bimminger
Feb 6 '19 at 18:33
Thanks @ChristophBimminger - I’ll edit my answer to include your note. FWIW this answer is nearly 5 years old (and IIRC I was using Debian stable at the time), so would have definitely been a much older version of QEMU. –
Jeremy Davis
Feb 6 '19 at 19:19
Add a comment
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/68496.html