A little while ago someone I know seemed a little bit confused as to how a traceroute interacts with a firewall, so I decided to properly look into and write this post.
Traceroute is the practice of sending particular packets across a network in order to discover all the different hops between the source computer and the destination. For example, here's a traceroute between starbeamrainbowlabs.com and bbc.co.uk:
traceroute to bbc.co.uk (126.96.36.199), 30 hops max, 60 byte packets 1 125.ip-37-187-66.eu (188.8.131.52) 0.100 ms 0.015 ms 0.011 ms 2 be10-147.rbx-g1-a9.fr.eu (184.108.40.206) 0.922 ms 0.912 ms 0.957 ms 3 be100-1187.ldn-1-a9.uk.eu (220.127.116.11) 7.536 ms 7.538 ms 7.535 ms 4 * * * 5 ae-1-3104.ear2.London2.Level3.net (18.104.22.168) 18.481 ms 18.676 ms 18.903 ms 6 unknown.Level3.net (22.214.171.124) 10.725 ms 10.434 ms 10.415 ms 7 * * * 8 ae0.er01.telhc.bbc.co.uk (126.96.36.199) 10.565 ms 10.666 ms 10.603 ms 9 188.8.131.52 (184.108.40.206) 12.123 ms 11.781 ms 11.529 ms 10 220.127.116.11 (18.104.22.168) 10.596 ms 10.587 ms 65.243 ms
As you can see, there are quite a number of hops between us and the BBC, not all of which responded to attempts to probe them. Before we can speculate as to why, it's important to understand how a traceroute is performed.
There are actually a number of different methods to perform a traceroute, but they all have a few things in common. The basic idea exploits something called time to live (TTL). This is a special value that all IP packets have (located 16 bytes into an ipv4 header, and 7 bytes into an ipv6 header for those who are curious) that determines the maximum number of hops that a packet is allowed to go through before it is dropped. Every hop along a packet's route decreases this value by 1. When it reaches 0, an ICMP TTL Exceeded message is returned to the source of the packet. This message can be used to discover the hops between a given source and destination.
With that out of the way, we can move on to the different methods of generating this response from every hop along a given route. Linux comes with a
traceroute utility built-in, and this is the tool that I'm going to be investigating. If you're on Windows, you can use
tracert, but it doesn't have as many options as the Linux version.
traceroute utility defaults to using UDP packets on an uncommon port. It defaults to this because it's the best method that unprivileged users can use if they have a kernel older than 3.0 (check your kernel version with
uname -r). It isn't ideal though, because many hosts don't expect incoming UDP packets and silently drop them.
-I flag causes
traceroute to use ICMP ping requests instead. Thankfully most hosts will respond to ICMP pings, making it a much better probing tool. Some networks, however, don't allow ping requests to pass through their gateways (usually large institutions and schools), rendering this method useless in certain situations.
To combat the above, a new method was developed that uses TCP SYN packets instead of UDP or ICMP ping. If you send a TCP SYN packet (manipulating the TTL as above), practically all hosts will return some kind of message. This is commonly referred to as the TCP half-open technique, and defaults to port 80 - this allows the traceroute to bypass nearly all firewalls. If you're behind a proxy though I suspect it'll snag on it - theoretically speaking using port 443 instead should rectify this problem in most cases (i.e.
traceroute -T -p 443 hostname.tld).
Traceroute has a bunch of other less reliable methods, which I'll explain quickly below.
tracerouteto use UDP on port 53. This method usually only elicits responses from DNS servers along the route.
tracerouteuse udplite in a similar fashion to UDP in the bullet point above. This is only available to administrators.
- DCCP can also be used with the
-D. It works similar to the TCP method described earlier.
- A raw IP packet can also be used, but I can't think of any reasons you'd use this.
That just about covers all the different traceroute methods. If you have any questions, please leave a comment below.