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: ip route get shows which route and source address the kernel would use

Linux
~/tips/tip-networking-ip-route-get

ip route get 1.1.1.1

Asks the kernel which gateway, interface and source address it would pick for a destination, without sending anything.

With several network interfaces, a VPN or Tailscale on the same machine, I do not trust my guess about where a packet goes. I ask the kernel.

ip route get 1.1.1.1
ip route get 192.168.1.50

The answer is one line with via (the next-hop gateway), dev (the outgoing interface) and src (the source address the kernel would use). It is a lookup in the routing table only, so no packet goes out.

That makes it a quick check for questions like “does this traffic go through the VPN interface or the normal one?”. Compare the dev value for a public address and for an address in your LAN.

The man page lists extra arguments to simulate other situations. from pretends a source address, iif pretends the packet arrives on an interface, and oif forces an output interface.

ip route get 8.8.8.8 from 10.0.0.5 iif eth1

The caveat is that this shows the routing decision, not whether the destination answers. A firewall rule, a missing return route or a dead server will not show up here. For the path hop by hop you need tracepath or mtr.

Further reading: ip-route(8) manual

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