Skip to content
Pwnversity
FUND-ROUTINGbasic · 9 min · upd. 2026-11

How a Packet Travels: Gateway, ARP and Routes

Knowing how to address isn’t enough: you need to know what your machine does with a packet before letting it go. That decision explains why ARP spoofing puts you in the middle, why a reverse shell never comes back, and why, after compromising a machine, you suddenly “see” networks that didn’t exist before. It all comes down to two pieces: the routing table and ARP.

flowchart TB
    A["Packet to destination IP"] --> B{"Is it my own IP?"}
    B -->|"Yes"| L["Loopback: never leaves the machine"]
    B -->|"No"| C["Routing table: most specific route"]
    C --> D{"Does the route have a router (via)?"}
    D -->|"No: connected network"| E["ARP: destination's MAC?"]
    E --> F["Direct delivery to the destination"]
    D -->|"Yes"| G["ARP: that router's MAC?"]
    G --> H["Deliver to the router, which repeats the process"]

Two things to notice. First, the routing table is always consulted, even for your own network: your subnet is just a route without a router. That’s why a more specific route (for example, one pushed by a VPN) can win over your local network’s route. Second, when the route goes through a router, your machine never asks for the remote server’s MAC. It asks for the router’s. Each router repeats the same decision with its own table until the packet reaches the destination’s network.

The default gateway is a router with one leg on your network and another outside. Two conditions:

  • It must be on your own network. If you configure a gateway outside your subnet, your machine can’t find out its MAC and goes nowhere.
  • It’s the exit of the default route (default or 0.0.0.0/0): “anything I don’t know where to send, send it here”.

A machine can have several routes. For each packet the most specific one wins (the longest prefix, longest prefix match); the default route, with prefix /0, is only used if there’s nothing better.

Ventana de terminal
$ ip r
default via 192.168.1.1 dev eth0 proto dhcp metric 100
10.10.10.0/23 via 10.10.14.1 dev tun0
10.10.14.0/23 dev tun0 proto kernel scope link src 10.10.14.7
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.50 metric 100
Line How to read it
default via 192.168.1.1 dev eth0 Anything unknown goes out eth0 to the router 192.168.1.1.
10.10.10.0/23 via 10.10.14.1 dev tun0 Lab machines are reached through the VPN, via 10.10.14.1.
10.10.14.0/23 dev tun0 ... src 10.10.14.7 Directly connected network (no via): direct delivery. Your IP there is 10.10.14.7.
192.168.1.0/24 dev eth0 ... src 192.168.1.50 Your home network, also direct.

To find out which route a given destination will use, don’t do the maths: ask the system.

Ventana de terminal
$ ip route get 10.10.10.5
10.10.10.5 via 10.10.14.1 dev tun0 src 10.10.14.7
# → goes out through the VPN, and your source IP will be 10.10.14.7

ARP maps an IP on your network to its MAC. It works in two steps:

  1. Broadcast question: “who has 192.168.1.1? tell 192.168.1.50”. It reaches every machine on the network.
  2. Unicast reply: only the owner of that IP answers with its MAC.

The answer is stored in the ARP cache for a while, so it doesn’t ask for every packet.

Ventana de terminal
$ sudo tcpdump -i eth0 -nn arp
ARP, Request who-has 192.168.1.1 tell 192.168.1.50, length 28
ARP, Reply 192.168.1.1 is-at 52:54:00:12:35:02, length 28
$ ip neigh
192.168.1.1 dev eth0 lladdr 52:54:00:12:35:02 REACHABLE

Every IP packet carries a TTL (time to live) that each router decrements by 1. When it reaches 0, the router drops it and notifies the source with an ICMP time exceeded. traceroute exploits this: it sends packets with TTL 1, 2, 3… and each router that answers is a hop on the path. On Linux it uses UDP by default; Windows tracert uses ICMP.

Ventana de terminal
# Troubleshoot from the inside out: the first step that fails points to the cause
ip -br -4 a # no IP → interface down or no DHCP
ip r # no default line → no way out
ping -c 3 192.168.1.1 # can't reach the router → cable, wifi or wrong IP
ping -c 3 8.8.8.8 # can't reach the Internet → router or default route
ping -c 3 example.com # only fails by name → DNS problem
Ventana de terminal
# After compromising a host: what other networks can it reach?
ip -br -4 a # a second interface on 172.16.5.0/24...
ip r # ...and its route: a new network your Kali can't see
ip neigh # neighbours it has already talked to: targets
# On Kali, route that network through the pivoting tunnel
# (the interface is created by the tool, e.g. ligolo-ng)
sudo ip route add 172.16.5.0/24 dev ligolo
Concept What to remember
First Routing table, most specific route. Always.
Route without via Connected network: ARP for the destination’s MAC and direct delivery.
Route with via ARP for the router’s MAC, never the remote server’s.
Default gateway Must be on your own network. It’s the default route.
Several routes The longest prefix wins.
ip route get IP Which route, interface and source IP will be used.
ARP Broadcast question, unicast reply, cache. No authentication.
TTL Each router subtracts 1; at 0, ICMP time exceeded. That’s how traceroute works.
Troubleshooting IP → route → router → 8.8.8.8 → name.
  1. Your PC (192.168.1.50/24) pings 8.8.8.8. Whose MAC does it ask for via ARP?

    Answer

    The default gateway’s. 8.8.8.8 is outside its network, so the packet is handed to the router; the PC never needs 8.8.8.8’s MAC.

  2. You configure IP 192.168.1.50/24 and gateway 192.168.2.1. What happens?

    Answer

    The gateway isn’t on your network, so you can’t resolve its MAC via ARP and you can’t reach anything outside 192.168.1.0/24.

  3. You have a route default via 192.168.1.1 and another 10.10.0.0/16 via 192.168.1.254. Where does a packet to 10.10.3.4 go? And to 10.20.3.4?

    Answer

    10.10.3.4 matches 10.10.0.0/16, which is more specific than the default route: it goes via 192.168.1.254. 10.20.3.4 matches no specific route: it uses the default, 192.168.1.1.

  4. Pinging 8.8.8.8 works, but ping example.com fails. Where’s the problem?

    Answer

    In name resolution (DNS): connectivity and routing work. Check /etc/resolv.conf and the configured DNS server.

  5. Why is ARP spoofing possible?

    Answer

    Because ARP doesn’t authenticate replies: machines accept unsolicited replies and update their cache. An attacker can announce that the gateway’s IP maps to their MAC.

  6. You compromise a machine and ip a shows a second interface on 172.16.5.10/24. What does it mean for you?

    Answer

    The machine is connected to an internal network your Kali can’t reach. It’s a pivoting candidate: enumerate 172.16.5.0/24 from it, or set up a tunnel and a route to that network.