LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-23-2004, 12:37 AM   #1
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Rep: Reputation: 32
TCP/IP Behaviour


hi
i have a very silly question but it is irritating me.
i want to know tha


Code:

192.168.0.1                      192.168.1.1
    ------                        ------
    |      |                     |      |
    ------   _______Router_____   ------        Works Fine   l/
   /        \                   /        \
   ----------                  -----------




192.168.0.1                      192.168.1.1
    ------                        ------
    |      |                     |      |
    ------   ________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 ?
Please help

Last edited by ilnli; 12-23-2004 at 12:53 AM.
 
Old 12-23-2004, 01:02 AM   #2
n0sr
Member
 
Registered: Sep 2004
Location: 127.0.0.1
Distribution: Slackware 13; Ubuntu Raspberry Pi OS
Posts: 255

Rep: Reputation: 34
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.

Hope that helps!
 
Old 12-23-2004, 01:25 AM   #3
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
yes you are right n0xvb but the thing here is that if both the computers can see and receive packets in case of hub then why don't they ping each other?

Last edited by ilnli; 12-23-2004 at 01:26 AM.
 
Old 12-23-2004, 02:00 AM   #4
n0sr
Member
 
Registered: Sep 2004
Location: 127.0.0.1
Distribution: Slackware 13; Ubuntu Raspberry Pi OS
Posts: 255

Rep: Reputation: 34
Well that really is one of the core premises of networking.

You are actually trying to compare apples to oranges, because these functions are performed at different layers of the network model. (Check out http://www.uwsg.iu.edu/usail/network...rk_layers.html)

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.)
 
Old 12-23-2004, 09:17 AM   #5
cowanrl
Member
 
Registered: Dec 2004
Location: Western Pennsylvania, USA
Distribution: Red Hat
Posts: 150

Rep: Reputation: 15
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.
 
Old 12-23-2004, 09:21 AM   #6
cidrolin
Member
 
Registered: Jul 2004
Distribution: Fedora c2
Posts: 89

Rep: Reputation: 15
To put it otherwise...

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...

Hope this doesn't make things mor obscure
 
Old 12-24-2004, 12:27 AM   #7
ilnli
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Slackware 10.0, SUSE 9.1, RH 7, 7.3, 8, 9, FC2
Posts: 413

Original Poster
Rep: Reputation: 32
I am very much thankful to all of you for clearing up my concept.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vi Behaviour! dlublink SUSE / openSUSE 5 09-20-2006 09:14 AM
Is this behaviour normal? Manuel-H Linux - General 2 01-20-2005 09:20 AM
Woody 3.0 Open Ports 1470/tcp/uaiact 1518/tcp/vpvd What for?How can I remove them? alexxxis Debian 5 07-05-2004 05:18 PM
Clone Behaviour stomfi General 0 11-07-2002 08:19 PM
close port 6000/tcp 515/tcp SchwipSchwap Linux - Newbie 1 09-12-2002 08:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration