Skip to content

How to enable ICMP (e.g. ping) from QEMU NAT network

ForrestGu edited this page Mar 14, 2017 · 1 revision

Background

We enable NAT for virtual node. Corresponding configuration is compute:networks:-:network_mode, e.g.:

compute:
    networks:
        -
            network_mode: nat
            network_name: ens160
            device: e1000

With these options, you will see InfraSIM starts qemu with a netdev of user, e.g.:

 -netdev user,id=netdev0 
 -device e1000,netdev=netdev0,mac=52:54:BE:c8:d1:18 

Problem is, by default, you can't ping from this NIC, from inside virtual node, to external world.

Solution

A quick solution is to run below command in the environment host qemu:

 sudo sh -c "echo \"0 2147483647\" > /proc/sys/net/ipv4/ping_group_range"

See more detail from this ICMP sockets patch:

This patch adds IPPROTO_ICMP socket kind. It makes it possible to send ICMP_ECHO messages and receive corresponding ICMP_ECHOREPLY messages without any special privileges.  In other words, the patch makes it possible to implement setuid-less /bin/ping.

By the way, 2147483647 is INT32_MAX.