# Run MTR on MacOS without sudo

Coming from Linux/Windows it rather feel bothersome to run `mtr` with `sudo` each time if you want to quickly diagnosis a hostname/IP address.

Since, `mtr` require access to raw packets. MacOS permissions doesn't allow it to access those raw packets without `sudo`, fortunately we can fix that by setting ownership of executables to **root** and **SUID** by following steps -

## Step 1: Find path of mtr executables

First we need to find the path of `mtr-packet` which is another program which handles the networking and does the actual tracing.

```zsh
command -v mtr-packet
/opt/homebrew/sbin/mtr-packet
```

Here we can see, it's residing at `/opt/homebrew/sbin` directory, but that's not the true location of it, let's figure out why!

```zsh
ls -lsh $(command -v mtr-packet)
0 lrwxr-xr-x 1 jugal admin 34 Aug 31 23:28 /opt/homebrew/sbin/mtr-packet -> ../Cellar/mtr/0.96/sbin/mtr-packet
```

Ah, we can see `/opt/homebrew/sbin/mtr-packet` is actually linked to `/opt/homebrew/Cellar/mtr/0.96/sbin/mtr-packet`, that's where we are going to apply the necessary permissions.

## Step 2: Change ownership of executables to root

Change ownership of `mtr-packet` to `root` user by issuing following command -

```zsh
sudo chown root /opt/homebrew/Cellar/mtr/0.96/sbin/mtr-packet
```

## Step 3: Set SUID bit

We also need to set SUID (Set User ID) to `4755` -

```zsh
sudo chmod 4755 /opt/homebrew/Cellar/mtr/0.96/sbin/mtr-packet
```

Run the `mtr` command again, and it should work without prompting you for `sudo` password.

**Note:** The paths given as example are taken from Homebrew on M4 cores, Mac Intel architecture's path may differ.

***Reference(s):***

* [Dave's Network Blog](https://blog.dave-bell.co.uk/2020/01/06/using-mtr-on-os-x-without-sudo/)
* [Dzubayyan's Articles](https://article.masdzub.com/how-to-use-mtr-without-sudo-macos.aspx/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.devjugal.com/macos/run-mtr-without-sudo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
