As a new user of Home Assistant I set it up on Armbian under a python3 virtual environment. I had difficulties with the nmap device tracker, but none of the similar topics on here explained the issue that was affecting me so as it seemed it might affect others I thought I’d post my issue and solution here.
Issue: nmap on the command line e.g. “nmap -sn --host-timeout 10s 192.168.1.0/24” was detecting all hosts on the LAN, but device tracker was seeing only a small proportion of them
Problem: I was logged in as ‘root’ to test the nmap command. When root user, nmap with those options uses ICMP ‘ping’. The same command run under user ‘homeassistant’ who does not have root privileges does not use ICMP ping and therefore misses all hosts that do not respond to TCP SYN on port 80, which happened to be many devices. (Trying nmap with the ‘-privileges’ option as user homeassistant gave an error ‘dnet: failed to open device… QUITTING’.)
My solution (YMMV): is to set root-uid bit on /usr/bin/nmap (chomd u+s /usr/bin/nmap). When run under user ‘homeassistant’ nmap then gives a warning about a security flaw, but then proceeds to identify all hosts properly.
YMMV as there are certainly be other solutions to using nmap functionality without exposing the security flaw. The simplest might be to use ‘ping’ tracker instead of ‘nmap’, but as the IP address leases are not all reserved that isn’t a reliable option in my case. nmap options available to non-root users that get nearly all of the hosts to respond require probing on many ports per IP address and take several minutes to complete on my network (roughly 30-50 active hosts).