Demystifying Switches, Routers, and Gateways in Local Area Networks (LAN)

Meenal JyotikaMeenal Jyotika
2 min read

SWITCH

  1. Crucial for creating a local area network (LAN) where devices can communicate with each other efficiently.

  2. Here the connection between the two systems is made by a switch.

  3. The switch creates the network containing the two systems.

  4. To connect the 2 systems with this switch we need a network interface (physical or virtual) on each host. To see the interface for the host we will use this command – ip link

  5. Let’s assume we have two systems System A and System B, now on System A ip addr add < System A Ipaddress>/<SUBNET_MASK> dev <INTERFACE_NAME> on System B Here, <IP_ADDRESS>: The IP address you want to assign to the interface. It can be in IPv4 or IPv6 format.

    <SUBNET_MASK>: The subnet mask or prefix length associated with the IP address. It determines the network portion of the IP address.

    <INTERFACE_NAME>: The name of the network interface to which you want to add the IP address. For example, –

    ip addr add 192.168.1.10/24 dev eth0 ,

    where 192.168.1.10 is the network of A system.

    ip addr add 192.168.1.11/24 dev eth0 , where 192.168.1.11 is the network of the B system.

  6. Now systems can communicate with each other via this switch.

  7. The switch can only enable communication within the network.

ROUTE

  1. The router connects two networks. It has many network ports.

  2. The router is just another device on the network.

  3. The router will have 2 IP addresses, for each network on which systems are present.

  4. The gateway is the door to the outside world or to other networks.

  5. The gateway is the door to the outside world or other networks.

  6. To see the existing routing configuration on the system – route as a command, it displays the Kernel’s routing table.

  7. To configure a gateway on system B to reach the system C –

    ip route add <destination-IP> via <internet-gateway-id>

  8. destination-IP: Specifies the destination network or host IP address along with the subnet. The IP address of the switch of that network.

  9. internet-gateway-id: Specifies the gateway IP address through which the packet should be forwarded to reach the destination.

  10. Again, run this command – route 8. Step No.7, the configuration needs to be done on all the systems.

    DEFAULT GATEWAY

  1. In Linux, the default gateway is typically the IP address of the router or the network gateway that connects the local network to external networks, such as the Internet.

  2. The command for it is – ip route add default via

  3. Instead of the word “default”, we can use 0.0.0.0 which means any IP address.

0
Subscribe to my newsletter

Read articles from Meenal Jyotika directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Meenal Jyotika
Meenal Jyotika

AWS-DevOps Engineer:: Automating solutions in a chaotic world:: Epicurean passionate:: Sustainable Cultivator::