Traceroute works by sending packets with incrementing time-to-live (TTL) values and monitoring the ICMP error responses. Routers along the path will generate ICMP Time Exceeded messages when the TTL expires, allowing traceroute to detect each hop. Eventually the TTL will be large enough for the packet to reach the destination host, which will respond with an ICMP port unreachable message since the destination port is unlikely to be in use.