A firewall is a network security device or software that monitors and controls incoming and outgoing network traffic based on predetermined security rules. Its primary purpose is to establish a barrier between a trusted internal network (like your local network) and untrusted external networks (like the internet) in order to protect the internal network from unauthorized access, cyberattacks, and other security threats.

sudo apt install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing

Allowing SSH by Port Number

sudo ufw allow 4000
Enabling UFW
Your firewall should now be configured to allow SSH connections. To verify which rules were added so far, even when the firewall is still disabled, you can use:
sudo ufw show added
sudo ufw enable
Specific IP Addresses
When working with UFW, you can also specify IP addresses within your rules. For example, if you want to allow connections from a specific IP address, such as a work or home IP address of, you need to use the from parameter, providing then the IP address you want to allow:

sudo ufw allow from
Denying Connections
Or if you want to deny all connections from you could use this command:

sudo ufw deny from
Deleting Rules
sudo ufw status numbered
sudo ufw delete 2

Deleting a UFW Rule By Name
sudo ufw delete allow "Apache Full"

Checking UFW Status and Rules
sudo ufw status verbose
sudo ufw disable
If you already have UFW rules configured but you decide that you want to start over, 
you can use the reset command:

sudo ufw reset
Bastion server/Jump Server
Bastion server
--> AlhadiTech