I’m using nmap as device tracker and my hass is running in a Docker container.
I find that the command does not return the MAC address of the devices on the network, hence they never get added to known_devices.yaml.
Adding them manually they show up in the font-end, but never change state (always away).
I have added setcap to my Docker instance:
apt-get install libcap2-bin
in order to run the commands:
Could the problem be that the nmap command is not run with ‘sudo’?
Since running nmap -oX - 192.168.1.0/24 -F --host-timeout 5s does not include MAC address in the output whereas running sudo nmap -oX - 192.168.1.0/24 -F --host-timeout 5s does.
Anyone trodden this path already and can shed some light ?
Can you please show your device_tracker configuration in the configuration.yaml?
I recently setup nmap device tracker myself. I don’t scan the entire subnet, because that is quite cpu intensive. I just scan the devices I want to track.
To do so I marked the mac addresses of the devices I want to track static in the DHCP pool of my router. This way those mac addresses always keep the same IP address.
My device_tracker: config contains only IP addresses of the devices I want to track:
It is not clear to me if by adding scan_options you are replacing the default scan_options or adding to them.
With Debug logging I get:
2018-12-11 18:29:20 INFO (SyncWorker_12) [homeassistant.components.device_tracker.nmap_tracker] Scanning...,
2018-12-11 18:29:20 INFO (SyncWorker_12) [homeassistant.components.device_tracker.nmap_tracker] nmap scan successful,
2018-12-11 18:29:20 DEBUG (SyncWorker_12) [homeassistant.components.device_tracker.nmap_tracker] Nmap last results []
Which looks like an empty array to me.
When I comment out the scan_options then I get the following in the log file, which I interpret as the command is not running under sudo:
2018-12-11 18:39:41 INFO (SyncWorker_11) [homeassistant.components.device_tracker.nmap_tracker] No MAC address found for 192.168.1.xxx,
2018-12-11 18:39:41 INFO (SyncWorker_11) [homeassistant.components.device_tracker.nmap_tracker] No MAC address found for 192.168.1.xxx,
2018-12-11 18:39:41 INFO (SyncWorker_11) [homeassistant.components.device_tracker.nmap_tracker] nmap scan successful,
2018-12-11 18:39:41 DEBUG (SyncWorker_11) [homeassistant.components.device_tracker.nmap_tracker] Nmap last results []
OK so the reason is that running hass in Docker will put it on the 172.17.0.X network, and nmap is unable to obtain the MAC address from devices on my 192.168.1.X network.
The fix is to use --network="host".
I’d read somewhere that this was not optimal for Docker, but in this case it’s the only option.
Hi @kev - are you still using this solution?
Where would I add the string you provided --network= "host" - in the configuration.yaml under the nmap tracker platform as a scan-option?
the “–net=host” command is entered into the docker run command. it’s not used in the HA configuration.
It basically sets up your docker container to be able to access every port on your host system just like any other machine on your network as opposed to just exposing one port from the host to the container with the “-p 8123:8123” option.
and you may have to remove the port settings. I know in the regular docker run you can’t have “–net” and “-p” at the same time since they are redundant.
you can still do that with net=host. you just need to point your browser to port 8124 instead of 8123. I use that exact thing for a second instance of HA running on the same machine at port 8124. just change the port in the config to 8124 instead of 8123.
I am running into the same issue in the latest core-2021.8.8, running Home Assistant OS 6.2 on an Odroid-N2+. I am sure that my firewall allows icmp packges across the VLANs as I can use nmap to scan the target host from another system on the same vlan as HA and I can ping from HA other hosts on the target vlan.
Nmap does not work across vlans, however. Any way to solve this? The official documentation still claims that nmap works across vlans & subnets…