As others have commented, IP packets with a TTL of 0 are discarded and the TTL is updated whenever the IP header is processed/rewritten, and usually decremented by 1. In practice, the TTL is decremented whenever a packet exits a router through a physical interface.
To answer your question more specifically, the TTL is decremented only when it egresses the router. In your case, for packets destined for the loopback interface or interface 0/2, the packet does not exit the router, the IP header is not updated, so TTL is not decremented and pings are returned.
Looking at a couple of examples using your topology:
Ping from host 192.168.1.50 to 1.1.1.1 or 192.168.2.1: The ping is
received by the router on interface 0/1, the TTL is 1 so the packet
is accepted, the ping is destined for a local interface so the IP
header is not updated and TTL is not decremented, the packet is
received by the IP interface (1.1.1.1 or 192.168.2.1). Ping
succeeds.
Ping from host 192.168.1.50 to 192.168.2.50 (a host on the LAN): The
ping is received by the router on interface 0/1, the TTL is 1 so the
packet is accepted, a routing decision is made and the packet will be
routed out of interface 0/2 to the destination (192.168.2.50), at
this stage the IP header is updated, the TTL is decremented and the
packet is discarded as the TTL is 0. Ping fails.
In summary, if you connect your PC to interface 0/1, yes, you should be able to ping interface 0/2 or the loopback interface. With the same setup, if you attempted to ping another host on 192.168.2.0/24 (not the router), the ping would fail.
I have set this up with Cisco 7200 routers to prove how this works in real life:
- PC1 is connected to router interface E1/1 with IP address 192.168.1.50/24
- PC2 is connected to router interface E1/2 with IP address 192.168.2.50/24
- Router has IP 192.168.1.1/24 on E1/1
- Router has IP 192.168.2.1/24 on E1/2
- Router has loopback address 1.1.1.1/32
First, a ping from PC1 (192.168.1.50) to router E1/2 (192.168.2.1) with TTL of 1 (PING SUCCEEDS):
Router debug output:
*Nov 3 20:55:33.447: IP: s=192.168.1.50 (Ethernet1/1), d=192.168.2.1, len 84, rcvd 0
*Nov 3 20:55:33.451: ICMP type=8, code=0
*Nov 3 20:55:33.451: ICMP: echo reply sent, src 192.168.2.1, dst 192.168.1.50, topology BASE, dscp 0 topoid 0
*Nov 3 20:55:33.451: FIBipv4-packet-proc: route packet from (local) src 192.168.2.1 dst 192.168.1.50
*Nov 3 20:55:33.451: FIBfwd-proc: packet routed by adj to Ethernet1/1 192.168.1.50
*Nov 3 20:55:33.451: FIBipv4-packet-proc: packet routing succeeded
*Nov 3 20:55:33.451: IP: s=192.168.2.1 (local), d=192.168.1.50 (Ethernet1/1), len 84, sending
*Nov 3 20:55:33.451: ICMP type=0, code=0
R2#
*Nov 3 20:55:33.451: IP: s=192.168.2.1 (local), d=192.168.1.50 (Ethernet1/1), len 84, sending full packet
*Nov 3 20:55:33.455: ICMP type=0, code=0
*Nov 3 20:55:33.455: IP: s=192.168.1.50 (Ethernet1/1), d=192.168.2.1, len 84, input feature
*Nov 3 20:55:33.455: ICMP type=8, code=0, packet consumed, MCI Check(88), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSE
- Router receives IP packet 192.168.1.50 -> 192.168.2.1
- Router does not route the packet this is a local interface, packet will not exit router
- Router creates an ICMP Echo Reply from 192.168.2.1 -> 192.168.1.50
- Router routes the reply and sends out of interface E1/1
Second, a ping from PC1 (192.168.1.50) to PC2 (192.168.2.50) with TTL of 1 (PING FAILS):
Router debug output:
*Nov 3 20:57:23.419: FIBipv4-packet-proc: route packet from Ethernet1/1 src 192.168.1.50 dst 192.168.2.50
*Nov 3 20:57:23.419: FIBfwd-proc: packet routed by adj to Ethernet1/2 192.168.2.50
*Nov 3 20:57:23.419: FIBipv4-packet-proc: packet routing succeeded
*Nov 3 20:57:23.419: ICMP: time exceeded (time to live) sent to 192.168.1.50 (dest was 192.168.2.50), topology BASE, dscp 0 topoid 0
*Nov 3 20:57:23.419: FIBipv4-packet-proc: route packet from (local) src 192.168.1.1 dst 192.168.1.50
*Nov 3 20:57:23.419: FIBfwd-proc: packet routed by adj to Ethernet1/1 192.168.1.50
*Nov 3 20:57:23.419: FIBipv4-packet-proc: packet routing succeeded
R2#
*Nov 3 20:57:23.419: IP: s=192.168.1.1 (local), d=192.168.1.50 (Ethernet1/1), len 56, sending
*Nov 3 20:57:23.419: ICMP type=11, code=0
*Nov 3 20:57:23.419: IP: s=192.168.1.1 (local), d=192.168.1.50 (Ethernet1/1), len 56, sending full packet
*Nov 3 20:57:23.419: ICMP type=11, code=0
*Nov 3 20:57:23.419: IP: s=192.168.1.50 (Ethernet1/1), d=192.168.2.50, len 84, input feature
*Nov 3 20:57:23.419: ICMP type=8, code=0, packet consumed, MCI Check(88), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSE
- Router routes the packet from E1/1 to E1/2
- TTL is decremented to 0, time exceeded, packed discarded
- Router sends ICMP TTL exceeded to packet source
- ICMP packet is routed out of E1/1 to PC1