question about submask of computer network and gateway IP address - ip

If the IP address of a gateway is set as 10.206.0.30 (last section is 0001 1110) and the submask is 255.255.255.240 (last section is 1111 0000). My understanding is I can set the IP for the second computer go through the gate way as 10.206.0.29 (last section is 0001 1101). am I correct? or do I set the IP address of the second computer as 10.206.0.0-15 (last section is 0000 xxxx) to separate gateway with other computers?

Related

Is IP routing table required for host to host communication

Only two hosts are available with IP addresses
192.168.1.2
and
192.168.1.3
What will be the routing table entries, if one has to setup?
What will be the Next Hop if only one interface is there on each machine.
Data can be transferred to and from both the machines.
Basically, my doubt is what will be the next hop in each case
If the packet has to be delivered to some other network (then i think it will be the IP address of the router connecting to it)
If the packet has to be delivered locally (same subnet) what should be the next hop IP
If the packet has arrived on the host, and it has to be given to upper layers (since it has to see once the routing table, what will be the entries in this case)
All entries in the routing table are static.
Thanks
If you have the standard network mask of 255.255.255.0 for those IP addresses, then no you don't need a routing table, or a default gateway since both machines are in the same network.
A routing table is basically a set of directions for how to get to another network. It says that if you want to go to 12.34.56.78 then go out of x network card, and to go 192.168.1.x (presuming you are on the 192.168.1.0 network)
A default network basically says if you're not on this network, and there's not a more precise route i.e. 12.34.56.78 above. then just go through a particular network address.
A local network works through broadcasting, machine A will send a broadcast packet to MAC (hardward) address FF:FF:FF:FF:FF:FF which will be accepted by all traffic on the network. (that isn't separated by a router). The broadcast packet basically says 'who owns IP Address x.x.x.x'
When the machine that owns that address receives that packet it sends a reply back saying 'I do'
Machine A can then start sending packets directly to MAC address of that machine, and Machine can reply to the MAC address that sent them.
From this you can understand why routing becomes important, once you start having a large number of hosts on the network, the network can become flooded just from the sheer volume of ARP requests that are bouncing around it. By splitting the address space into separate address blocks you can limit the number of hosts, and number of ARP requests that the network needs to broadcast.
To understand how this works at a lower level, you need to understand how IP addresses and subnet masks are used to determine network membership. Internally an IP Address and network mask are represented as binary numbers. The subnet mask will define the split between the network and the subnet. (it uses a Logical AND obtain the network id)
Address: 11000000 10101000 00000010 00000010
Subnet Mask: 11111111 11111111 11111111 00000000
Once it has the network id it can compare that to the address it is trying to send (using the same logic) to and determine what to do with it.
The logic for that goes something like this
If a packet's Network id matches a local network id send it directly, without routing.
If a packet's network id matches a specific route in a routing table. for instance if the packet is 10.1.1.1, and there is a route for 10.1.0.0/255.255.0.0 then forward the packet to the route marked in that routing entry.
If a packet's network id doesn't match a specific route, and there is a default gateway specified, then forward it there.
If there is no specific route, and no default gateway, return a failed send.
P.S. this is very simplified, in reality there are additional nuances!

What are the functions of the first and last IP address of every subnet?

I am new to IPs and subnets. I can calculate it and know the basics. Unfortunately, I couldn't find an answer to this question.
IPs ending on 0 designate the network address. Commonly, this address defines the route which traffic will be sent to.
Imagine that you have two routers connected by serial, so you have two subnets with 2 different private IPs: 10.0.0.0/8 and 11.0.0.0/8. /8 defines the address length in bits (Class A IP). First router will route traffic to 10.0.0.0 and second router will route traffic to 11.0.0.0.
IPs ending on 255 designate the broadcast address, a special address used to deliver packets to all hosts in the network.
For example, in case of ARP is very useful to locate/query other device's MAC by sending to the broadcast address a packet where you ask who has the MAC of a specefied IP. All the devices will capture your ARP request and if any of them has the specified IP, then you'll get a response with the MAC, but notice that you can be tricked since MAC can be impersonated (ARP Spoofing).
Regards.

If all bits of an IP are 0, the address refers to this host on this network. What exactly "this" means?

I was studying about the IP Class and reserved IP.
Somewhere it said "If an IP address consists of all zeros, the address refers to this host on this network."
What is referred to "this" in phrase "this host on this network"
Originally, the IPv4 address of all 0 (0.0.0.0) meant "This Network." That referred to the fact that it was used as a broadcast address for the network. It is, for all practical purposes, an invalid host address. It is often used for things like routing protocols with a mask length of 0 (0.0.0/0) to represent any address (default route).
The address of all 1 (255.255.255.255) is known as the "Limited Broadcast" address.
The original IP RFCs created the network classes, but they have since been obsoleted by RFCs creating Classless Interdomain Routing (CIDR) and Variable Length Subnet Masking (VLSM). I'm not sure why classful network is still taught today since it isn't really used anymore, but:
Class A addresses all start with a 0 as the first bit in the
address (0.0.0.0 to 127.255.255.255), and they have an 8-bit mask
(255.0.0.0).
Class B addresses all start with 10 as the first two bits in the
address (128.0.0.0 to 191.255.255.255), and they have a 16-bit
mask (255.255.0.0).
Class C addresses all start with 110 as the first three bits in the
address (192.0.0.0 to 223.255.255.255), and they have a 24-bit
mask (255.255.255.0).
Class D addresses (today, used for multicast) all start with 1110
as the first four bits of the address (224.0.0.0 to
239.255.255.255). Multicast doesn't use address masks since each
multicast address represents a multicast group to which host listen
to individually.
Class E addresses (reserved or experimental) all start with 1111 as
the first four bits of the address (240.0.0.0 to
255.255.255.255). Since these are all (except the Limited Broadcast
address) are invalid addresses, they do not use masks.
CIDR and VLSM did away with classful networking, and you should now look at a practical valid address as a series of bits in the range of 1.0.0.0 to 223.255.255.255, having a practical mask length of between 8 (255.0.0.0) and 32 (255.255.255.255).
In reality, IPv4 addresses and masks are just 32-bit unsigned integers on which to perform logical operations. When you are given problems involving IP addresses and masks, it is far easier to convert the dotted-decimal notation into binary to perform the operations, and then convert back to dotted-decimal for the final answer.
What 0.0.0.0 means depends on the context.
To a server process, it means "all IP addresses configured on this host." Let's say you have a host with multiple IP addresses configured, and you want to run a web server on port 443. You can either tell the web server to bind to a specific IP address, or you can tell it to bind to 0.0.0.0, meaning "bind to all IP addresses configured on this host."
In the context of a routing table, it means "the default route," which is sometimes expressed as 0.0.0.0/0. An example routing table:
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.131.64.1 0.0.0.0 UG 0 0 0 eth0
10.131.64.0 0.0.0.0 255.255.192.0 U 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
This table shows that 0.0.0.0 (the default route) points to the gateway 10.131.64.1. It then points other destinations to the default route at 0.0.0.0.
Here is an iptables ruleset snippet showing the CIDR notation 0.0.0.0/0. You can think of these entries being "FROM any TO any."
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
It is also used in some other cases, e.g. when a host comes up on a network and asks for address assignment via DHCP. If the host has no prior assigned address to try to use, it will be 0.0.0.0 until it has something assigned.
This is all in IPv4. In IPv6, you would see ::/0 instead.
A network is a created by using the subnets, mainly class A,B and C
now IPV4 has 4 octets with 8 bits each
11111111.11111111.11111111.11111111
Now if I take an IP whose bits are as under
11111111.11111111.11111111.11111110 and the subnet is
11111111.11111111.11111111.00000000
It is an ip on the network of a particular subnet, in this example Class C
The 'this network' implies the IP addresses is a member of the network like
11111111.11111111.11111111.11111000
or
11111111.11111111.11111111.11111100

Is a subnet's broadcast address required to be the highest address in the subnet?

For example, consider the following network:
IP address: 192.168.0.1
subnet mask: 255.255.255.0
Is the broadcast address required to be 192.168.0.255?
Broadcast Address Defined by RFC 919
Yes, it is required. The (direct) broadcast address is the "all-ones-address" in the local network as defined by RFC 919, thus always the last address in a network range.
Since the local network layer can always map an IP address into data
link layer address, the choice of an IP "broadcast host number" is
somewhat arbitrary. For simplicity, it should be one not likely to
be assigned to a real host. The number whose bits are all ones has
this property; [...]
Examples
For the network from your example, this would be 192.168.0.255, expressed in binary:
11000000 10101000 00000000 11111111
For a network like 10.0.0.32/248 (thus subnet mask 255.255.255.248), it would be 10.0.0.39 (next subnet starts at 10.0.0.40).
00001010 00000000 00000000 00100111
Exemptions
Exemptions exist for /31 and /32 networks. /31 networks (P2P-networks) do not have a broadcast address, they only have two hosts and are sometimes used to connect networks. /32 networks reference a single host together with dedicated routing rules (as there is no gateway).
Yes, though the broadcast address varies dependent on the subnet. From wikipedia:
The broadcast address for an IPv4 host can be obtained by performing a
bitwise OR operation between the bit complement of the subnet mask and
the host's IP address.
Example: For broadcasting a packet to an entire IPv4 subnet using the private IP address space 172.16.0.0/12, which has the subnet mask 255.240.0.0, the broadcast address is 172.16.0.0 | 0.15.255.255 = 172.31.255.255.

Networks vs Subnetworks

Can a computer with an IP address of class C like 192.168.0.1 and subnet mask 255.255.255.0 communicate and share resources with another computer having the IP 192.168.1.1 and the same subnet mask 255.255.255.0 ? I'm asking this because the first 3 octets in this case tell us that these IPs are running on different networks (network 192.168.0.0 and network 192.168.1.0).
Also, does "network" mean the same thing as "subnetwork" (or "subnet") in this context?
Thank you!
To fully understand how computer networks work, you need to take a look at OSI model (or in practice - TCP/IP or DoD model. For your question you need to look at first three layers: physical, data link and network.
Physical connection is self explanatory, and represents direct connection via some medium (copper, glass, air).
When a host A tries to send a packet to host B first thing it will do is look at the destination IP address and based on it's own IP configuration determine if host B is in the same subnet as a host A. This is done as Eugen Rieck explained to you already: subnet mask bits are used to mask the bits of the IP address (logical AND operation). Now, we have two cases:
Host A and B are in the same subnet.
Host A and B are not in the same subnet.
You should note that on layer 2, which network adapters use to send and receive frames, there is no IP addresses (which are present on layer 3) but instead the communication between devices is done by using MAC addresses. Because of that, host can directly communicate only with hosts in their subnet (1st scenario). For sending a frame host A needs the MAC address of host B. So host A first looks up the MAC address mapped to the IP address of host B in his ARP table. If he can't find it, it sends broadcast ARP request asking all host on the subnet who has that specific IP. If he gets a response it adds the MAC address of the host he got the reply from and builds a packet with destination MAC address of that host and IP address of that host.
If both hosts are not in the same subnet (2nd scenario) the packet is sent to default gateway which is responsible for finding a route to the destination. The crucial point to make here is that even if the destination MAC address in this case is the MAC address of the router (default gateway), the destination IP address is still the IP address of host B as in the first scenario. As the packet flows from router to router the source and destination MAC addresses will change, as they are locally significant, but the source and destination IP address will stay the same. This is how every layer provides a service (so to speak) to upper layers, and upper layers use it transparently without needing to know what is happening below.
So you have:
1st scenario.
----------------
L2:
Src MAC: host A
Dst MAC: host B
----------------
L3:
Src IP: host A
Dst IP: host B
----------------
2nd scenario:
----------------
L2:
Src MAC: host A
Dst MAC: router
----------------
L3:
Src IP: host A
Dst IP: host B
----------------
To sum it up (the answer #Eugen Rieck already gave you):
Two hosts which are not in the same subnet as in your example (192.168.0.1/24 and 192.168.1.1/24) will not be able to communicate on layer 2, and will require a L3 capable device such as router to act as a default gateway and to route the traffic between two networks (broadcast domains) for layer 3 connectivity.
Yes and no:
Yes: Those two computers can communicate, if there is a (properly set up) router in between and both sides have knowledge of it.
No: Those two computers can not communicate, if simply wired to the same dumb switch.
Rule of thumb: IP & SNM must be identical for all participants to allow direct communication.
You'd need to change the subnet mask to 255.255.254.0, or use a router or layer-3 switch to communicate.
Network generally means the whole network you're referring to, while subnet refers to a specific separate portion of it. However, the terminology is pretty loose.

Resources