Skip to content

Networking Host vs Macvlan

github-actions[bot] edited this page Dec 5, 2026 · 1 revision

Networking: host vs macvlan

The relay has to do two things on your LAN: answer multicast DNS (UDP 5353) so iPhones and Macs discover it, and accept IPP (TCP 631, or CUPS_PORT) so they can print. How the container is attached to the network decides whether both work.

Mode Discovery Status Use when
Host (network_mode: host, the default) Yes Tested Almost always
macvlan (own IP and MAC address) Yes Experimental The host can't share TCP 631 or UDP 5353, or you want a separate IP
ipvlan L2 (own IP, host's MAC) Yes Experimental Like macvlan, but extra MAC addresses aren't allowed (Wi-Fi, some hypervisors)
Bridge (Docker default, ports:) No Not supported Never for AirPrint: multicast doesn't cross Docker's NAT
flowchart TB
    subgraph host["Host networking"]
        H1["NAS / server<br/>192.0.2.20"] --- C1["relay shares the host's IP<br/>631/tcp + 5353/udp on 192.0.2.20"]
    end
    subgraph mv["macvlan / ipvlan"]
        H2["NAS / server<br/>192.0.2.20"]
        C2["relay with its own IP<br/>192.0.2.30"]
    end
    LAN(("LAN<br/>iPhone, iPad, Mac")) --- C1
    LAN --- H2
    LAN --- C2
Loading

Host networking (default)

compose.yaml uses network_mode: host. The container uses the host's network interfaces directly: Avahi in the container sends and receives mDNS on the LAN, and CUPS listens on the host's address.

What you need to know:

  • TCP 631 must be free on the host. Synology DSM, QNAP and desktop Linux may run their own CUPS there. Stop it, or set CUPS_PORT to another port. If 631 is taken, the relay stops at start with [lpar] ERROR: TCP port 631 is already in use on this host ….
  • The host may have its own mDNS responder (Synology Bonjour, TrueNAS, Raspberry Pi OS, Unraid, desktop Linux). Both share UDP 5353 and, with AVAHI_HOSTNAME left empty, the host name too: they announce the same name with the same address, which is not an mDNS conflict (Tested on Synology; Expected elsewhere). A line *** WARNING: Detected another IPv4 mDNS stack running on this host is expected and harmless, and so is a single Host name conflict, retrying with <name>-2 right after start. On Synology a custom AVAHI_HOSTNAME looped forever, so set one only as a last resort.
  • Some hosts don't let other programs use 5353 at all. TrueNAS's Avahi has been reported to block it (TrueNAS forum). Then use macvlan.
  • Interfaces. By default the relay announces only on the interface holding the default route (AVAHI_INTERFACES=auto), which avoids talking on Docker and VM bridges; announcing on all of them can make Avahi rename the host forever (<name>-3, -4, …). Likewise only the subnets of the announced interfaces may print (ALLOWED_INTERFACES=auto), so other containers on the host are refused. Set AVAHI_INTERFACES=eth0 (or ovs_eth0, ovs_bond0, bond0, wlan0 …) to choose, or all for every interface.
  • Linux only. On Docker Desktop for Mac and Windows, host networking runs inside a VM and doesn't reach the LAN (Docker docs). See macOS and Windows.

macvlan: the relay gets its own IP address

With a macvlan network the container appears on the LAN as a separate device with its own IP and MAC address. The host's CUPS and mDNS responder are no longer in the way, so you don't need CUPS_PORT. The container announces its own name (the Compose hostname:), so leave AVAHI_HOSTNAME empty here too.

Trade-offs (Docker macvlan docs):

  • Linux hosts only, and the parent interface should be wired. Most Wi-Fi drivers refuse extra MAC addresses.
  • Your network must accept several MAC addresses on one port ("promiscuous mode"). Home switches normally do; some hypervisors and cloud networks don't.
  • The host can't reach the container directly. iPhones and Macs can, but the Docker host itself can't open the relay's IP unless you add a macvlan shim interface on the host.
  • Docker assigns the IP, not your router. Choose an address outside the DHCP pool, or reserve it.
  • On Synology, the parent interface is eth0, bond0 or ovs_eth0 (with Open vSwitch); the network is created with Portainer (Networks › Add network, driver macvlan) or over SSH.

A complete example with the .env settings, the shim commands and an ipvlan variant: examples/macvlan. In short:

services:
  airprint-relay:
    # image, environment and volumes exactly as in compose.yaml, minus network_mode: host
    hostname: airprint-relay           # announced as airprint-relay.local
    networks:
      lan:
        ipv4_address: 192.0.2.30       # free address outside the DHCP pool

networks:
  lan:
    driver: macvlan
    driver_opts:
      parent: eth0                     # the host's wired LAN interface
    ipam:
      config:
        - subnet: 192.0.2.0/24
          gateway: 192.0.2.1

Because the container's own subnet is the LAN, clients on it are allowed to print without ALLOWED_NETWORKS.

ipvlan

ipvlan in L2 mode works like macvlan but reuses the host's MAC address, so it also works where extra MAC addresses are refused. Unraid recommends ipvlan for custom networks since 6.12, because macvlan on a bridge interface can cause kernel call traces (release notes). The host-access restriction is the same. Use driver: ipvlan with ipvlan_mode: l2 in driver_opts.

Bridge networking (why it doesn't work)

Docker's default bridge network puts the container behind NAT. Publishing 631:631 makes IPP reachable, but mDNS multicast from the LAN never reaches the container and its announcements never leave the host, so iPhones don't discover it. You could still add the printer manually by address on a Mac or a Windows PC, but AirPrint on iOS depends on discovery.

Other VLANs and subnets

mDNS is link-local: it doesn't cross routers, whichever mode you choose. If phones are on a different VLAN than the relay:

  • let an mDNS reflector/repeater on your router or firewall forward Bonjour between the VLANs, and
  • add the phones' subnet to ALLOWED_NETWORKS so CUPS accepts their jobs.

Unicast alternatives (an Apple configuration profile that points at the relay's address) are covered on Clients and are Experimental.

Clone this wiki locally