,

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
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
894ae3b6b1081aca2a5d90a9855568eaa533c08a174874be59569d4656f9bc45

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 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 forever

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

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

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

Subscribe

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


Categories


Search