Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Raspberry PI QEMU VM via network

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. enter image description here

And here the content of my /etc/network/interfaces file enter image description here

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<PERFORMNUD>
    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?

like image 396
Andi Avatar asked Apr 16 '14 09:04

Andi


People also ask

How do I access my Raspberry Pi remotely from my router?

Connect Raspberry Pi Remotely Over Internet Just click the terminal icon next to your device. It will open up a new window for SSH access to your device. Provide your Raspberry Pi login credentials there to access your Pi shell. You'll be logged into your device and put in a shell prompt.

How do I connect to a Raspberry Pi network?

To set up a wired internet connection, simply connect your Raspberry Pi to the back of your network router with an ethernet or RJ45 cable. Once plugged in, you should observe the network LED blinking on your Raspberry Pi.


1 Answers

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)

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:

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

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)

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.

The more complicated method

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.

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

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 )

  • 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:

qemu -smb /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.

like image 150
6EQUJ5 Avatar answered Oct 11 '22 12:10

6EQUJ5