Blocking Websites with Networking

Sainadh
4 min readJul 4, 2021
Photo by Jordan Harrison on Unsplash

In this blog you will come to know about networking, basic network terminology, Linux commands and how to block the website.

In the end our task is to allow Google web page and block Facebook.

Networking

A computer network is a group of computers that use a set of common communication protocols over digital interconnections for the purpose of sharing resources located on or provided by the network nodes.

In our daily life we are using lots of networking concepts from phone calls to watching videos on YouTube and reading this blog.

Terminology in Networks

Internet Protocol (IP): - An Internet Protocol address is a numerical label assigned to each device connected to a computer network that uses the Internet.

We have two types of IP’s ipv4 and ipv6.

IPv4 is of 32bits and IPv6 is of 128bits. In this blog we only use IPv4.

We have two types of Ip address.

One is Public Ip address through this anyone can to our services. And other one private IP address now one can connect to this IP address, this our local system address.

Private IPs are limited with in a range.

  1. 10.0.0.0–10.255.255.255
  2. 172.16.0.0–172.31.255.255
  3. 192.168.0.0–192.168.255.255

Gateway: - A gateway is a hardware device that acts as a “gate” between two networks. It may be a router, security system, server, or other device that enables traffic to flow in and out of the network.

We can configure the gateway to restrict the incoming and outgoing networks.

Genmask:- This is the subnet mask, used to figure out what IP addresses match what destination.

Local Area Network (LAN) :- It covers a small area such as a small office or home. It physically connects all the computers located in the premises.

Linux commands

Route :- It is a command used to view and manipulate the IP routing table in Unix-like and Microsoft Windows operating systems

With the help of route, we can manipulate our gateway to allow only certain IPs to connect our devices.

It can be for incoming and outgoing services.

Ingress: - It is the incoming network packets of a device.

Outgress:- It is the outgoing network packets from a device.

route -n command is used to know the ingress and outgress of our system.

route commands

You can use route — help to know more about the route commands.

In the above image you can see the Destination, it defines from where the packages are coming and where to go. It only looks for the gateway.

Manipulate or customize route

We have the commands like add and delete.

Deleting our route configuration to connect internet.

$ route del -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.1 dev enp0s3$ route del -net 162.254.0.0 netmask 255.255.255.0 gw 0.0.0.0 dev enp0s3# in the aove command dev is the device name

We can also add our required ip address to connect we reconfigure our setup to add internet.

$ route add -net 0.0.0.0 netmask 255.255.0.0 gw 192.168.1.1 dev enp0s3$ route add -net 162.254.0.0 netmask 255.255.0.0 gw 0.0.0.0 dev enp0s3

We also have nslookup command which help us to know the ip address of any services.

nslookup cmd

The best way to use nslookup

$ nslookup <website.com>

Netstat:- It is command to know about the services running in our system.

It describes all the network connection and services used in our system.

netstat cmd

netstal -tnlp is command which describes the services with the port number of our system.

Task: -

We have to setup our system to ping google services and block Facebook services.

From nslookup we come to know that google is running at ip 216.58.197.46.

So, we delete our internal configuration by the above steps and add the new configuration which only sends and receives the network packates from google.

Commands

$ route add -net 216.58.197.0 netmask 255.255.255.0 gw 192.168.1.1 dev enp0s3# Here instead of using 0.0.0.0, we use 216.58.197.0 as Destination, so that our gateway can connect to only google ip

Here I am using my virtual machine to setup the configuration.

ping is command which checks whether the networks packets have reached to the destination or not.

ping cmd

We have successfully completed our task and learned about the basics of networking and Linux commands to change our internal routing.

Thank you for reading my blog if you have any doubts comment below.

--

--

Sainadh

Devops and automation export, explorer, opensource enthusiast, follow for more content related to devops and easy way to do the things.