How to get gateway address when subnetting?
I have to subnet a network from a single class C IP address.
I have figured out the subnet mask and the broadcast address (I'm using subnet mask /28) but don't understand how to ge开发者_StackOverflow社区t the gateway address.
Can anyone help me?
If subnet mask is 255.255.255.248 then number of masked bit will be 5, hence number of subnets = 2. The power number of masked bits = 2 the power 5 = 32 subnets, and the number of hosts per subnets = 2. The power (unmasked bit or 32- total number of network bits) = 2 the power (32-29) = 8 host/subnet.
Hence:
1) IP's in subnet-1 will be from 192.168.1.0 to 192.168.1.7 where 192.168.1.0 will be subnet id and 192.168.1.7 will be broadcast id.
2) IP's in subnet-2 will be from 192.168.1.8 to 192.168.1.15
and so on............
- 32) IP's in subnet-32 will be from 192.168.1.248 to 192.168.1.255.....
The gateway is only one for a network i.e. the first IP address of that network.
This post is almost 8 years old, but in case someone wanders across this, I wanted to fix a few issues with the top voted comment. I would've commented directly, but I literally just started this account, so I don't have the authority to do that.
- A subnet mask of /28 would be 255.255.255.240, not 248, not 248.
- Having 32 subnets with 8 hosts per subnet is impossible with the given mask.
The purpose of the mask is that is shows which bits within a network can and can't change. 240 in binary = 1111 0000. This means the first 4 msb in the last value cannot change AND be in the same network.
So let's say your network address is 192.168.1.0/28. Write the last decimal value (0) out in binary with 8 bits. 0000 0000. Since 240 comes out to 1111 0000, the first 4 bits must remain unchanged in order to be subnets on the same network.
From here, subnets and hosts are determined by the last 4 bits. You can have 2 subnets with 6 hosts/subnet or 4 subnets with 2 hosts/subnet. Say you're going with the first option. The last decimal in the address (0) has this notation. MMMM SHHH
- M is Masked bits which can't change in network.
- S is Subnet ID, which determines the subnet
- H is Host ID, which determines the hosts.
Looking at some values with the mask
- Mask 240 = 1111 0000
- Binary 0 = 0000 0000
- Binary 15 = 0000 1111
- Binary 16 = 0001 0000
As we see, binary 16 would change a bit within the mask. Once a bit covered by the mask is changed, you're in a different network.
So the final breakdown would be
1) IP's in subnet-1 = 192.168.1.1 to 192.168.1.6 where 192.168.1.0 will be subnet id and 192.168.1.7 will be broadcast id.
2) IP's in subnet-2 = 192.168.1.9 to 192.168.1.14 where 192.168.1.8 will be subnet id and 192.168.1.15 will be broadcast id.
Once again, I don't expect much traction on an 8 year old post, but if someone happens across this like I did, I don't want them to get confused with the wrong information.
The gateway address is arbitrary in IPv4. Configured statically or dynamically on each host.
"Class C" is obsolete terminology and not correct.
In a broadcast network, any IP address in the subnet's usable range can be a gateway (and there can be multiple gateways too). It is only by convention that either the first or last usable addresses are typically chosen nowadays.
The gateway for a network/subnet has to be (physically) setup on a network and each host on that network has to be made aware of that gateway - both are setup by the administrator and are picked from an arbitrary IP address in the subnet. Hosts are made aware of the gateway address(es) either by DHCP/Static addressing or by a route advertisement (through a routing protocol like RIP or OSPF, etc).
The last three contributors are correct and for more reference to folks who are new, see at least https://www.rfc-editor.org/rfc/rfc950 "Internet Standard Subnetting Procedure"
精彩评论