Enable IP address forwarding for a container host

IP forwarding is disabled on some versions of Linux, which breaks IP forwarding to containers after the VM is suspended and then resumed.

Affected Linux distributions:

  • CentOS
  • Red Hat Enterprise Linux
  • Fedora
To enable IP forwarding for a container host VM
  1. In the VM, navigate to the directory /usr/lib/systemd/network/

    Create the directory if it does not exist.

  2. Type the following command to determine the name of the Docker interface:

     ifconfig
    

    Typically, the host name for the Docker interface on a machine where there is only one network interface card installed, is docker0.

  3. Create a new file named: 80-container-<interface_name>.network, where <interface_name> is the host name for the Docker interface that you determined in step 2.

  4. In the new file, add the following content:
     [Network]
     IPForward=kernel
    
  5. Restart the VM.
  6. Verify that containers are still accessible after the VM is suspended and then resumed, by typing the following command in a terminal:
     sysctl net.ipv4.conf.<interface_name>.ip_forward
    

    The terminal should display the status:

     net.ipv4.ip_forward = 1