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.
Concepts
Section titled “Concepts”The decision before sending
Section titled “The decision before sending”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
Section titled “The default gateway”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 (
defaultor0.0.0.0/0): “anything I don’t know where to send, send it here”.
The routing table
Section titled “The routing table”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.
$ ip rdefault via 192.168.1.1 dev eth0 proto dhcp metric 10010.10.10.0/23 via 10.10.14.1 dev tun010.10.14.0/23 dev tun0 proto kernel scope link src 10.10.14.7192.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.
$ ip route get 10.10.10.510.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.7ARP: from IP to MAC
Section titled “ARP: from IP to MAC”ARP maps an IP on your network to its MAC. It works in two steps:
- Broadcast question: “who has 192.168.1.1? tell 192.168.1.50”. It reaches every machine on the network.
- 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.
$ sudo tcpdump -i eth0 -nn arpARP, Request who-has 192.168.1.1 tell 192.168.1.50, length 28ARP, Reply 192.168.1.1 is-at 52:54:00:12:35:02, length 28
$ ip neigh192.168.1.1 dev eth0 lladdr 52:54:00:12:35:02 REACHABLEtraceroute: seeing the hops
Section titled “traceroute: seeing the hops”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.
In practice
Section titled “In practice”# Troubleshoot from the inside out: the first step that fails points to the causeip -br -4 a # no IP → interface down or no DHCPip r # no default line → no way outping -c 3 192.168.1.1 # can't reach the router → cable, wifi or wrong IPping -c 3 8.8.8.8 # can't reach the Internet → router or default routeping -c 3 example.com # only fails by name → DNS problem# 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 seeip 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 ligoloNext offensive step
Section titled “Next offensive step”- Get in the middle on the local network: ARP spoofing and MITM.
- Reach internal networks through a compromised host: pivoting.
- Discover neighbours and services: network enumeration.
Cheat sheet
Section titled “Cheat sheet”| 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. |
Review questions
Section titled “Review questions”-
Your PC (
192.168.1.50/24) pings8.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.
-
You configure IP
192.168.1.50/24and gateway192.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.
-
You have a route
default via 192.168.1.1and another10.10.0.0/16 via 192.168.1.254. Where does a packet to10.10.3.4go? And to10.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.
-
Pinging 8.8.8.8 works, but
ping example.comfails. Where’s the problem?Answer
In name resolution (DNS): connectivity and routing work. Check
/etc/resolv.confand the configured DNS server. -
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.
-
You compromise a machine and
ip ashows a second interface on172.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.