Generator Firewall Linux UFW, Iptables & Nftables
Generate skrip hardening firewall server Linux untuk UFW, iptables, dan /etc/nftables.conf lengkap dengan proteksi rate-limit SSH dan whitelist subnet.
Parameter Input
Hasil Perhitungan
- Kebijakan Default Trafik Masuk (Inbound)
- DROP
- Antarmuka Jaringan WAN
- eth0
- Port Layanan SSH
- 22
- Jumlah Aturan Port Aktif
- 4 Aturan
- Ringkasan Port Layanan Terbuka
- 22/tcp, 80/tcp, 443/tcp, 51820/udp
- Evaluasi Keamanan Firewall (ID)
- Tinggi (Zero-Trust Default DROP + Rate-Limit Anti-BruteForce SSH Aktif)
Uji aturan firewall dan skrip cron pada lingkungan staging terlebih dahulu, dan simpan backup konfigurasi di Git.
| Nama Layanan | Port / Protokol | Sumber Alamat IP (Source) | Tindakan Filter (Action) |
|---|---|---|---|
| SSH Remote Admin | 22/tcp | 0.0.0.0/0 (Any) | LIMIT (Anti-BruteForce) |
| HTTP Web Server | 80/tcp | 0.0.0.0/0 (Any) | ALLOW |
| HTTPS TLS Web Server | 443/tcp | 0.0.0.0/0 (Any) | ALLOW |
| WireGuard VPN Tunnel | 51820/udp | 0.0.0.0/0 (Any) | ALLOW |
# === UFW (Uncomplicated Firewall) Configuration === sudo ufw --force reset sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw limit 22/tcp comment 'SSH with brute-force rate limit' sudo ufw allow 80/tcp comment 'HTTP Web' sudo ufw allow 443/tcp comment 'HTTPS TLS Web' sudo ufw allow 51820/udp comment 'WireGuard VPN' sudo ufw --force enable sudo ufw status verbose
#!/usr/bin/env bash # === Linux iptables Stateful Firewall Rules (eth0) === iptables -F iptables -X iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT ACCEPT # Allow loopback and established/related connections iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT iptables -A INPUT -m conntrack --ctstate INVALID -j DROP iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 5/sec --limit-burst 10 -j ACCEPT # SSH (22/tcp) with brute-force protection (max 6 connections / 60s) iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -m recent --set --name SSH_BRUTE iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 6 --name SSH_BRUTE -j DROP iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT iptables -A INPUT -p tcp -m multiport --dports 80,443 -m conntrack --ctstate NEW -j ACCEPT iptables -A INPUT -p udp --dport 51820 -j ACCEPT
#!/usr/sbin/nft -f
# === Modern Linux nftables Configuration (/etc/nftables.conf) ===
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
iif "lo" accept
ct state established,related accept
ct state invalid drop
ip protocol icmp icmp type echo-request limit rate 5/second accept
ip6 nexthdr icmpv6 accept
tcp dport 22 ct state new limit rate 6/minute burst 10 packets accept
tcp dport { 80, 443 } ct state new accept
udp dport 51820 accept
}
chain forward {
type filter hook forward priority 0; policy drop;
}
chain output {
type filter hook output priority 0; policy accept;
}
}Multi-Vendor Config Translator & Visualisasi Alur Paket (Packet Flow)
# MikroTik RouterOS v7 — Equivalent Input/Forward Hardening Filter /ip firewall address-list add list=TRUSTED_MGMT address=10.10.10.0/24 /ip firewall filter add chain=input connection-state=established,related,untracked action=accept add chain=input connection-state=invalid action=drop add chain=input src-address-list=TRUSTED_MGMT action=accept comment="Allow Management Subnet" add chain=input protocol=tcp dst-port=22 connection-state=new src-address-list=SSH_STAGE2 action=add-src-to-address-list address-list=SSH_BLACKLIST address-list-timeout=1d add chain=input protocol=tcp dst-port=22 src-address-list=!SSH_BLACKLIST action=accept comment="Rate-Limited SSH" add chain=input protocol=tcp dst-port=80,443 action=accept comment="Allow HTTP/HTTPS" add chain=input in-interface-list=!LAN action=drop comment="Default Drop Input"
Cara Menggunakan Alat Ini
- Pilih kebijakan default trafik masuk (disarankan DROP), tentukan nama antarmuka WAN, port SSH kustom, dan aktifkan proteksi rate-limit SSH.
- Centang layanan publik dan manajemen yang ingin dibuka (HTTP/HTTPS, WireGuard, Proxmox, atau port database dengan pembatasan subnet tepercaya).
- Salin skrip konfigurasi UFW, iptables, atau blok /etc/nftables.conf yang dihasilkan dan jalankan pada terminal server melalui sesi konsol yang aman.
Contoh Perhitungan Nyata: Server Web Produksi + WireGuard VPN (SSH Port 2222)
Contoh terhitung: Kebijakan default DROP pada eth0 dengan port SSH 2222 (rate-limit aktif), HTTP 80, HTTPS 443, dan WireGuard 51820/udp menghasilkan 5 aturan eksplisit dan menghemat eksposur port manajemen.
- Kebijakan Default Inbound (Input)
- DROP (Silent Drop — Rekomendasi Server Produksi)
- Nama Interface Jaringan WAN
- eth0
- Port TCP SSH Server
- 2222
- Aktifkan Proteksi Brute-Force Rate-Limit pada SSH
- Ya / Aktif
- Izinkan HTTP Web Server (Port 80/TCP)
- Ya / Aktif
- Izinkan HTTPS TLS Web Server (Port 443/TCP)
- Ya / Aktif
- Izinkan Tunnel VPN WireGuard (UDP)
- Ya / Aktif
- Port UDP WireGuard
- 51820
- Izinkan Web GUI Proxmox VE (Port 8006/TCP dari Subnet Tepercaya)
- Tidak / Nonaktif
- Izinkan Database MySQL/PostgreSQL (3306 & 5432 dari Subnet Tepercaya)
- Tidak / Nonaktif
- Subnet Manajemen Tepercaya (CIDR)
- 10.10.10.0/24
- Izinkan Diagnostik ICMP Echo Request (Ping)
- Ya / Aktif
- Kebijakan Default Trafik Masuk (Inbound)
- DROP
- Antarmuka Jaringan WAN
- eth0
- Port Layanan SSH
- 2222
- Jumlah Aturan Port Aktif
- 4 Aturan
- Ringkasan Port Layanan Terbuka
- 2222/tcp, 80/tcp, 443/tcp, 51820/udp
- Evaluasi Keamanan Firewall (ID)
- Tinggi (Zero-Trust Default DROP + Rate-Limit Anti-BruteForce SSH Aktif)
- Skrip Perintah UFW (Ubuntu / Debian)
- # === UFW (Uncomplicated Firewall) Configuration === sudo ufw --force reset sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw limit 2222/tcp comment 'SSH with brute-force rate limit' sudo ufw allow 80/tcp comment 'HTTP Web' sudo ufw allow 443/tcp comment 'HTTPS TLS Web' sudo ufw allow 51820/udp comment 'WireGuard VPN' sudo ufw --force enable sudo ufw status verbose
- Skrip Aturan Linux Iptables
- #!/usr/bin/env bash # === Linux iptables Stateful Firewall Rules (eth0) === iptables -F iptables -X iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT ACCEPT # Allow loopback and established/related connections iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT iptables -A INPUT -m conntrack --ctstate INVALID -j DROP iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 5/sec --limit-burst 10 -j ACCEPT # SSH (2222/tcp) with brute-force protection (max 6 connections / 60s) iptables -A INPUT -p tcp --dport 2222 -m conntrack --ctstate NEW -m recent --set --name SSH_BRUTE iptables -A INPUT -p tcp --dport 2222 -m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 6 --name SSH_BRUTE -j DROP iptables -A INPUT -p tcp --dport 2222 -m conntrack --ctstate NEW -j ACCEPT iptables -A INPUT -p tcp -m multiport --dports 80,443 -m conntrack --ctstate NEW -j ACCEPT iptables -A INPUT -p udp --dport 51820 -j ACCEPT
- Konfigurasi Modern Nftables (/etc/nftables.conf)
- #!/usr/sbin/nft -f # === Modern Linux nftables Configuration (/etc/nftables.conf) === flush ruleset table inet filter { chain input { type filter hook input priority 0; policy drop; iif "lo" accept ct state established,related accept ct state invalid drop ip protocol icmp icmp type echo-request limit rate 5/second accept ip6 nexthdr icmpv6 accept tcp dport 2222 ct state new limit rate 6/minute burst 10 packets accept tcp dport { 80, 443 } ct state new accept udp dport 51820 accept } chain forward { type filter hook forward priority 0; policy drop; } chain output { type filter hook output priority 0; policy accept; } }
| Nama Layanan | Port / Protokol | Sumber Alamat IP (Source) | Tindakan Filter (Action) |
|---|---|---|---|
| SSH Remote Admin | 2222/tcp | 0.0.0.0/0 (Any) | LIMIT (Anti-BruteForce) |
| HTTP Web Server | 80/tcp | 0.0.0.0/0 (Any) | ALLOW |
| HTTPS TLS Web Server | 443/tcp | 0.0.0.0/0 (Any) | ALLOW |
| WireGuard VPN Tunnel | 51820/udp | 0.0.0.0/0 (Any) | ALLOW |
Konsep Dasar & Catatan Teknis
Cara Perhitungan (Rumus & Langkah)
Rumus Matematika
- Prinsip Stateful Firewall: Izinkan ct state { established, related }, buang ct state invalid, dan terapkan kebijakan default DROP pada rantai INPUT.
- Rate-Limit SSH: Batasi koneksi SYN baru maksimal 6 percobaan per 30–60 detik per alamat IP sumber.
- Isolasi Port Manajemen & Database: Batasi akses port 8006, 3306, dan 5432 hanya dari blok CIDR manajemen tepercaya.
Langkah Substitusi
- 1. Kebijakan Default Inbound: DROP pada interface eth0 dengan pelacakan status koneksi stateful (ESTABLISHED, RELATED).
- 2. Proteksi Port Manajemen SSH: Port 22/tcp dilindungi dengan pembatasan laju (rate-limiting maksimal 6 koneksi baru per 60 detik).
- 3. Total Port Layanan Terbuka: 4 port (22/tcp, 80/tcp, 443/tcp, 51820/udp).
- 4. Menghasilkan aturan ekuivalen untuk UFW (Ubuntu/Debian), iptables klasik, dan nftables modern (Kernel Linux 5.x/6.x).
Pertanyaan yang Sering Diajukan (FAQ)
Apa perbedaan utama antara iptables dan nftables di Linux modern?
Nftables menggabungkan aturan IPv4 dan IPv6 ke dalam satu tabel 'inet', memproses pembaruan aturan secara atomik, dan mengevaluasi daftar port/IP jauh lebih efisien dibandingkan evaluasi sekuensial pada iptables.
Mengapa aturan izin SSH harus ditambahkan sebelum mengaktifkan ufw enable?
Jika kebijakan default diubah ke DROP atau ufw diaktifkan sebelum port SSH diizinkan, koneksi manajemen jarak jauh dapat terputus ketika sesi baru dibuka.
Bagaimana cara kerja ufw limit pada port SSH?
Perintah ufw limit menolak koneksi baru dari sebuah alamat IP apabila alamat tersebut mencoba melakukan 6 atau lebih inisiasi koneksi dalam kurun waktu 30 detik.
Apakah Docker memodifikasi aturan iptables/ufw secara langsung?
Ya. Daemon Docker menyisipkan aturan pada rantai PREROUTING dan DOCKER-USER. Untuk membatasi port container yang dipublikasikan (-p), tambahkan aturan filter pada rantai DOCKER-USER atau ikat container ke 127.0.0.1.
Alat Kalkulator Terkait
Lihat Semua Kalkulator Linux & DevOps →Konversi izin file Linux chmod oktal (755, 644, 4750) dan simbolik (-rwxr-xr-x), kalkulasi umask, analisis keamanan 777, dan tabel hak akses.
Generator ekspresi cron POSIX 5 kolom, baris crontab siap pakai, jadwal 5 eksekusi berikutnya, dan konversi unit systemd timer.
Hitung ukuran swap optimal Linux, parameter sysctl vm.swappiness, vm.vfs_cache_pressure, estimasi jumlah inode ext4, dan generator skrip /swapfile.
Rencanakan jadwal jendela maintenance server lintas zona waktu WIB, WITA, WIT, SGT, dan UTC dengan deteksi benturan cron backup otomatis.
Referensi Standar & Catatan
- Netfilter Project Official Documentation — nftables & iptables Architecture
- Ubuntu Server Security Documentation — Uncomplicated Firewall (UFW)
Catatan: Hasil di atas merupakan estimasi berdasarkan rumus standar. Selalu verifikasi dengan dokumentasi resmi vendor dan kondisi lapangan sebelum implementasi pada lingkungan produksi.