Install UFW pada Ubuntu 20.04 / Debian 11
Update OS
sudo apt update -y
Install UFW
sudo apt install ufw -y
Cek status
sudo ufw status verbose
UFW Default Policies
Perilaku default dari UFW Firewall adalah memblokir semua lalu lintas masuk dan meneruskan dan mengizinkan semua lalu lintas keluar. Ini berarti bahwa siapa pun yang mencoba mengakses server Anda tidak akan dapat terhubung kecuali Anda secara khusus membuka port tersebut. Aplikasi dan layanan yang berjalan di server Anda akan dapat mengakses dunia luar.
Kebijakan default didefinisikan dalam file /etc/default/ufw dan dapat diubah baik dengan memodifikasi file secara manual atau dengan perintah sudo ufw default <policy> <chain>.
Application List pada UFW
cek list aplikasi
sudo ufw app list
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
cek full info aplikasi
sudo ufw app info 'Nginx Full'
Enable UFW
Allow SSH service
sudo ufw allow ssh
allow port daemon ssh
sudo ufw allow 7722/tcp
Enable UFW
sudo ufw enable
Cara Open Port
general command
ufw allow port_number/protocol
allow service
sudo ufw allow http
allow port dan protokol
sudo ufw allow 80/tcp
Allow port range
sudo ufw allow 7100:7200/tcp
sudo ufw allow 7100:7200/udp
Allow spesifik IP dan port
spesifik IP
sudo ufw allow from 10.10.10.10
Allow spesifik IP menuju port
sudo ufw allow from 10.10.10.10 to any port 22
Subnets
sudo ufw allow from 192.168.1.0/24 to any port 3306
Network Interface
sudo ufw allow in on eth2 to any port 3306
Denying connections
sudo ufw deny from 23.24.25.0/24
sudo ufw deny proto tcp from 23.24.25.0/24 to any port 80,443
Deleting UFW Rules
Cek list
sudo ufw status numbered
Delete rule
sudo ufw delete 3
Disabling UFW
sudo ufw disable
Resetting UFW
sudo ufw reset
Setting IP Masquerad
Edit Config
sudo nano /etc/ufw/sysctl.conf
net/ipv4/ip_forward=1
Edit UFW
sudo nano /etc/default/ufw
DEFAULT_FORWARD_POLICY="ACCEPT"
Edit PostRouting
sudo nano /etc/ufw/before.rules
#NAT table rules
*nat
:POSTROUTING ACCEPT [0:0]
# Forward traffic through eth0 - Change to public network interface
-A POSTROUTING -s 10.8.0.0/16 -o eth0 -j MASQUERADE
# don't delete the 'COMMIT' line or these rules won't be processed
COMMIT
Reload service
sudo ufw disable
sudo ufw enable
0 Comments