brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: arping -D checks if an IP address is already taken

Linux
~/tips/tip-networking-arping-duplicate-ip

sudo arping -D -I eth0 -c 3 192.168.1.50

Checks whether another device on your LAN already answers to an IP address.

Before I give a server a static IP, I want to know nobody else is sitting on it. A ping isn’t proof, because plenty of devices ignore ping. ARP is different: anything on the same LAN that owns the address has to answer an ARP request. arping from iputils has a mode just for this.

sudo arping -D -I eth0 -c 3 192.168.1.50

-D is duplicate address detection. -I picks the network interface and -c 3 stops after three requests. According to the man page, arping returns 0 when DAD succeeded, which means no replies came back and the address is free. If something answers, you’ll see its MAC address in the output and the exit code is no longer 0.

That exit code makes it script friendly:

if sudo arping -D -q -I eth0 -c 2 192.168.1.50; then echo free; else echo taken; fi

I’d run it before adding a DHCP reservation or a static address on a NAS, a Pi or a VM, because two devices with the same IP give the weirdest half-working network you can get.

Caveats: arping needs the CAP_NET_RAW capability, which in practice means sudo. It only works on your own layer 2 network, so it can’t check an address behind a router. And there are two different programs called arping. These flags are for the iputils version that most Debian and Ubuntu systems ship; check arping -V if the options don’t match.

Further reading: arping(8) man page (iputils)

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link