sudo visudoIt will ask for your Mac password, then open the file in the Terminal editor.
Press the End key or use the arrow keys to scroll to the very last line.
Type it exactly as shown:
%admin ALL=(ALL) NOPASSWD: /sbin/route
This is the part that trips people up since it's not a normal text editor.
Press Ctrl + X → then press Y to confirm save → then press Enter to keep the filename.
visudo will validate the syntax before saving, so if you made a typo it will warn you rather than corrupting the file.
sudo route -n add 1.2.3.4 192.168.1.1If it runs without asking for a password, you're good. Clean it up after:
sudo route -n delete 1.2.3.4If you see ~ characters on empty lines, your Terminal opened visudo in vim. The commands are different:
| Action | Command |
|---|---|
| Go to end of file | Shift + G |
| Open a new line | o |
| Type the rule | (type normally) |
| Exit insert mode | Esc |
| Save and quit | :wq then Enter |
Vim has a "command mode" — press : first to enter it, then type the command.
| Command | Meaning | What it does |
|---|---|---|
:wq |
write + quit | Save and exit |
:q |
quit | Quit (only works if no unsaved changes) |
:q! |
quit force | Exit without saving, discards all changes |
:w |
write | Save only, stay in the editor |
The
!in vim generally means "force it / I'm sure" — use it when vim refuses to quit due to unsaved changes.