As far as I know, inside subnets, there is no such thing as routing.
How are IP-packets « routed » inside a subnet, and does this circumstance has an influence on how subnets are set up?
Thank you in advance,
Let’s agree on some terminology: forwarding means moving data from one interface to another.
If we use layer 3 information to decide which interface, we call it routing. If we use layer 2 information, we call it switching or bridging.
When a device is forwarding on the same subnet, we don’t need to route. The device uses layer 2 ( MAC address) to address the destination.
Subnets are usually associated with a multipoint link layer, such as Ethernet.
Routing table entries direct packets to an interface and optionally a next hop IP address. The routing table for a typical end device with a single ethernet interface might look something like.
Destination interface next hop
0.0.0.0/0 eth0 192.168.0.1
If the entry does not have a next hop address then the destination is used as the next hop.
In order to actually send the packet the next hop address must be translated into a link layer address. For IPv4 over Ethernet a protocol known as ARP is used to translate the next hop IP address to a MAC address. The host or router will look up the next hop IP address in the ARP table for the interface, if it finds a match the packet can be sent immediately, otherwise the packet will be held until an ARP table entry can be established through an ARP request and response.
If the host or router fails to establish an ARP table entry then it will drop the packet. On many platforms it will also generate a "no route to host" ICMP error.
Ethernet frames have source and destination MAC addresses.
Originally Ethernet used a shared medium, all hosts would receive all frames sent and it would be up to the network cards in the hosts to filter incoming packets based on the destination MAC address.
Nowadays most Ethernet networks use switches, these use the source MAC addresses to keep track of which MAC addresses are behind each port and use that information to limit where frames with known Unicast destinations are sent (some fancier switches also have features for controlling the delivery of some types of multicast traffic but multicast is out of the scope of this answer).
That depends on your definition of routing.
In my book, the decision to send locally or to a gateway is part of routing already - I define routing as deciding where to send a packet. So, any L3 node routes, it doesn't necessarily forward though.
Of course, deciding whether to send locally includes testing the destination address against your own subnet address (when your IP address masked with your subnet mask equals the destination address masked with your subnet mask, then the destination is on your local subnet).
Hosts communicate locally (addressing the destination directly on L2) when possible because it's more efficient than sending everything to a router, which would then forward the packet back to the destination on the same subnet.
This also depends on the definition of subnet.
Based on the question, I assume that subnet refers to a single layer 2 domain / LAN / network.
In this case packet is not routed based on IP addresses. Instead layer 2 determines how to deliver packets based on layer 2 addresses.
For example in Ethernet, switches forward packet based on its MAC address. This procedure is based on a combination of flooding and MAC learning. At a very shallow level: if a switch does not know where the station from destination address is, it floods the entire LAN with the packet. While forwarding frames, switches "learn" location of stations by recording input ports for source addresses. A more detailed overview can be found here.
To clarify the relationship with this answer to the answer of Zac67.
When a host needs to send IP packet, then this must involve IP processing on the host. In case of subnet, the host needs to determine that the destination is located in the same subnet (which it can do by comparing network part of the address) and then pass processing to layer 2. If the packet was to be forwarded, IP layer would have determined the next IP hop for the packet and then invoke layer 2 processing with the address of next hop instead of address of the destination. As pointed out in the answer, this IP processing can be viewed as routing.
Also, to clarify the comment below. Subnet is not layer segment, it is "what is configured for IP layer" as a single layer 2 segment.
In network layer, each interface is configured with IP address and network mask. This network mask specifies which IP addresses are in the same subnet. In this case, the IP layer assumes that all such addresses are in the same subnet, and are thus reachable through layer 2 of this interface. So, each subnet must correspond to a connected layer 2 segment. However, two different subnets, as configured at IP layer, can correspond to the same connected layer 2 segment. So, a connected layer 2 segment can span more than one subnet.