Demystifying Switches, Routers, and Gateways in Local Area Networks (LAN)
SWITCH
Crucial for creating a local area network (LAN) where devices can communicate with each other efficiently.
Here the connection between the two systems is made by a switch.
The switch creates the network containing the two systems.
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
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 ,
where192.168.1.11
is the network of the B system.Now systems can communicate with each other via this switch.
The switch can only enable communication within the network.
ROUTE
The router connects two networks. It has many network ports.
The router is just another device on the network.
The router will have 2 IP addresses, for each network on which systems are present.
The gateway is the door to the outside world or to other networks.
The gateway is the door to the outside world or other networks.
To see the existing routing configuration on the system –
route
as a command, it displays the Kernel’s routing table.To configure a gateway on system B to reach the system C –
ip route add <destination-IP> via <internet-gateway-id>
destination-IP
: Specifies the destination network or host IP address along with the subnet. The IP address of the switch of that network.internet-gateway-id
: Specifies the gateway IP address through which the packet should be forwarded to reach the destination.Again, run this command – route 8. Step No.7, the configuration needs to be done on all the systems.
DEFAULT GATEWAY
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.
The command for it is – ip route add default via
Instead of the word “default”, we can use 0.0.0.0 which means any IP address.
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::