Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
i have a very silly question but it is irritating me.
i want to know tha
| | | |
------ _______Router_____ ------ Works Fine l/
/ \ / \
| | | |
------ ________HUB_______ ------ Does Not Work X
/ \ / \
I want to ask that if we have a HUB and we attach two computers and assign them different networks ip addresses then that does not work but if we use a router instead of a hub then that thing work. The thing which is irritating me is that what does a hub do, what we have learnt is that a hub simply forwards what it got on its port so when a packet comes from 192.168.0.1 with the destination address 192.168.1.1 the hub should simply forward this pack to all of its ports no matter from which network it comes from and to which network it has to go, so the computer with 192.168.1.1 ip address will also receive this pack and when this computer receives this packet then it should also reply to that pack but the computer with ip 192.168.0.1 does not receives a reply and on the other hand router also do the same thing in this scenario but in case of router the computer with ip 192.168.0.1 receives the reply. I want to know why this behaviour is ?
You are correct in how a hub and router work, the hub will forward all packets received to all ports. If you have a packet sniffer on the hub in your drawing below, you would see packets from both networks.
In your example using a router, your packet sniffer would see packets specific to the network it is connected to.
The router is only allowing network traffic originating from or destined to the specific network.
The end result is that while using a router, bandwidth on the local network is not eaten up by traffic from and to other networks.
Now let's expand this idea just a bit. Imagine the Internet as a whole being connected with hubs instead of routers. The local network would see *every* network packet from *all* connected computers -- on a global scale!
The routers on the Internet keep network traffic that is not relevant to your network away from your network.
I like the ISO/OSI model, even for TCP/IP (even though everything doesn't always fall into one specific networking layer), it simplifies the many different functions happening in a network.
For example, a hub operates at the Data Link layer, only dependent upon the physical wire or medium by which it is connected.
A router operates at the Network & Transport layers, dependent upon the lower layers.
Ping operates at the highest layer, the Application layer, and thus is dependent upon all the lower layers. (And thus it requires the router functionality to be able to communicate between different networks.)
You need a little understanding of how TCP/IP works.
Lets call the 192.168.0.1 machine A and the 192.168.1.1 machine B.
Here's what happens when you have the router between the 2 machines. Besides the IP address, you also have a netmask and a default gateway configured on each machine. On A, the default gateway is an address on the 192.168.0.0 network that is assigned to a port on the router. On B, the default gateway is an address on the 192.168.1.0 network that is assigned to a port on the router.
When you ping B from A, the first thing that A does is use the netmask(in your case probably 255.255.255.0) to determine if B is on the same network as itself. In this case it discovers that B is not on the same network so it looks through it's route table to find a route to the 192.168.1.0 network. Since it can't find a direct route, it will use the default gateway. The ping packet is sent to 192.168.1.1 but it is sent via the router. When the router receives the packet, it sees that the destination IP address is not it's own, so it forwards the ping packet out the port it has on the 192.168.1.0 network and machine B receives it.
Machine B receives the ping packet and replys. It goes through the same procedure to send the ping reply to machine A.
Now lets see what happens if you remove the router and connect the 2 computers together with a hub.
When you ping B from A, once again it determines that B is on a different network than itself. This time, it can't communicate with it's default gateway so the ping packet will never actually be sent out. B will never receive a ping packet.
Even if you removed the default gateway configruation from both machines, it still wouldn't work. If you ping machine B from A, A will determine once again that B is on a different network. It will search it's route table for a route to the 192.168.1.0 network. It won't find a direct route and without a default gateway defined, it can never send the ping packet.
Basically, in TCP/IP, if the packet is not destined for the same network the machine is on, it has to have a route to the other network, even if that route is just to use the default gateway. If it can't find a route, it will not transmit the packet.
The entire process of transmitting a TCP/IP packet is much more involved than what I have described here. I've tried to keep it as simple as possible. I hope this helps you understand why you can't use a hub or switch to connect 2 computers together that are on different IP networks.
The IP address has 2 parts : the left part is the network address, the right part is the computer address on *that* network. Hmm, but how do we know where left stops, and where right start ? Well that information is given by the subnet mask : if you translate this one into binary you find one's on the left and zeroes on the right.
When a networked computer wants to send something to another, it must know the IP address of the destination. It compares it to its own, to see if it belongs to the same subnet, or not.
If it doesn't, it sends the data directly to a router that makes the junction with the other subnet (or with yet another network, hoping that one will know the way). How does our source know the address of the router ? Because it is given to it as the *default gateway*, in a config file or by the dhcp server which issued its IP address lease. Actually ther might be several routers, for different destinations, so the default gateway specification wouldn't be enough, but let's make things outrageously simple.
If it does, it must learn the MAC address of the destination : that's a too often forgotten thing that network adapters are not overly concerned with IP address, but instead wait for traffic pointing to their real, hard-coded in firmware, unique address. It does that with a special protocol called ARP, the process is called ARP discovery, and it works with a braodcast. In short, our source PC shouts for everyone on the network "Who has IP address such and such ?" The destination responds "I do, my MAC address is such and such". Then the source can put the data on the wire, only the destination will grab it.
So you see now that PC's connected through a hub will be able to communicate with TCP/IP if and only if they belong to the same subnet; if you put a router between them, this router does the bridging between the 2 networks (called segments, btw).
Now, if your PC's don't belong to the same segment, and are nonetheless connected through a hub, you can't communicate with TCP/IP *but* they are still on the same ethernet wire, which means that if you're a programmer you can force them to communicate from MAC address to MAC address...