So you went and installed mtr via the Brew package manager
, only to find it doesn’t really work? Bummer. Good thing there’s a fix.
$ mtr ma.ttias.be
host: ma.ttias.be
mtr: unable to get raw sockets.
But the sudo variant does work:
$ sudo mtr ma.ttias.be
1.|-- 10.200.200.200 0.0% 1 14.4 14.4 14.4 14.4 0.0
2.|-- 10.0.1.1 0.0% 1 17.7 17.7 17.7 17.7 0.0
3.|-- ge-0-0-24-605.rtr1.ant1.n 0.0% 1 14.7 14.7 14.7 14.7 0.0
4.|-- ge-0-0-20-2.csw01.ocs.ant 0.0% 1 15.5 15.5 15.5 15.5 0.0
5.|-- ma.ttias.be 0.0% 1 15.5 15.5 15.5 15.5 0.0
Having to sudo every time is a bit of a pain, so we can use the magic setuid bit that allows us to execute mtr without additional hassle.
These days mtr does the raw-socket work in a separate mtr-packet helper, so that’s the binary that needs the setuid bit (not mtr itself). Find it first, then chown it to root and flip the setuid bit:
$ which mtr-packet
/usr/local/sbin/mtr-packet
$ sudo chown root /usr/local/sbin/mtr-packet
$ sudo chmod 4755 /usr/local/sbin/mtr-packet
On an Apple Silicon Mac, Homebrew lives under /opt/homebrew instead, so the path is /opt/homebrew/sbin/mtr-packet (run which mtr-packet to be sure).
Now, next time you execute mtr, it’ll just work. It’s like magic.