Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Apr 2003 12:47:05 -0500 (CDT)
From:      Eduardo Viruena Silva <mrspock@esfm.ipn.mx>
To:        Steve Warwick <ukla@attbi.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Netmasks: the truth is out there?
Message-ID:  <20030429121519.O1228@Gina.esfm.ipn.mx>
In-Reply-To: <BAD3FE56.49C3%ukla@attbi.com>
References:  <BAD3FE56.49C3%ukla@attbi.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 29 Apr 2003, Steve Warwick wrote:

> Hi All,
>
> I know someone out there knows the truth about netmasks. All the
> documentation I can find on the net talks about "masking off" part of the IP
> address and how you can tell network from subnet and host ids.
>
> However, I have knowledgeable friend who is telling me that the netmask is
> also dependant on how the hosting company has set up their routing tables
> and incorrect netmasking on my part can reduce or halt my connection.
>
> So the question is, who is right? Is it as simple as just masking off the
> first three octets or does the netmask interact with the router?
>
> Please point me to an authoritative source or if you have the time, a brief
> description of if or how the netmask has to match the router, as I am not
> sure what questions to ask my hosting company.
>

suppose computer A and B with:

	IPA: a1.a2.a3.a4	MaskA:  ma1.ma2.ma3.ma4

and
	IPB: b1.b2.b3.b4	MaskB: mb1.mb2.mb3.mb4

Of course, a1 ... a4 and b1...b4  are integer numbers  in [0..255],
that is, they are bytes.


-----example-------
ma1 ... ma4 are also bytes, but build with leading 1's till
certain bit.  If you have a mask of 24 bits you have:

		11111111.11111111.11111111.00000000

written in binary, equivalent to:

		255.255.255.0

in decimal.

if you have a mask of 26 bytes you have:

		11111111.11111111.11111111.11000000

written in binary, equivalent to:

		255.255.255.192

in decimal.
----------------------


Surely you know how to make a bitwise AND between IPA and MaskA,
I mean:

	IPA & MaskA = (a1 & ma1).(a2 & ma2).(a3 & ma3).(a4 & ma4)
	IPB & MaskB = (b1 & mb1).(b2 & mb2).(b3 & mb3).(a4 & mb4)

Now, IPA and IPB are in the same subnet if:

	IPA & MaskA == IPB & MaskB

if not, they need a router to communicate.

Let show an example:

Lets suppose you have:

	IPA=   192.168.123.244
	MaskA= 255.255.255.0

	IPB=   192.168.123.120
	MaskB= 255.255.255.0

Now, IPA & MaskA = 192.168.123.0
     IPB & MaskB = 192.168.123.0

They are in the same subnet, you do not require a router.

But....

	IPA=   192.168.123.218
	MaskA= 255.255.255.128

	IPB= 	192.168.123.66
	MaskB= 255.255.255.128

Makes:
	IPA & MaskA = 192.168.123.128
	IPB & MaskB = 192.168.123.0

They do require a router to connect.


>
> ---
>
> My current rc.conf entry looks like this (these ips are bogus) - no
> broadcast and FreeBSD seems happy with this.
>
> defaultrouter="123.456.789.1"
                      ^   ^  these are not valid IP numbers.


> ifconfig_rl0="inet 123.456.789.111 netmask 255.255.240.0"
                          ^   ^ neither are these.

> ifconfig_rl0_alias0="inet 123.456.789.112 netmask 255.255.255.0"
> <+7 other aliases>

remember:  IP must be built out of BYTES, numbers in [0..255]
but you cannot use 0 or 255 in the last byte, because they have special
meanings.


>
>
> Thoughts, suggestions, links ?
>
>
> TIA
>
>
> Steve
>
>
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030429121519.O1228>