Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
podman-bridge-network

This will work if you have an existing bridge or if you don't: if the bridge referenced in this config doesn't exist, it will be created when you start a container attached to the network.

  1. Create the CNI network configuration in /etc/cni/net.d/99-example.conflist:
{
  "cniVersion": "0.4.0",
  "name": "example",
  "plugins": [
    {
      "type": "bridge",
      "bridge": "br-example",
      "isGateway": true,
      "ipMasq": true,
      "ipam": {
        "type": "host-local",
        "routes": [
          {
            "dst": "0.0.0.0/0"
          }
        ],
        "ranges": [
          [
            {
              "subnet": "10.9.8.0/24",
              "gateway": "10.9.8.1"
            }
          ]
        ]
      }
    },
    {
      "type": "portmap",
      "capabilities": {
        "portMappings": true
      }
    },
    {
      "type": "firewall"
    },
    {
      "type": "tuning"
    }
  ]
}
  1. Verify the network shows up:
# podman network ls
NAME      VERSION   PLUGINS
podman    0.4.0     bridge,portmap,firewall,tuning
example   0.4.0     bridge,portmap,firewall,tuning
  1. Spawn a container on that network:
  # podman run -it --rm --net=example alpine sh
  / # ip addr show
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
  		link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  		inet 127.0.0.1/8 scope host lo
  			 valid_lft forever preferred_lft forever
  		inet6 ::1/128 scope host
  			 valid_lft forever preferred_lft forever
  2: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN qlen 1000
  		link/sit 0.0.0.0 brd 0.0.0.0
  4: eth0@if3: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
  		link/ether 4e:42:de:5a:78:df brd ff:ff:ff:ff:ff:ff
  		inet 10.9.8.2/24 brd 10.9.8.255 scope global eth0
  			 valid_lft forever preferred_lft forever
  		inet6 fe80::4c42:deff:fe5a:78df/64 scope link
  			 valid_lft forever preferred_lft forever
  / # ping -c1 8.8.8.8
  PING 8.8.8.8 (8.8.8.8): 56 data bytes
  64 bytes from 8.8.8.8: seq=0 ttl=55 time=8.921 ms

  --- 8.8.8.8 ping statistics ---
  1 packets transmitted, 1 packets received, 0% packet loss
  round-trip min/avg/max = 8.921/8.921/8.921 ms
  / #

@larsks

This comment has been minimized.

Copy link
Owner Author

@larsks larsks commented Apr 3, 2020

This assumes you want to use the address range 10.9.8.0/24 for your network. You are of course free to use other settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment