How to access Raspberry PI QEMU VM via network - linux

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

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.

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 <other-qemu-switches-options-etc> -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).

Related

Can't ping linux image running on Qemu

I am very new to this
but i used build root to built kernel for arm-versatilepb then i am using qemu to run it
with the following command:
qemu-system-arm -M versatilepb -m 256 -kernel zImage -dtb versatile-pb.dtb -drive file=rootfs.ext2,if=scsi,format=raw -append "root=/dev/sda console=ttyAMA0,115200" -serial stdio -net nic,model=rtl8139 -net user
when i run the image from qemu and do the ifconfig :#ifconfig
eth0 Link encap:Ethernet HWaddr 52:54:00:12:34:56
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
so the problem is i can ping any site i try from my qemu machine
but when i try to ping the qemu machine(with ip :10.0.2.15) from my host machine it is not responding
thanks in advance
The answer to your question is the same as the answer to this one:
How to connect KVM guest vm from mac hosts by ssh?
You're using user-mode networking, which doesn't allow the outside world to connect in to the guest, except if you set up specific port forwarding on your QEMU command line.
The network configuration you are using (-net user) configures qemu to use a SLiRP network which does not support ICMP packets from the host machine into the qemu virtual NIC.
See https://wiki.qemu.org/Documentation/Networking#Network_backend_types, where it states that "in general, ICMP traffic does not work", and "the guest is not directly accessible from the host or the external network".

How do i staticly assign a ip in CentOS7

Trying to follow the guides online but i have no ifcfg-Eth0 or ensp3? or what ever all i have i ifcfg-lo and the contents look nothing like https://www.youtube.com/watch?v=5Hwv6OcfazI https://i.imgur.com/bxovaJ1.png also been trying to assign ip in Ubuntu 18.04 which doesn't use ect/network/interface no more it uses Netplan and even after i edit that and apply it i never have internet access. why on earth is linux so difficult to give addresses, i also tried the GUI way but i can never get online after. Is it something to do with Vmware?
You must add nic to your VM and centos must have driver for this nic. After that you can ask a question in "Unix & Linux Stack Exchange" (how to configure network connection in centos7) or try to configure it youself.
I recommend to do something like:
[root#centos7]# nmcli con show
NAME UUID TYPE DEVICE
enp0s3 d77bd8ad-ec13-4442-bb2b-ccee7a697552 ethernet enp0s3
[root#centos7minimal network-scripts]# nmcli con mod "enp0s3" ipv4.address "192.168.1.2/25, 192.168.1.3/32" ipv4.gateway "192.168.1.1" ipv4.dns "192.168.1.1, 8.8.8.8"
[root#centos7minimal network-scripts]# nmcli con up enp0s3
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)

How to access a raspberry pi localhost from a linux?

I set up a php file in my raspberry pi so that I can access some files on it from my local network.
Within raspbian, it works well in any browser using localhost/test. I tested it also in a Windows and a Mac computer in the same network, using my.local.ip.address/test in my browsers and it also worked fine.
Now here is the problem: in my linux computer, it does not work. It simply says that "the site cannot be reached". I already tried disabling the firewall (UFW) but it doesn't change anything.
I also tried several browsers in linux and the result is the same.
I think I am overseeing something obvious but I cannot see it.
Could someone give me a pointer on what might be wrong?
ifconfig -a output (Linux machine)
ifconfig -a output (Raspberry Pi machine)
It's possible that your Ubuntu machine is not in the same network. You can try theses steps to confirm :
Ping
Go on your ubuntu machine and type :
ping <rasp.pi.local.ip.address>
Go on your Raspberry Pi and type :
ping <ubuntu.local.ip.address>
If the ping request do not succeed your machines are probably in different networks. Your can use this command to watch the path used by packets between your ubuntu machine and your Raspberry Pi :
traceroute <rasp.pi.local.ip.address>
Change network card settings
Before this step, check if your are able to connect your machines togather (switch, router, vlan...).
ifconfig <interface> down
ifconfig <interface> <ip.network> netmask <netmask.network>
ifconfig <interface> up
After completing theses steps try to ping again and access to your website.

Debian guest on VirtualBox with bridged adapter has no internet access

I have setup a Debian guest and I am messing around with it to learn more about VirtualBox, Debian, and later after that is done I'll be messing around with a NodeJS server on it.
After a while I noticed I couldn't do some things with it when I had a Bridged adapter setup for the VM. NPM would not install packages because it timed out. I tried running "w3m google.com" and even looked up google.com's ip to check for a DNS issue.
No matter what, I cannot connect to any form of internet. But I can ping anything just fine. I can ping google, npmjs.org, etc.
Thanks for the assistance.
Update: I have been working on this more today, Newer router, asus, I read that people were having issues with belkin routers with bridged adapters so I switched, the asus is new anyways.
The host is connected via ethernet wire.
The VM shows up on the router just fine, And I connect to that device with the IP given by the router just fine. but I still cannot connect to google.com or anything.
This is too long to explain in a comment. Below is how the bridged adapter works.
Yet, if you can ping from the guest debian that means some form of DHCP happened and you must have and IP (which is a different IP from the host machine). I'd check router configuration to see if you're not allowing/disallowing specific MACs and/or IPs from the usage of TCP/UDP protocols (that is a measure some people use on their routers).
Bridged adapter
A bridged adapter on VirtualBox simulates as if there was a bridge (well it is easier to think of this as a hub) on the cable connection to your (host) actual machine. Even if the connection is over wireless the simulation is similar.
For (almost) all purposes the guest (debian) and the router the host machine is connected to are connected directly. Have separate MAC, separate IP, they even give separate ARP requests.
router <---> host machine running VirtualBox
^
|
+-----> guest machine running Debian
This is done by sending packets with a different hardware address (you can configure the hardware address in the adapter).
You need to configure the guest system (Debian) to connect to the network as if it was a separate machine. For example, if you use a WPA connection from the host machine you need to configure WPA (including the username and password) in the guest machine.
I am not an expert, but after some research I could solve a similar problem. I have a Mac hosting a Debian server. I used Bridged Adapter on interface en0 in my Mac.
1) My Mac is running on 192.168.10.101. I know that because I run the command:
ifconfig -a
and the interface en0 shows that IP
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 6c:40:08:98:72:4c
inet6 fe80::6e40:8ff:fe98:724c%en0 prefixlen 64 scopeid 0x4
inet 192.168.10.101 netmask 0xffffff00 broadcast 192.168.10.255
2) Running netstat command at my Mac:
netstat -nr
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.10.1 UGSc 296 142 en0
I see that the Mac Gateway is on 192.168.10.1
3) Mac and Debian must be in the same segment as the Gateway, I mean 192.168.10.xxx. So I decided that my Debian must run on the static IP 192.168.10.115.
I edited /etc/network/interfaces file at my Debian server to look this way:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.10.115
netmask 255.255.255.0
gateway 192.168.10.1
dns-nameservers 8.8.8.8 192.168.10.1
Then I did ping from my Mac and ping from my Debian and they answered Ok. I also have access to internet from Debian, because I have the same Default Gateway as my Mac.
root#debian64:/home/myuser# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default TEW-711BR 0.0.0.0 UG 0 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
I hope it helps and if anybody have better explanations I would like to learn.

multicast traffic fails with virtualbox host only network

I have an application where it sends some multicast request to the multicast group ,
If I test my Client and Server application on two separate PC which are in same subnet it works fine .
Since I can not run always on two PCs during testing of my application, I thought of using the virtualbox to run the another OS to run my server application .
My Host is ubuntu , I installed the vitrtualbox to run the another guest os linux , and since my traffic only has to be with in the HOST and Guest , I have selected a "host only network type" .
My guest OS get the IP address but when I run my server application, It fails to join to the multicast group says
"No Such Device" .
Can someone help me to set up a network between the Guest and HOST OS ..
My main goal is to send a multicast request and it should reach the guest OS.
In VM:
ls /sys/class/net - get net devices. (lo, eth0, eth1...). You should have one lo and two eth devices.
sudo nano /etc/network/interfaces. At eth0 there is a NAT connection. Lo is a localhost. We should set the Host-Only connection. Add the following:
# The host-only network interface
auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
(Address is taken from ipconfig/ifconfig output in host system. Instead eth1 you can have another connection name, taken from the step 4.b.i)
For checking the edited file, run:
sudo service network-manager restart
Check if you have all three connections running. Check Host-Only addresses.
ifconfig
Reboot
sudo reboot

Resources