Could someone please explain why a router can't have 2 interfaces on same subnet?
Do routers use network addresses to forward traffic?
Network Engineering Stack Exchange is a question and answer site for network engineers. It only takes a minute to sign up.
Sign up to join this communityCould someone please explain why a router can't have 2 interfaces on same subnet?
Do routers use network addresses to forward traffic?
why can't we have 2 interface on same subnet?
You can generally, some devices may have restrictions though. There are just very few situations where that makes sense.
A router forwards in between subnets, so multiple interfaces with the same subnet are rarely useful. (I'm referring to logical interfaces. Multiple physical interfaces commonly make sense when aggregating links, as @Peregrino69 has already pointed out, or for redundancy.)
Do router use network address to forward traffic?
Yes, routers forward by a packet's destination network address (usually IP nowadays).
a router can be physically connected to the same subnetwork with different interfaces.
routers, that implement dynamic routing protocols, may not work if a single router has two interfaces facing the same subent. This has something to do with how information is exchanged and how shortest paths are calculated. Thus a routing protocol may not support a situation where two interfaces are connected to the same subnet. I.e., this protocol will do something incorrectly if this happens. Examples:
OSPF RFC, Appendix F more or less says that you actually can. You have to specially configure the router, and from what i read, configuration error can cause incorrect behavior.
here is a link testing simple configuration with two interfaces having the same subnet with RIP, EIGRP, and OSPF. According to the link, both RIP and EIGRP work, however IOS version of OSPF fails to compute correct routes
this applies to bridges/switches too. STP in particular specifies how to handle situation where two interfaces are connected to the same LAN. In this case the bridge selects one based on this interface identifier.
there is nothing related to forwarding that prevents a router to have two interfaces on the same subnetwork. There is nothing special in a situation where a router has several interfaces that can route traffic to the same destination, and this case is a special case of such situation.
3.1. first, there is usually more than one physical network path between a given router and a given destination, and different paths go through different interfaces (or different routers which are connected through the same interface, this happens e.g., if routers are connected to the same subnet). The goal of a shortest path routing protocol is to select the best one (based on cost/metric). While doing so it also selects the interface that this path goes through.
3.2 it also can happen that there are several paths with the same cost. in this case there are two options: a) router selects one (it does not matter which one) , b) router distributes traffic between them all - this is known as Equal Cost Multi-Path (ECMP). AFAIK at least most intra-domain protocols do option b.
Here's a much simplified explanation. This applies only in a situation where a router has 2 locally connected interfaces in the same subnet without link aggregation or other bonding method.
There are 2 types of networks and interfaces: physical and logical. A physical interface is the port where you plug a cable in, a physical network is the arrangement of physical devices connected to the network; usually in the same physical location. A logical interface is the IP address used to make forwarding decisions, a logical network is the subnet identified by network address. Logical networks can extend to multiple physical locations.
Assume you have a network 192.168.1.0/24. To route traffic to that network your router must have an interface connected to that network, and the interface must have an IP address. Like this:
-------------------------
| ROUTER |
| 192.168.1.1 int1--------- 192.168.1.0/24 network
INTERNET-------int0 10.10.10.10 |
-------------------------
The devices in the network will have a routing table instructing them to route all traffic to all unknown networks to IP address 192.168.1.1 (Default Gateway). The router will have a routing table showing:
Route all traffic to network 192.168.1.0/24 through physical interface int1 (alternatively logical interface 192.168.1.1)
Route all traffic to all other networks through physical interface int0 (alternatively logical interface 10.10.10.10)
Having 2 logical interfaces pointing to the same logical network (192.168.1.0/24) confuses things. Let's assume this situation:
WEB1 2.2.2.2/24
|
|
|2.2.2.1/24
IROUTER
|1.1.1.1/24
|
| LAN 192.168.1.0/24
---|---------------- --------------
| R0 1.1.1.2/24 | | |
| | | |
| 192.168.1.1/24 R1------ SW1 ----PC1
| | | |
| GWROUTER | --------------
| | --------------
| | | |
| 192.168.1.2/24 R2------ SW2 ----PC2
| | | |
-------------------- --------------
PC1 wants to access a website provided by WEB1 on IP address 2.2.2.2. The server is not in subnet 192.168.1.0/24, so it will send the packet to GWROUTER 192.168.1.1. It doesn't know where the server is either, but it knows that traffic to all unknown destinations must go to IROUTER 1.1.1.1 so it forwards the packet there. IROUTER has direct connection to subnet 2.2.2.0/24, so it will follow instruction "Forward all traffic to 2.2.2.0/24 through locally connected interface", whereupon it will reach the WEB1 server.
WEB1 sends a response. IROUTER doesn't know where the eventual target is, but it knows the request came from GWROUTER so it will forward the response to 1.1.1.2. GWROUTER receives it, and since it's directly connected to 192.168.1.0/24 it will follow instruction "Forward all traffic to 192.168.1.0/24 through locally connected interface".
But there are 2 locally connected interfaces to 192.168.1.0/24. Which one should be used to forward the response?
For redundancy and efficiency purposes there are ways to combine multiple physical interfaces so that they are presented as a single logical interface; for example LACP. Similarly there are ways to combine multiple logical interfaces to use to a single physical interface; for example configuring sub-interfaces to forward traffic to multiple VLANs.
Also it should be noted that any individual manufacturer may well have a solution for connecting one subnet may be via 2 individual logical interfaces, without any kind of bonding or link aggregation. However these are proprietary solutions, not applicable in general level.
Could someone please explain why a router can't have 2 interfaces on same subnet?
As others pointed out, you can. My answer explains the typical terminology associated with this function.
Using the example of Cisco Systems products, this is normally called either an SVI or bridging (depending on the model of the device in question).
In order to have the same subnet on 2 interfaces I did use the Bridge.
By the way, Virtual machines often create a virtual bridge in host OS to connect physical network with virtual network.