You are on page 1of 4

Block Sites in Ubuntu

Open a terminal, and type sudo vi /etc/hosts.

Type Shift+G, then Shift+A, then I.

You should now see --INSERT-- at the bottom of the screen. Then, cut and paste this code:

127.0.0.1 siteyouwanttoblock.com

To save, press : and type wq and click enter.

Configure Built-in Firewall in Ubuntu


apt-get install ufw

To check whether ufw is running run

systemctl status ufw

If it is running, you should get the output below

● ufw.service - Uncomplicated firewall


Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor
preset: enab
Active: active (exited) since Tue 2018-04-10 22:03:30 UTC; 4min
1s ago
Process: 376 ExecStart=/lib/ufw/ufw-init start quiet
(code=exited, status=0/SU
Main PID: 376 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
CPU: 0
CGroup: /system.slice/ufw.service

Apr 10 22:03:30 ip-172-31-41-251 systemd[1]: Started Uncomplicated


firewall.
Warning: Journal has been rotated since unit was started. Log
output is incomple
To check whether it's active or inactive run

ufw status

If it is inactive, you'll get the output below

Status: inactive

To turn UFW on with the default set of rules run

ufw enable

To disable the firewall run

ufw disable

Setting up default ufw rules


To set up default rules that allow all outgoing
protocols, log in as root and run

ufw default allow outgoing

Output

Default outgoing policy changed to 'allow'


(be sure to update your rules accordingly)

To deny all incoming connections, run

ufw default deny incoming

Output

Default outgoing policy changed to 'deny'


(be sure to update your rules accordingly)

The above commands will allow all outgoing connections


and deny or block all incoming connections.

At this point, you may want to enable the firewall,


however before you don that, allow ssh first. This
prevents disconnection to the server since we specified
the denial of all incoming connections earlier on.

To allow ssh, run

ufw allow 22/tcp

Outgoing

Skipping adding existing rule


Skipping adding existing rule (v6)

ssh access can also be allowed by service name,

ufw allow ssh

If you want to remove the rule run

ufw delete allow 22/ssh

To deny a service by name run

ufw deny service-name

Starting ufw firewall


To activate the firewall log in as root and run following
command:
ufw enable

You may be prompted with the following warning

Command may disrupt existing ssh connections. Proceed with


operation (y|n)? y

If you select yes, you'll get the output below

Firewall is active and enabled on system startup

Firewall is now active and it will start on every boot.


We can look at firewall rules again:

ufw status

Source: https://linoxide.com/linux-how-to/setup-ufw-ubuntu/

You might also like