How to limit network ingress and egress on a running container

Thanx for all the help @tomp ! This is what I ultimately did to limit networking capacity on LXD containers, as a reference for others. (Here is a link to the references on available limits for networking)

  1. First, I investigate the individual container. Note the “-e” which is needed to see any settings derived from the profiles as they are not shown otherwise:
lxc config show -e mycontainer
  1. If you need to modify the individual container, this is done in two steps. In the example below, we limit the container to 1Mbit both upload & download:
lxc config device override mycontainer eth0 limits.ingress=1Mbit
lxc config device set mycontainer eth0 limits.egress=1Mbit

No container restart needed. This comes into effect immediately. You can test this with the tool speedtest-cli

If you like to set this for all containers in the default profile, then:

Edit the profile:
lxc config profile edit default

Add limits.egress & limits.ingress to the device as below.

Note that the changes will take effect immediately for all containers using the default container without container restart needed.

config: {}
description: Default LXD profile
devices:
  eth0:
    limits.egress: 1Mbit
    limits.ingress: 1Mbit
    name: eth0
    nictype: bridged
    parent: br0
    type: nic
1 Like