Basics of Networking...
Tags: beginners, devops, linux
Published: 2022-03-21 12:01:59

### Basic Networking Terms

**LAN**(Local Area Network)

Collection of devices connected together in one *physical* location. Each device has a unique **IP**(Internet Protocol) address. Devices communicate via these IP addresses.

![LAN.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647860192164/u39HMx4tA.png)

**IP**(Internet Protocol)

It's a 32-bit value.

* 1 bit: **1 or 0**.
    
* 00000000: **0**
    
* 11111111: **255**
    
    ![ip-addressing.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1647860218283/5kP3xF97w.jpg)
    

For example, 172.16.0.0

**IP addresses can range from 0.0.0.0 to 255.255.255.255**

**IP address range**

![ip range.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647860280986/NTGVNY5Zu.png)

**Switch**

It sits within the LAN and facilitates the connection between all the devices within the LAN.

![Switch.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647860247157/m3ZXKGYIb.png)

**Gateway** is the **IP address** of the router.

![Gateway.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1647860261506/boTuYCm1m.jpg)

**Router**

It sits between **LAN** and outside networks **(WAN: Wide Area Network)**.

It connects devices on LAN and WAN and allows networked devices to access the Internet.

![Router.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1647860271264/uwr-X6Shw.jpg)

A **subnet** is the **logical subdivision** of an IP network.

![Subnet.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647860372479/prUaxaNfV.png)

How to know whether the other device is inside or outside the LAN?

* It knows because of the IP address of the target device.
    
* Devices in the LAN belong to the same IP address range.
    

**Subnetting** is the process of dividing a network into two or more networks.

**CIDR***(Classless Inter-Domain Routing)* block

It is a subnet mask that dictates how many bits are fixed.

* 255.255.0.0 =&gt; means that 16 bits are fixed
    
* 255.255.255.0 =&gt; means that 24 bits are fixed
    

![CIDR block.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1647860582020/42G5M_-8O.jpg)

**Any device needs 3 pieces of data for communication:**

* IP address
    
* Subnet
    
* Gateway
    

### NAT(Network Address Translation)

It's the IP address range chosen by an administrator.

Each device gets a unique IP from that range.

How to make sure that IP addresses don't overlap?

* IP addresses within LAN are not visible to the outside network or internet.
    
* Your laptop's private IP address is replaced by the router.
    

![NAT.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647861049560/S7uB9G4H8.png)

**Benefits of NAT**

* Security and Protection of devices within LAN.
    
* Reuse IP addresses.
    

*There are a limited no. of IPv4 addresses available - 4,294,967,296 public addresses.*

### Firewall

A system that prevents unauthorized access from entering a private network.

Using Firewall Rules you can define, which requests are allowed.

![Firewall.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647861481860/-CFrbZDhk.png)

What are these firewall rules?

* It defines which IP address in your network is accessible and which IP address can access your server.
    
    * For example, you can allow any device to access your server.
        
* It allows the device's IP address at the port to be accessed.
    
* This is also called **Port Forwarding**.
    

![Firewall Rule.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647861543124/dQ6a_NroG.png)

### What is a Port?

Port =&gt; every device has a set of ports.

You can allow specific ports(doors).

You can allow specific ports(doors) AND specific IP addresses (guests).

Different Applications listen to specific ports.

![Ports.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1647862056022/LCqPF4c83.jfif)

**Standard Ports for many applications**

* Port **80** =&gt; Web Servers
    
* Port **3306** =&gt; MySQL DB
    
* Port **5432** =&gt; PostgreSQL DB
    

For every application, you need a port!

**Each port is unique on a device.**

### DNS or Domain Name Service

It translates domain names to IP addresses.

![what-is-dns.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647862414466/2h9sHMqBl.png)

Why do we use names instead of IP addresses?

* Humans are better at remembering words & names instead of numbers.
    

For example, **www.facebook.com** is converted to **69.63.176.13** *(Mapping IP addresses to names).*

How does DNS manage all these IP addresses?

* Domain Names have a hierarchical structure.
    

**Root Domains** *(there are 13 root domains named from a to m)*

**Top Level Domain**

![TopLevelDomainNames.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1647862737667/TQvr_umFK.jpg)

There are also geographical domains that were added later.

![domains.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1647862829646/sHS6Vlgzp.gif)

Who manages these names?

Who can keeps the track of the availability of names?

This is all regulated by a dedicated organization called Internet Corporation for Assigned Names & Numbers**(ICANN)**.

![ICANN.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1647863414740/xfI8x1r40.png)

This organization manages the TLD development and architecture of the internet domain space and authorizes Domain Name Registrars, which register and assign domain names.

Each domain name can have a subdomain name with an IP address range of the domain name.

### How does the DNS Resolution work?

![rc24-how-dns-works.webp](https://cdn.hashnode.com/res/hashnode/image/upload/v1647863446892/JufhMCS_u.webp)

**DNS entries are cached for efficiency.**

### Networking Commands

* `ifconfig` =&gt; shows all network details.
    
* `netstat` =&gt; shows an active connection on your machine.
    
* `ps -aux` =&gt; shows currently running applications on which port they are listening, computer resources they are consuming, etc.
    
* `nslookup` =&gt; you can get the IP address of any domain name.
    
* `ping` =&gt; checks whether a service/application is accessible.
    

These are used to troubleshoot your network.

* And of course, there are parameters for all those commands.