QEMU how to ping host network?
QEMU supports ICMP on the SLIRP backend. It is necessary to allow so called ping socket (PF_INET, SOCK_DGRAM, PROT_ICMP) for users in kernel.
It is simple
sysctl -w net.ipv4.ping_group_range='0 2147483647'
See also http://lwn.net/Articles/422330/
From QEMU wiki, QEMU doesn't support ICMP on the SLIRP backend.
User Networking (SLIRP)
This is the default networking backend and generally is the easiest to use. It does not require root / Administrator privileges. It has the following limitations:
- there is a lot of overhead so the performance is poor
- ICMP traffic does not work (so you cannot use ping within a guest)
- the guest is not directly accessible from the host or the external network
For ICMP work you'll need use TAP, VDE or Socket.
More information: QEMU Wiki - Networking and alo the Wikibooks QEMU networking section
Recommended also: advanced guide for dealing with VLANs
The simplest and more effective way I found out for me was this.
In summary, on the host:
tunctl -u <username>
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/wlan0/proxy_arp
echo 1 > /proc/sys/net/ipv4/conf/tap0/proxy_arp
ip link set tap0 up
route add -host 192.168.0.20 dev tap0 <-- to be changed by you.
and for the guest, just run it with:
kvm -hda ~/fedora.qcow2 -net nic -net tap,ifname=tap0,script=no -usb
or
qemu -hda ~/fedora.qcow2 -net nic -net tap,ifname=tap0,script=no -usb
You just have to configure a tap
device, owned by your user, enable arp proxying
and configure a route
between your host and guest.
The author (and myself) used that to deal with the problem of bridging to a wlan0
device, which is not supported by the Linux kernel.
But it works as well with a wired connection. In the arp
configuration, just change wlan0
to eth0
.
The guest IP address must be set by you, as DHCP
doesn't work.
And you can already ping your host.