Chapter 11. Setting container network modes
You can configure container network modes by using Podman to define how your workloads communicate with the host and external networks. Selecting the appropriate networking environment ensures optimal performance and security isolation tailored to your specific application requirements.
11.1. Running containers with a static IP Copy linkLink copied to clipboard!
Assign a specific IP address to a container by using the --ip option. This helps ensure consistent network addressing for services that require fixed IPs.
The podman run command with the --ip option sets the container network interface to a particular IP address, for example, 10.88.0.44. To verify that you set the IP address correctly, run the podman inspect command.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Set the container network interface to the IP address 10.88.0.44:
# podman run -d --name=myubi --ip=10.88.0.44 registry.access.redhat.com/ubi10/ubi efde5f0a8c723f70dd5cb5dc3d5039df3b962fae65575b08662e0d5b5f9fbe85
Verification
Check that the IP address is set properly:
# podman inspect --format='{{.NetworkSettings.IPAddress}}' myubi 10.88.0.44
11.2. Running the DHCP plugin for Netavark using systemd Copy linkLink copied to clipboard!
You can run the DHCP plugin for Netavark as a systemd service to enable dynamic IP addressing for your containers. By operating this plugin as a persistent service ensures that containerized workloads maintain consistent network connectivity automatically.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Enable the DHCP proxy by using the systemd socket:
systemctl enable --now netavark-dhcp-proxy.socket Created symlink /etc/systemd/system/sockets.target.wants/netavark-dhcp-proxy.socket/usr/lib/systemd/system/netavark-dhcp-proxy.socket. Optional: Display the socket unit file:
# cat /usr/lib/systemd/system/netavark-dhcp-proxy.socket [Unit] Description=Netavark DHCP proxy socket [Socket] ListenStream=%t/podman/nv-proxy.sock SocketMode=0660 [Install] WantedBy=sockets.targetCreate a macvlan network and specify your host interface with it. Typically, it is your external interface:
# podman network create -d macvlan --interface-name <LAN_INTERFACE> mv1 mv1Run the container by using newly created network:
# podman run --rm --network mv1 -d --name test alpine top 894ae3b6b1081aca2a5d90a9855568eaa533c08a174874be59569d4656f9bc45
Verification
Confirm the container has an IP on your local subnet:
# podman exec test ip addr 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: eth0@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000 link/ether 5a:30:72:bf:13:76 brd ff:ff:ff:ff:ff:ff inet 192.168.188.36/24 brd 192.168.188.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::5830:72ff:febf:1376/64 scope link valid_lft forever preferred_lft foreverInspect the container to verify it uses correct IP addresses:
# podman container inspect test --format {{.NetworkSettings.Networks.mv1.IPAddress}} 192.168.188.36
When attempting to connect to this IP address, ensure the connection is made from a different host. Connections from the same host are not supported when using macvlan networking.
11.3. The MacVLAN plugin Copy linkLink copied to clipboard!
You can connect containers directly to a physical network interface by using the macvlan plugin. This allows containers to appear as physical devices on the network.
Most of the container images do not have a DHCP client, the dhcp plugin acts as a proxy DHCP client for the containers to interact with a DHCP server.
The host system does not have network access to the container. To allow network connections from outside the host to the container, the container has to have an IP on the same network as the host. With the macvlan plugin, you can connect a container to the same network as the host. This only applies to rootfull containers. Rootless containers are not able to use the macvlan and dhcp plugins.
You can create a MacVLAN network by using the podman network create --driver=macvlan command.