[4003] in linux-net channel archive
Re: Subnetting, Arghh
daemon@ATHENA.MIT.EDU (Scott Laird)
Sun Aug 11 16:59:49 1996
To: Henry W Miller <mill0440@gold.tc.umn.edu>
cc: Mogens Melander <mogens@frontier.dk>,
Linux Net <linux-net@vger.rutgers.edu>
In-reply-to: Your message of "Fri, 09 Aug 1996 07:11:50 CDT."
<Pine.SOL.3.91.960809065803.4548A-100000@gold.tc.umn.edu>
From: scott@laird.com (Scott Laird)
Date: Sat, 10 Aug 1996 11:32:25 -0700
In message <Pine.SOL.3.91.960809065803.4548A-100000@gold.tc.umn.edu>, Henry W M
iller writes:
>
>This depends on your setup. It looks like you want 5 subnets, in
>which case you would need a mask of 255.255.255.31, providing up to 30
>hosts on each network.
You have the wrong subnet mask. It should be 255.255.255.224. You
want to have all of the bits set from the top down, not from the
bottom up. With 255.255.255.31, the subnet mask (in binary) is
111...11100000111, which means that the low bits are part of the
network address, and some of the middle bits are the host address.
Technically, this will probably work, but it's a bad idea :-).
I'm having a tough time understanding what the original poster wanted,
but I've got a few suggestions. With a decent router (like Linux, in
this case), there isn't any real need to have all your subnets be the
same size. Look at it this way -- each host needs to know its own
subnet mask and the address of the local router/gateway. Other than
that, it depends on the router to forward packets. Therefore, the
router's the only machine that has to know how big *all* the subnets
are.
I'm having a tough time understanding exactly what the original poster
wants, so I'll throw together my own ugly ASCII diagram and show
something similar:
+-------------+
| Dedicated |
Internet --+ Router +---+
| | | +---------+
+-------------+ E| | WWW/FTP |
t+--+ Server |
h| | |
e| +---------+
r|
n| +----------+
e| | DNS/Mail |
t+--+ Server |
| | |
| +----------+
|
| +-----------+
| | Linux |
+--+ router |
| |
+-+-+-+-+-+-+
| | | | |
N N N N N
e e e e e
t t t t t
1 2 3 4 5
Let's say the the main Ethernet (let's call it net 0) needs room for
30 hosts, nets 1-4 need room for 14 hosts, and net 5 needs 30 hosts.
So, here are your netmasks:
Net 0 255.255.255.224
Net 1 255.255.255.240
Net 2 255.255.255.240
Net 3 255.255.255.240
Net 4 255.255.255.240
Net 5 255.255.255.224
Let's suppose that your class C network is 192.168.1.0, just so I have
some numbers to work with. Let's assign each network some network
addresses:
Net 0 192.168.1.0 (to .31)
Net 1 192.168.1.128 (to .143)
Net 2 192.168.1.144 (to .159)
Net 3 192.168.1.160 (to .175)
Net 4 192.168.1.176 (to .191)
Net 5 192.168.1.192 (to .223)
I put all of the machines that are routed from the Linux box higher up
in the address space to make the routing a bit easier. One thing to
watch -- each subnet has to be aligned correctly for whatever size
subnet mask it uses. That is, you can't have a 6-bit subnet (like net
5) start at an address that doesn't have the lowest 6 bits of its
address set to 0. We couldn't start net 5 at .208, for instance.
Now, let's suppose that the router at the top of the diagram is
192.168.1.1. Since the Linux box is connected to that network, it has
to have an address in that network. Let's give it .2.
Each of its other network interfaces need their own addresses. Let's
give them the lowest-possible addresses in each subnet.
Net 1 192.168.1.129
Net 2 192.168.1.145
Net 3 192.168.1.161
Net 4 192.168.1.177
Net 5 192.168.1.193
Remember, you can't a host address of all 0s or 1s, so .128 and .143
aren't usable on network 1, along with similar addresses on all the
other networks.
One the Linux box, the first thing you have to do is ifconfig all the
network interfaces. I'm going to use eth0 through eth5, but it'll
work the same for other types of networks.
/sbin/ifconfig eth0 192.168.1.2 netmask 255.255.255.224
/sbin/ifconfig eth1 192.168.1.129 netmask 255.255.255.240
/sbin/ifconfig eth2 192.168.1.145 netmask 255.255.255.240
/sbin/ifconfig eth3 192.168.1.161 netmask 255.255.255.240
/sbin/ifconfig eth4 192.168.1.177 netmask 255.255.255.240
/sbin/ifconfig eth5 192.168.1.193 netmask 255.255.255.224
Next, you need to tell the Linux box how to route all of these
networks.
/sbin/route add -net 192.168.1.0 netmask 255.255.255.224 eth0
/sbin/route add -net 192.168.1.128 netmask 255.255.255.240 eth1
/sbin/route add -net 192.168.1.144 netmask 255.255.255.240 eth2
/sbin/route add -net 192.168.1.160 netmask 255.255.255.240 eth3
/sbin/route add -net 192.168.1.176 netmask 255.255.255.240 eth4
/sbin/route add -net 192.168.1.192 netmask 255.255.255.224 eth5
Now configure all the hosts on networks 1-5. You'll have to assign
them IP addresses. Use the numbers from above for netmasks and
gateway addresses.
At this point, all the hosts on networks 1-5 should be able to talk to
each other and the Linux box.
Now you need to configure the main router to route traffic for
networks 1-5 through the Linux box. You could add a separate route
for each network, or just add a route for 192.168.1.128 (netmask
255.255.255.128) to the Linux box. This wastes a few addresses, but
it should work, and it keeps the routing table smaller.
You also need to configure the Linux box to use the main router as its
default route. Use
/sbin/route add default gw 192.168.1.1
At this point, everything should work. It's possible that I've
screwed up the options for /sbin/route or /sbin/ifconfig, although I
doubt it. I copied them more or less directly from my work system's
rc files, and it works fine.
One thing to watch: this assumes that nets 1-5 are local, and
connected via Ethernet (or TR, or arcnet), and not connected over SLIP
or PPP. If they are, then you need to do things a bit differently.
All the numbers still work, but you'll want to ifconfig the local
interface to use a different IP address (technically, 192.168.1.2 will
work, but it's not really the best way to do it) and then have the
system at the far use whichever address I specified above. For
example, if network 1 is connected via SLIP on sl0, then you'll want
to use something like this:
Configure the sl0 to use 192.168.1.2
Configure the remote machine to use 192.168.1.129
Add a route to the local machine to get to 192.168.1.129 over sl0:
/sbin/route add -host 192.168.1.129 sl0
Add a route to the remote network using 192.168.1.129:
/sbin/route add -net 192.168.1.128 netmask 255.255.255.240 gw 192.168.1.129
The remote router can just use 192.168.1.2 as its default route, and
everything should work.
Hope this helps,
Scott