Lease dynamic IPs with Netavark

As Brent announced Netavark v1.6 with DHCP support is released, together with podman v4.5 you can now use DHCP with your macvlan networks in only a few simple steps. In order to use macvlan and DHCP you must run Podman as root.

First enable the dhcp proxy via systemd socket:

$ sudo 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.

Now just create a macvlan network and specify your host interface with it, this is typically your external interface.

$ sudo podman network create -d macvlan --interface-name enp9s0u2u1u2 mv1

Make sure you supply the correct interface name, you can also use a different network name if you like. 

Now just use this network to run any container you want:

$ sudo podman run --rm --network mv1 -d --name test alpine top

Confirm the container got a ip on your local subnet:

$ sudo 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 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 brd scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5830:72ff:febf:1376/64 scope link 
       valid_lft forever preferred_lft forever

Lastly, lets see if podman inspect shows us the correct ip address:

$ sudo podman container inspect test --format {{.NetworkSettings.Networks.mv1.IPAddress}}

Keep in mind that when you try to connect to this ip you must do that from another host. Connecting from the same host does not work with macvlan.

As you can see, using the new DHCP feature is very easy. If you used DHCP with CNI you can now migrate to netavark. If you face any issues you can reach out to us on Github or the Podman communication channels.

Leave a Reply

Your email address will not be published. Required fields are marked *


Sign up with your email address to receive updates by email from this website.