12

I'm trying to ping from guest to my host network without success.

qemu-system-x86_64 -hda debian_squeeze_amd64_standard.qcow2 -netdev user,id=user.0 -device e1000,netdev=user.0

I try to ping a random machine:

$ ping 10.0.2.21
Destination Host Unreachable

In the guest I'm only able to ping the host 10.0.2.2 (DHCP server).

1
  • Attach it to a tap device and attach the tap device & your network device to the bridge Jun 10 '13 at 22:29
12

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/

8

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

2
4

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.

0

I have just achieved this by directly combining the following two answers of mine:

Combining those, I found the "host IP" with ip route and then did:

ping 10.0.2.2

and it worked.

Tested with this QEMU + Buildroot setup on an Ubuntu 19.04 host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.