Netlens needs three settings that most container tools do not set for you. They belong to the Netlens container (not to the host, not to Docker itself, not to Netlens’ own settings):
| Setting | What it does | In a compose file or stack | In a container form (Portainer, Synology wizard) |
|---|---|---|---|
| Host network | lets it see the devices on your LAN | network_mode: host |
Network = host |
NET_RAW |
raw packets: ARP, ping and nmap scans, listening for DHCP | cap_add: list |
Capabilities → NET_RAW on |
NET_ADMIN |
network configuration used by the scanner | cap_add: list |
Capabilities → NET_ADMIN on |
In a compose file cap_add: is a line of the netlens: service itself: the same indentation as image: and network_mode:, and its two entries are a list below it. This is the part that goes wrong most often, so here is the whole service with the right places marked:
services: # the top of the file
netlens: # the name of this container (2 spaces in)
image: ghcr.io/gatlarf/netlens:latest
container_name: netlens
restart: unless-stopped
network_mode: host # <- same level as "image:"
cap_drop: # <- same level as "image:"
- ALL
cap_add: # <- same level as "image:": NOT under "environment:", NOT under "volumes:"
- NET_RAW # 4 spaces for "cap_add", 6 spaces for each "- NAME"
- NET_ADMIN
read_only: true
tmpfs:
- /tmp
volumes:
- netlens-data:/data
environment:
- TZ=Europe/Brussels
volumes: # the top level again (no indentation)
netlens-data:
Common mistakes:
cap_add:at the top level (no indentation) or underenvironment:: the container starts, but without the capabilities. Compose may also refuse the file (“additional properties not allowed”).NET_RAWandNET_ADMINwritten in the environment (- NET_RAW=true): they are not variables.- Tabs instead of spaces: YAML only accepts spaces.
privileged: trueinstead: it also works for scanning, but gives the container the whole host. Use the two capabilities.security_opt: no-new-privileges:true: it stops the scanner from using the capabilities. Leave it out.
How do I know it worked? Press Scan in Netlens: it finds your devices. If it finds nothing, or Settings → Scan performance → Passive listening says “Not running” and mentions NET_RAW, the container is missing the host network or one of the two capabilities. To check from a terminal: docker inspect netlens --format '{{.HostConfig.NetworkMode}} {{.HostConfig.CapAdd}}' should print host [NET_RAW NET_ADMIN] (the order may differ).
Both are in the file, but scans still fail with dnet: Failed to open device ... (or nmap says “Couldn’t open a raw socket”)? Then the container has the capabilities, but nmap, which runs as a normal user, does not get them. Cause, reproduced on a virtual Synology DSM 7.2.2: on a Synology, Container Manager stores its containers with the btrfs driver when the volume is formatted as btrfs (the capability survives and the standard file works) and with the aufs driver when the volume is formatted as ext4, and aufs drops the file capability the image puts on nmap. Check which one you have: sudo docker info | grep 'Storage Driver'. First confirm it: sudo docker exec netlens getcap /usr/bin/nmap should print cap_net_admin,cap_net_raw=eip; empty output means it was lost (the Scans page also says so under What Netlens found inside the container). Only then use the workaround under Troubleshooting, and read what it costs: it is a weaker set-up than the default.