• Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / Linux sysadmin tutorials linux system administrator / ufw firewall commads allow port enable disable ubuntu 20.04

ufw firewall commads allow port enable disable ubuntu 20.04

Table of Contents

Toggle
  • ufw commands
  • ufw status inactive
  • UFW Allow Port
  • UFW Allow service nginx apache etc
    • sudo ufw app list
    • UFW Block Port
  • UFW Block All Ports except allowed
  • Delete UFW rule
  • ufw rules
  • rate limiting linux with ufw
  • ufw configuration file to save changes permanently
  • sudo ufw app list
  • ufw logging high
  • UFW Allow mail server

ufw commands

allow, disable, enable, status, applist
sudo ufw allow ssh/tcp
$ sudo ufw logging on
$ sudo ufw enable
$ sudo ufw status
IPtables rules vanished after reboot. but install persistent
rate limiting
ufw limit SSH  6r/30s
ufw will normally allow the connection but will deny connections if an IP address attempts to initiate six or more connections within thirty seconds
firewall install activate
sudo apt-get install ufw

ufw status inactive

don;t unable unless you have added the rules
sudo ufw enable
root@-s-4vcpu-8gb-blr1-01:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
enable on reboot
sudo ufw status verbose
sudo ufw help
root@instance-1:~# sudo ufw status verbose
Status: inactive
root@instance-1:~# sudo ufw app list
Available applications:
  OpenSSH

UFW Allow Port

sudo ufw allow 80
sudo ufw allow 22
sudo ufw allow 443
sudo ufw allow 3306
sudo ufw allow 9000
sudo ufw allow 6379  //redis
         ufw allow 80/tcp
sudo ufw allow 80 && sudo ufw allow 22 && sudo ufw allow 443 && sudo ufw allow 3306 && sudo ufw allow 9000 && sudo ufw allow 6379
port 9000

UFW Allow service nginx apache etc

port 80 automatically adds above services
The profiles are kept in /etc/ufw/applications.d
root@-s-4vcpu-8gb-blr1-01:~# sudo ufw allow ‘Nginx HTTP’
ERROR: Could not find a profile matching ‘Nginx HTTP’

sudo ufw app list

sudo ufw allow nginx

root@-s-4vcpu-8gb-blr1-01:~# ls /etc/ufw/applications.d
openssh-server

cat /etc/ufw/applications.d/openssh-server

root@-s-4vcpu-8gb-blr1-01:~# cat /etc/ufw/applications.d/openssh-server
[OpenSSH]
title=Secure shell server, an rshd replacement
description=OpenSSH is a free implementation of the Secure Shell protocol.
ports=22/tcp

root@-s-4vcpu-8gb-blr1-01:~# sudo ufw app list
Available applications:
OpenSSH

UFW Block Port

sudo ufw deny out 25
sudo ufw allow 21

UFW Block All Ports except allowed

to see open ports in linux
sudo lsof -i -P -n | grep LISTEN
to see incoming connections linux
netstat -an | grep ‘LISTEN’
netstat -natu | grep ‘ESTABLISHED’

Delete UFW rule

sudo ufw status numbered
sudo ufw delete 5
sudo ufw delete deny 22

ufw rules

root@-s-4vcpu-8gb-blr1-01:~# ufw status
Status: active

To Action From
— —— —-
80 ALLOW Anywhere
22 ALLOW Anywhere
443 ALLOW Anywhere
3306 ALLOW Anywhere
9000 ALLOW Anywhere
6379 ALLOW Anywhere
22/tcp ALLOW Anywhere
80 (v6) ALLOW Anywhere (v6)
22 (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)
3306 (v6) ALLOW Anywhere (v6)
9000 (v6) ALLOW Anywhere (v6)
6379 (v6) ALLOW Anywhere (v6)
22/tcp (v6) ALLOW Anywhere (v6)

rate limiting linux with ufw

cat /etc/ufw/after.rules
cat /etc/ufw/before.rules
nano /etc/ufw/after.rules
# Limit connections per IP
-A ufw-http -m state –state NEW -m recent –name conn_per_ip –set
-A ufw-http -m state –state NEW -m recent –name conn_per_ip –update –seconds 10 –hitcount 45 -j ufw-http-logdrop

ufw configuration file to save changes permanently

Prior to running the rules input through the terminal, UFW will run a file, before.rules
cat /etc/ufw/before.rules
cat /etc/ufw/after.rules (if any changes made via terminal)
ipv6 rules
after6.rule
before6.rules
/etc/ufw/user.rules
also check in /lib/ufw/user.rules
UfW is frontend for iptables, so iptables-save and iptables-restore would work fine with it.
ufw status numbered
ufw delete NUM
is ufw interfere with iptables
No,
ufw log errors configuration
sudo ufw logging on
/var/log/ufw.log
Sep 16 15:08:14 <hostname> kernel: [UFW BLOCK] IN=eth0 OUT= MAC=00:00:00:00:00:00:00:00:00:00:00:00:00:00 SRC=123.45.67.89 DST=987.65.43.21 LEN=40 TOS=0x00 PREC=0x00 TTL=249 ID=8475 PROTO=TCP SPT=48247 DPT=22 WINDOW=1024 RES=0x00 SYN URGP=0
The initial values list the date, time, and hostname of your Linode. Additional important values include:
[UFW BLOCK]: This location is where the description of the logged event will be located. In this instance, it blocked a connection.
IN: If this contains a value, then the event was incoming
OUT: If this contain a value, then the event was outgoing
MAC: A combination of the destination and source MAC addresses
SRC: The IP of the packet source
DST: The IP of the packet destination
LEN: Packet length
TTL: The packet TTL, or time to live. How long it will bounce between routers until it expires, if no destination is found.
PROTO: The packet’s protocol
SPT: The source port of the package
DPT: The destination port of the package
WINDOW: The size of the packet the sender can receive
SYN URGP: Indicated if a three-way handshake is required. 0 means it is not.
sudo ufw logging low|medium|high,

sudo ufw app list

root@-s-4vcpu-8gb-blr1-01:~# sudo ufw app list
Available applications:
  OpenSSH
sudo ufw deny 21
sudo ufw enable
sudo ufw disable
sudo ufw status
sudo ufw allow ssh
To additionally let in HTTP and HTTPS traffic, we can allow the “WWW Full” application profile:
ERROR: Could not find a profile matching ‘Nginx HTTP’
– sudo ufw allow ‘WWW Full’
sudo ufw allow ‘WWW Full’
If ip tables firewall
sudo iptables -S
sudo iptables -S
 netstat -tlpn
netstat -tlpn
sudo iptables -L -n
service vsftpd stop
/etc/init.d/ssh restart
check ssh2 php support
php -m |grep ssh2
install
aptitude install libssh2-1-dev libssh2-php
apt-get
sudo service iptables stop
sudo ufw disable
– sudo ufw allow ‘Nginx HTTP’
You can verify the change by typing:
– sudo ufw status
– /etc/default/ufw : This is main ufw config file for default policy and kernel modules.
cat /etc/default/ufw
– /etc/ufw/before.rules : Rules in these files are calculate before any rules added via the ufw command.
– /etc/ufw/after.rules : Rules in these files are calculate after any rules added via the ufw command.
/etc/ufw/sysctl.conf
etc/ufw/user.rules
https://www.digitalocean.com/community/tutorials/how-to-setup-a-firewall-with-ufw-on-an-ubuntu-and-debian-cloud-server

ufw logging high

ufw logging off
ufw logging low
sudo netstat -tlpn
sudo iptables -S

UFW Allow mail server

sudo ufw deny out 25  (block outgoing mails)
sudo ufw allow 25 (incoming)
sudo ufw allow 143
Actually, iptables is the real firewall and ufw is only a interface to configure the iptables. I don’t know if there is a way to do it using ufw, maybe other user knows it.
sudo iptables -A INPUT -p tcp –destination-port 22 -m mac –mac-source <Mac_address> -j ACCEPT
sudo iptables -A INPUT -p tcp –destination-port 22 -m mac –mac-source 3C:1E:04:28:16:5A -j ACCEPT
netstat -plnt
Active Internet connections (only servers)
lsof -i :
sudo netstat -plant | grep LISTEN

pam_unix(sshd:auth): check pass; user unknown
Apr 21 06:03:18 -s-4vcpu-8gb-blr1-01 sshd[16902]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=80.98.249.181

The result is RESULT.
Apr 21 06:58:43 -s-4vcpu-8gb-blr1-01 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=a6:01:3e:6a:96:b1:fe:00:00:00:01:01:08:00 SRC=45.146.165.129 DST=128.199.25.144 LEN=40 TOS=0x00 PREC=0x00 TTL=249 ID=46620
PROTO = The protocol used by the attempted connection.

ufw allow ssh out
sudo ufw allow from 203.0.113.4 to any port 22
sudo ufw allow from 15.15.15.0/24 to any port 22

Linux sysadmin tutorials linux system administrator

  • top 10 apt & apt-get commands (most used) apt vs apt-get
  • If-Else Statements in Shell Scripting
  • linux commands pdf (files & Directories, zip & unzip process, search etc)
  • Find Files with Specific Text on Linux grep find command
  • linux performance tuning inode limit file descriptors tco, kernel etc
  • Variables and Data Types in Shell Scripting
  • Top 10 most used Cat commands with examples (create, view, append files)
  • Ip tables / ufw / firewall d commands for block port ip rate limiting
  • Top 10 zip / tar commands to compress & extract files in linux
  • TOP 10 mv & cp commands in linux to move & copy files in Linux
  • Top 10 GREP Commands in linux to search files directory words strings
  • lsof netstat commands to know listening ports in linux 3 ways
  • Upgrade Ubuntu from 18.04 (19.10) to 20.04 LTS command line or gui server | desktop
  • 3 Ways (SCP, rsync, Sftp) linux server migration between two remote server apache nginx
  • linux system specs commands (CPU, Memory, Disk )speed, type. manufacture
  • linux sysctl command tweaks & hardening
  • linux security limits.conf deciding user limits process limits for nginx server
  • ulimit linux unlimited command unlimto set & know user limits open files file descriptor max user process etc.
  • red hat linux certification cost jobs salary syllabus courses fees
  • ufw firewall commads allow port enable disable ubuntu 20.04
  • ddos attack prevention
  • change ssh port in linux - avoid sshd ddos attacks
  • ping command
  • memcached install ubuntu wordpress
  • check linux version (lsb_release -a) ubuntu debian 32 or 64 bit
  • rsync command linux with examples comparison to scp
  • how to uninstall package in linux ubuntu rpm, yum apt-get
  • increase open file limit linux File descriptor ft nginx , mysql, lemp
  • remove repository ubuntu
  • htop commad memory details virtual vs shard vs resident
  • chown command in Linux with Examples
  • Kill PHP process
  • VIrtual Memory vs RSS Memory vs Shared memory in Linux
  • oom killer fixing it by configuration linux ubuntu
  • Install Lemp nginx mysql php fpm Stack on Debian 11 with repository
  • connect two remote servers linux command line
  • auto start after oom killer Mysql & php fpm nginx etc ubuntu wth systemd or cron job
  • load average Linux 1, 5, 15 min 2,4,8 cores explained
  • Control Structures in Shell Scripting
  • Shell Scripting Roadmap for Beginners to Advanced
  • awk commands with practical examples
  • Shell Scripting Tutorial for Beginners 🚀
  • find Command in Linux with Examples
  • sed Command in Linux with Examples (Beginner to Advanced)
  • Linux Text processing commands in with Examples
  • linux disk management commands
  • fdisk command in linux with examples
  • how to add a new disk in linux
  • Linux mount Command with Examples
  • fstab options with examples
  • Top 50 Shell Scripting Interview Questions and Answers
  • Linux Networking Interview Questions and Answers
  • Linux Networking Commands Cheat Sheet with Examples pdf
  • Netstat & SS Commands cheat sheet with examples Interview Questions
  • Nmap Cheat Sheet – Network Scanning & Security
  • Bash Brackets ([], (), {}, $( ), $(( ))) – Types, Uses & Examples

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy