TCP/IP and NetMasks and Routing Tables

Posted on 2002-04-22
Medium Priority
Last Modified: 2010-03-18
Perhaps someone can help me to understand TCP/IP and subnet masks better.

I have two computers (connected to a cable modem and to each other via a hub, not a router) that have been dynamically assigned (via DHCP) their IP addresses. The addressess are as follows:

Computer A:  xxxx.yyyy.181.97, subnet mask

Computer B:  xxxx.yyyy.180.177, subnet mask

Now, doing a "bitwise and" between the two addressess and their respective masks, I derive the network to which I belong to be xxxx.yyyy.176.0.

I also note that for computer A the last byte is less than 128 and for computer B the last byte is greater than 128. I know that there can be some significance to this, but have not seen an explanation.

Now, if we limited the IP addresses on the subnet xxxx.yyyy.176.0 to be of the form xxxx.yyyy.176.(1-255) with a subnet mask of, then this subnet would only be able to accommodate 255 IP addresses. It looks like the combination of the 181 and the 248 on the subnet mask allows for more IP addresses to be assigned to that subnet? Is that the point?

Now let's say that I wanted to be able to network these two computers together at home. I would want an entry in my routing table for computer A that says that if I am trying to send a packet to computer B, I should send it from computer A. What should that look like and why?:

Destination: ??
Gateway: ??
Genmask: ??
Flags: ??
MSS: 0?
Window: 0?
irtt: 0?
IFace: eth0

Thanks for the help/tutorial.
Question by:amcandrew
  • 4
  • 2
  • 2

Accepted Solution

newmang earned 400 total points
ID: 6961985
I may be missing the point of your question but it appears to me that this is a simple subnetting exercise where they have allowed for 8190 subnets each having 2046 hosts.

The address bit layout is therefore

nnnnnnnn nnnnnnnnn nnnnnhhh hhhhhhhh
(where n = network address bit and h = host address bit)

The valid IP addresses on these subnets are x.x.176.1 to x.x.183.254. The subnet address itself is x.x.176.0 and the broadcast address is x.x.183.255, all other addresses are valid for use by hosts.

As far as I can see there would be no requirement to route packets between the two PCs as they are on the same network, routers only being required when traversing networks.

I can't see any significance for the low-order byte being greater than or less than 128, this byte in and of itself has no special meaning as it is only the last 8 bits of the 11 bit host address area.

Cheers - Gavin

Author Comment

ID: 6962630
Now I think I understand the subnet/host part. I did not realize that one could specify that only 5 of the eight bits in the 3rd byte would be used for the subnet, since almost all of the examples that I have seen have had subnet masks of the form

As to the last question, the two computers that I wish to network together are connected to each other via a hub and they are each connected to the Internet (and to subnet xxxx.yyyy.176.0 via a cable modem). If I want to send a packet from A to B, I see two physical possibilities. First, the packet could go from A out the cable modem to a computer on the subnet (xxx.yyy.176.1? it is the gateway for destination and then come back through the cable modem to computer B. Or, the packet could go directly from A to B, if A knows that it is directly connected to B via the hub.

I think that the second approach would be the best. Can I implement it directly by the following routing table entry on A?:

Destination: xxxx.yyyy.180.177  (i.e. B)
Gateway: xxxx.yyyy.181.97  (i.e. A)
Genmask: xxxx.yyyy.248.0
Flags: U
MSS: 0
Window: 0
irtt: 0
IFace: eth0

Thanks for your assistance thusfar; I will accept your next answer so that you'll get the points you deserve.



LVL 40

Expert Comment

ID: 6962856
You don't need any routing in this case. As newmang stated above, in this case both computers are in the same subnet (same network number and netmask). Therefore each can "see" the other.

In practice what is going to happen when one wants to communicate to the other is that the originating box will broadcast an arp request. All nodes that are on the same subnet will see the broadcast. The arp request is simply the originating box's request to find out what system on the local subnet has the IP it's trying to reach. Basically it's asking "who has, tell me". The other system will see the broadcast and respond with its MAC and off they go.

Give the points to newmang. He's answered your question.
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.


Author Comment

ID: 6962974
But, when I try to ping B (xxxx.yyyy.180.177) from A, I get a message that all packets are lost.

The routing table on A has the following entries (generated by DHCP)

Destination       Gateway           Genmask
XXX.YYY.176.0             xxx.yyy.176.1

Note that pinging works fine and I have internet access via my browser. I am a little suspicious of the destination and gateway addresses that are simply; maybe that is the way DHCP sets things up so that I do not have access to, cannot ping, any other machine on the cable company's network?
LVL 40

Expert Comment

ID: 6963076
Your routing table is correct for the local network and the default route. The first line says that XXX.YYY.176/ is a local network and that no gateway is needed. The last line has a destination of (anywhere) and a gateway point to your ISP's router and is the default route for non-local traffic.

If these two boxes are Linux machines you may have installed a default firewall on them. This would prevent pings or anything else from working between the two systems. If that's the case you'll need to modify the firewall rulesets or disable the firewall.

Author Comment

ID: 6963498
It was a firewall on B. Duh!  Thanks for the help.

Expert Comment

ID: 6964204

Glad to see it is all working and you understand the addressing.

Just to fill in the background to this.....

In the beginning when the addressing structure was defined no-one had any idea of the "internet". All IP networks were essentially private networks.

There were 3 classes of addressing defined with the difference being the division of the 32 bit address into network and host component parts. These were as follows:

Class A :
8 bits of network address, 24 bits of host address.
1st bit of the address is ALWAYS 0
Addresses range from to
Allows for a small number of networks each with huge numbers of hosts.

Class B :
16 bits of network address, 16 bits of host address
1st 2 bits of address ALWAYS 10
Addresses range from to
Allows for a medium number of networks each with a medium number of hosts

Class C :
24 bits of network address, 8 bits of host address.
1st 3 bits of address ALWAYS 110
Addresses range from to
Allows for large number of networks each with a small number of hosts.

Class D : is reserved for multicasts, starts with 1110 and ranges from to

Note that 127.x.x.x addresses are reserved for internal loopback addresses, this explains why you could ping - it never went outside the box.

With the emergence of the internet this addressing structure became very wasteful as many addresses in each network were wasted. What then emerged was the ability to sub-net the address whereby a class B address such as you are using can be subdivided by allowing some of the host part of the address to be used as network address bits.

One entity would be allocated a Class B address (, they would then subdivide this address into a number of sub-nets by subnetting (in your case and then allocate those networks out to other entities.

This is a very simplified explanation of what's going on here - there is much much more such as super-netting, classless inter-domain routing (CIDR) etc but it should give you a start. There are many books available on the subject if you really want to get down and dirty with this - I've been doing this for 30 years now and I still find out new stuff every day.

Cheers - Gavin

Author Comment

ID: 6970813
Thanks for the additional background. I think I'll look for a book ("TCP/IP for Dummies"?).



Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question