Tuesday, April 25, 2023

Networking basics interview Q&As on ip address, subnet mask, DNS & gateway

 

Do software developers need to know networking?

The answer is Yes, but networking is a very vast subject. Knowing some basic fundamentals will make you a better developer. With the advent of cloud computing, containers like Docker & container orchestration technologies like Kubernetes, etc it makes more sense to have a basic understanding of networking.

Q1. What do you understand by the terms IP addressSubnetDNS server & Gateway?
A1. If you want to connect from a client to a server machine, you need 4 things:

1) IP Address: E.g. 9.1.1.11 denotes a host’s identity on a newtwork.

2) Subnet Mask: E.g. /24 or 255.255.255.0, tells the size of a host’s network, and allows the host to determine if it is trying to reach a machine on its own network or a foreign network outside its network.

3) Default Gateway: E.g. 9.1.1.1 If a client tries to reach a host machine in the same network, an ip address & a subnet mask will suffice, but if the host machine is outside on the internet in a wan, you need the ip address of the router, which is the default gateway.

4) DNS Server IP: E.g. 8.8.8.8. This is required to translate a domain name like myserver.com.au to its ip address. DNS stands for Domain Name System, which is used to look up for an IP address for a given domain name like google.com.

LAN (Local Area Network), WAN (Wide Area Network) and Routers

LAN (Local Area Network), WAN (Wide Area Network) and Routers

IP Address

An IP address is a unique address that identifies a device on the internet (i.e. WAN) or a local area network (i.e. LAN). IP stands for Internet Protocol. An example of an IP address is 192.158.1.38. Each number in the set can range from 0 to 255. So, the full IP addressing range goes from 0.0.0.0 to 255.255.255.255. This is an ipv4 address with 232 (i.e. ~ 4 billion) possible IP addresses. Given the number of devices we have in the world this is not enough, and this shortage has been addressed with

1) public versus private IP addresses.

2) ipv6 with 2128 possible ip addresses, which is very very large. The ipv6 has 8 values of 2 bytes (i.e. 16 bits) separated by “:“. 8 * 16 bits = 128 bits. ipv6 example:

2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF

These are hexadecimal values from 0-9, A, B, C, D, E, and F with 16 values. 4 bits represents these values. We will look at these 2 approaches to rectify the short of of IP address problem later.

There are static (i.e. remain consistent once the network assigns an IP address) & dynamic (i.e. change automatically and regularly) IP addresses. Dynamic IP address makes it harder for criminals to hack into your network interface and also cost by having a pool of IP addresses & recycling them. Static IP addresses are vital if you want other devices to be able to find them consistently on the web.

Q2. How will you find out the ip address of a host machine?
A2. ifconfig on Mac & ipconfig on windows command-line. On your mobile devices via the settings.

Subnet

subnet, or subnetwork, is a segmented piece of a larger network. More specifically, subnets are a logical partition of an IP network into multiple, smaller network segments. The practice of dividing a network into two or more networks is called subnetting. Subnetting provides us with a number of benefits, such as

1) Conserving IP addresses.

2) Reducing the network traffic. If a machine #1 needs to communicate with machine #1000, it needs to broadcast to all the say 700 machines in the network. This can cause chaos. By dividing this into say 10 subnets, routers can be used to route across the subnets & broadcast only within a subnet with say 100 machines.

3) Simplifying the network design.

Q3. What is a subnet mask?
A3. A subnet mask is a 32-bit number created by setting host bits to all 0s and setting network bits to all 1s. In this way, the subnet mask separates the IP address into the network and host addresses.

Network classes, CIDR, Subnet mask and Hosts

Network classes, CIDR, Subnet mask and Hosts

As shown above an IP address consists of two things i.e network address and host address. But from IP address only we are not able to find out which is network address and which is host address. So subnet mask allows us to find out network address and host address from the IP address. The 1s in the subnet mask denote a network bit & 0s denote a host bit. The 1s in the subnet mask must be contiguous.

Learn more about subnet mask at: https://www.youtube.com/watch?v=s_Ntt6eTn94

Q4. Can you identify some address range missing in the class A network?
A4. Yes, IPv4 network standards reserve the entire address block 127.0. 0.0/8 (more than 16 million addresses) for loopback purposes. That means any packet sent to any of those addresses is looped back.

In IPv6, the loopback address is 0:0:0:0:0:0:0:1 or ::1

Q5. How many networks can you have in each class of network?
A5.

In Class A, as shown in the diagram the network has 8 bits, which means 28, but the first bit of “1” is reserved to denote class type A. This means 28-1 = 27 = 128 networks. There will be 16,777,216 hosts (i.e 256 * 256 * 256), but only 16,777,214 will be available for hosts as 2 ip addresses are always reserved for network & broadcast. The “255” address is always assigned to a broadcast address, and the “0” address is always assigned to a network address. This class is used by very large organisations like your ISP (i.e. Internet Service Provider).

In Class B, as shown in the diagram the network has 16 bits, which means 216, but the first 2 bits of “01” is reserved to denote class type B. This means 216-2 = 214 = 16,384 networks. There will be 256 * 256 – 2 = 65,534 ip addresses for hosts. This class is used by large enterprises.

In Class C, as shown in the diagram the network has 24 bits, which means 216, but the first 3 bits of “001” is reserved to denote class type C. This means 224-3 = 221 = 2,097,152 networks. There will be 256 – 2 = 254 ip addresses for hosts. This class is used by small to medium size enterprises.

The other two classes are used for other purposes like class D for multicast and class E for experimental purposes.

Q6. What is a CIDR?
A6. CIDR is a method of assigning IP addresses that improves the efficiency of address distribution and replaces the previous system based on Class A, Class B and Class C networks. CIDR is the short for Classless Inter-Domain Routing, an IP addressing scheme that replaces the older system based on classes A, B, and C. A single IP address can be used to designate many unique IP addresses with CIDR.

CIDR conversion table

CIDR conversion table

Q7. What is Subnetting?
A7. The goal of a subnet is to split a large network into a group of smaller and interconnected networks to help minimise traffic. Subnetting prevents the unnecessary flow of routs, increasing network speeds. Subnetting also improves address allocation efficiency as same private ip addresses can be allocated to a LAN.

Q8. What is the purpose of Subnet mask?
A8. A subnet mask help determine if the target host is in the same LAN (i.e subnetwork) or a foreign network requiring to be routed via a router (i.e. a Gateway).

Gateway

A router is a networking layer system used to manage and forward data packets to devices network while a gateway is simply a hardware that acts as a gate between the networks. A gateway serves as a single access point and a converter to connect dissimilar networks using different protocols, while a router sets the shortest path for the data packets to travel from source to destination. Companies may deploy gateways to connect the corporate LAN to the public Internet or to link different internal networks.

Firewall

Q9. What is a Firewall?
A9. A firewall is a digital security system that checks all incoming and outgoing traffic on a network according to a defined set of rules. A firewall keeps out unauthorised traffic and lets in only communications that are deemed safe, using a set of security rules that you or your network administrator set up.

DMZ

Q10. What is a DMZ Network?
A10. DMZ is to add an extra layer of security to an organisation’s local area network (i.e LAN). A DMZ network gives organisations extra protection in detecting and mitigating security breaches before they reach the internal network, where valuable assets are stored.

All services accessible to users on communicating from an external network can and should be placed in the DMZ. For example, Web servers, Mail servers and FTP Servers. Web servers that communicate with an internal database server may need to be placed into a DMZ. This helps ensure the safety of the internal database, which is often storing sensitive information. The web servers can then interact with internal database server through an application firewall still under the umbrella of the DMZ protections.

Public Vs private IP addresses

Q11. What is a public ip address?
A11. A public IP address is an IPv4 address that is reachable from the internet. If a resource in your tenancy needs to be directly reachable from the internet, it must have a public IP address.

Having a public IP address is like having a P.O. box number instead of using your home address. A public address must be unique, and two devices cannot have the same public address. Your public IP address is the IP address that someone on the other end of your internet activity would see. If you ping google.com you will see their public address.

Q12. What is a private ip address?
A12. A private IP address is a range of non-internet facing IP addresses.

192.168.0.0 – 192.168.255.255 (65,536 IP addresses)
172.16.0.0 – 172.31.255.255 (1,048,576 IP addresses)
10.0.0.0 – 10.255.255.255 (16,777,216 IP addresses)

A private IP address is an address provided by network devices used only in an internal network (e.g. LAN or home network). It is also referred to as a local IP or internal IP. These IP addresses need not be unique & two different private networks can have the same IP address. Routers assign each private IP within the local area network (LAN) from the Internet Assigned Numbers Authority (IANA).

This is one of the ways of mitigating the shortage of IP addresses.

Q13. What are the differences between public & private IP addresses?
A13.

1) Private ip addresses are used to connect to other devices on the same local area network (LAN), and public ip addresses are used to connect to the Internet in a wide area network (WAN).

2) Private ip addresses are assigned by the network device, like the router, and public ip addresses are assigned by an Internet service provider (i.e. an ISP).

3) Private ip address can use the same address for multiple devices as long as they’re not on the same network, and public ip address must be unique to avoid ip conflict.

4) Private ip addresses can be found in individual device settings & via ipconfig or ifconfig, and public ip addresses can be found via online searches.

5) Private ip addresses can be found within the LAN, and public ip addresses can be found within the entire internet and WAN.

6) Private ip addresses are limited to 192.168.0.0 – 192.168.255.255, 172.16.0.0 – 172.31.255.255 and 10.0.0.0 from class A, B & C, and a public address can be any string of numbers outside those set aside for class A, B, or C. So, you can look at an ipv4 address & tell if it is a private or public address.

7) A private ip address change based on a network connection, and a public ip address changes periodically, since most ISPs use dynamic IP address systems.

Q14. Why do we have two types of addresses?
A14. At the beginning of the internet only IPv4 public IPs were in use, and each device received a public address to connect directly. However, as the Internet grew, the limited amount of public IPv4 addresses no longer had the capability to cover all devices. Because of this issue, NAT & ipv6 addresses emerged.

NAT

Q15. What is a NAT?
A15. NAT stands for network address translation. It’s a way to map multiple private addresses inside a local network to a public IP address before transferring the information onto the internet.

Step 1: NAT is a process in which your router translates your private IP address into a public one so that it can send your traffic over the internet, keeping track of the changes in the process.

Step 2: When the information comes back to your router, it reverses the change — from a public IP address into a private one — and forwards the traffic back to your computer.

Though IPv6 addresses with 2128 ip addresses, which is very very large number of ip addresses compared to the ipv4 with 232 (i.e. ~ 4 billion) have become the new solution to IPv4 exhaustion, the public and private addresses of NAT are still used to connect computing devices to each other and to the Internet.

Port forwarding

Q16. What is port forwarding?
A16. Port forwarding creates an association called a map between a router’s public, wide area network (i.e. WAN) IP address and a private, local area network (i.e. LAN) IP address for a device on that private network. Port Forwarding sets up public services on your network such as web servers, FTP servers and e-mail servers. When users send this type of request to your network via the Internet, the router will forward these requests to the appropriate computer.

No comments:

Post a Comment