Nowadays, this is practically standard, as most computers have both a wired and wireless NIC. But rarely do you have both connected at the same time. Have you wondered what happens when you have 2 connected NICs to 2 separate or even the same network? Most haven’t. I had wondered at one point, but had no answer. And programming took most of my time, where the NIC was a afterthought of infrastructure I built my software on, that had to “just work”. I learned what happens after I took a systems admin and networking course at BCIT. But I realized today that a lot of my networking articles assumes you know. And if I didn’t know, as a programmer, why would it be common knowledge? So without more ado:
BTW: under NORMAL circumstances, most computers DO NOT resend packets it has received, that was not destined for itself. It assumes the packet was sent in error and it is thrown away. You usually need to turn on a feature, for your computer to forward a packet, that it received, that was not destined for itself. On Linux, this feature is call ip_forwarding. On windows, I think you have to have routing software installed. Typically, this is not important, except for making your computer a router.
1. Computer connected to same Wireless and Wired network at same time.
All computers have routing tables, not just routers. Computer routing tables are extremely short, using only having 1 entry per NIC, plus 1 default route. But these entries tell a computer, where IP addresses are located on which NIC. So if Wireless and Wired have 2 different IP addresses on single soho wireless router, 192.168.1.100(wired) and 192.168.1.102(wireless), which one does it use?
There is a metric value on each routing table. Theoretically, ON A DESKTOP COMPUTER, the bigger metric wins. And the bigger metric should belong to the wired network (bc it is faster). Therefore there should be a default route entry to the wired NIC, with bigger metric.
There might be a second default route (why is it default, right?) with smaller metric number. This means, if the bigger one becomes disconnected, the smaller one becomes the default route.
This default route, is where all your network packets get sent to. EXCEPT packets with destination of an address listed on the route table. So if there is a 192.168.1.0/24 in route table pointing to your wireless network only, then any packets sent to 192.168.1.*, get sent to the wireless NIC.
ON a linux machine a computer w single connected wireless NIC, and disconnected wired looks like
bob@mint20-500G:~$ ifconfig eth0: flags=4099mtu 1500 ether d8:bb:c1:25:ec:85 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 2496224 bytes 217320539 (217.3 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2496224 bytes 217320539 (217.3 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlan0: flags=4163 mtu 1500 inet 192.168.1.100 netmask 255.255.255.0 broadcast 10.0.0.255 ...IP6 stuff... ether aa:bb:cc:dd:ee:ff txqueuelen 1000 (Ethernet) RX packets 86736780 bytes 97699133754 (97.6 GB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 26557528 bytes 15881365629 (15.8 GB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 bob@mint20-500G:~$ ip route default via 192.168.1.1 dev wlan0 proto dhcp metric 600 192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.100 metric 600 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.52 linkdown
So all packets get sent to wlan0, except packets sent to 192.168.1.*, which get sent to either wlan0 or eth0, whichever is bigger. eth0 is down. So packets for 192.168.1.* gets sent to wlan0. The net effect of which, all packets in a single connected network, get sent to that network. In this case, wlan0.
2. Computer connected to different Wireless and Wired network at same time.
In this case, you might have home wired network, but next door neighbor has a wifi. You go there and connect to their wifi. You come back and you’re still on their wifi bc their antenna is strong. What happens when you connect your wired network to your computer? Does it disconnect from neighbor’s wifi?
bob@mint20-500G:~$ ip route default via 10.0.1.1 dev eth0 proto dhcp metric 100 default via 192.168.1.1 dev wlan proto dhcp metric 600 192.168.1.0/24 dev wlan proto kernel scope link src 10.0.0.51 metric 600 10.0.1.0/24 dev eth0 proto kernel scope link src 192.168.0.2 linkdown
No, but it might trick you that you are. Wired is faster, so it will prefer the wired connection. But you are still connected to the wireless, if you are in range. If you disconnect from wired, you will start using the wireless. But if you have computers on your wired network, you will no longer be able to communicate with them. Consequently, b/c you never disconnected from the wireless network, you still might be able to communicate with hosts on this wireless network (if the address ranges don’t conflict between your neighbor’s wireless and your wired network).
3. Computer connected to 2 different Wired and Wired network at same time.
This was the purpose routing was invented. 2 different wired networks are supposed to be physical manifestations of a virtual addressing system. USUALLY, only 1 NIC (of the two or more) is connected to (the world, the internet, whatever you want to call it). The others are USUALLY connected to “stub network” or using a street analogy, a dead end or cul de sac. In this case, the default route points to the NIC connected to the world. The rest have “exceptions” entries in the routing table. So all network packets get sent to the world, EXCEPT the “sul de sac” networks which get sent from their particular NIC.
4. Computer connected to Wired network with 2 wired NICs to same wired network at same time.
There are a variety of weird things that might happen.
A. It might only prefer 1, bc it has a higher metric.
B. You may be able to configure a link aggregation protocol(LACP), if your switch supports it. Which means you double your bandwidth. BUT I think a lot of people don’t actually know the limits of this technology, if your switch and computer supports it. I think the algorithm used, uses a different port, if the destination and source IP are different. which means you don’t double the bandwidth, if you are communicating to the same IP address. It has to be on different IP address. I suspect it depends on how “smart” both ends of the link aggregation protocol support it. That is, if packet meant for the other NIC, gets processed correctly regardless of which NIC received it. And if the sender has a round robin queue set up, for either destination NIC.
C. If you “bridge” the 2 wired nics, this means whatever was received on one, gets sent out on the other. So then you created an infinite loop. Don’t do this. Commercial networking switches has safety interlock protocols, that can be turned on, to prevent infinite packet looping from happening, if someone accidentally created a loop. But not without some cost. The protocol is known as STP. This also means you never should connect 2 switches together using 2 wires, b/c it will create a loop, and NOT create a aggregate connection. Only commercial switches at this time support link aggregation.
So If I have articles about multiple NICs, WAN and LANs, VM and docker networking, these are all examples of multiple NICs (virtual or physical) on your computer. And above is how it decides to communicate with them.
VM
Everytime you create a VM that is connected to NAT, there is a virtual NIC created on your host computer, which all VM are connected to, which this host acts as a intermediary to the external network. All network connections from VM look like it is coming from the host IP.
Everytime you create a VM that is connected to Host only, there is virtual NIC created on your host computer, which all VM are connected to, which they are limited network connectibity to.
Everytime you create a VM that is connected to Internal only, there is NO virtual NIC created on your host computer, BUT all VM are limited limited network connectibity to each other.
Everytime you create a VM that is connected to NAT, there is a virtual NIC created on your host computer, which all VM are connected to, which serve as the bridge to your physical NICs, and they get their own IP address as if they were computers on the external network.
docker
bridged docker networks are not “bridged” as used by networking professionals. It means the docker container thinks it is on a host, connected to same network as docker0 virtual interface. And you have to instruct docker to forward packets to a docker container. It is closer to NAT, with ability to do port forwarding to a container.
Every docker container not bridged, typically is put into it’s own network. When a new docker network is created, a new docker virtual NIC is created. Which is how these containers think they are communicating with other containers in that network, which the host has a virtual NIC on.