route
Networking
Usage
route -n | route -n get defaultReads and edits the kernel routing table, but on Linux it has given way to `ip route`, and on BSD/macOS the grammar is different altogether, such as `route -n get default`, so examples do not carry across.
Common flags
| Flag | Meaning |
|---|---|
| -n | Numeric output, no reverse DNS (Linux). |
| -n get default | Show the default route on macOS/BSD, which has a different grammar. |
| add default gw <ip> | Add a default gateway (Linux); BSD writes add default <ip>. |
| del / delete | Remove a route. Linux says del, BSD says delete. |
Examples
route -nThe kernel routing table on Linux.
route -n get defaultWhich gateway macOS is using.
sudo route add default gw 192.168.1.1Set a gateway by hand, lost at reboot (Linux).
When a connection fails, these narrow down how far it got — name not resolving, no route, or a blocked port.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does route do?
Reads and edits the kernel routing table, but on Linux it has given way to `ip route`, and on BSD/macOS the grammar is different altogether, such as `route -n get default`, so examples do not carry across.
Q. How do I type it?
route -n | route -n get default — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
4 are listed here; the full set is in man route. This command sits under Networking.
Related commands
man page: man route