Tujuan Pembelajaran
Setelah menyelesaikan praktikum ini, mahasiswa mampu:
- Memahami konsep dan implementasi firewall menggunakan iptables dan UFW
- Mengkonfigurasi enkripsi data dengan GPG dan SSL/TLS
- Melakukan hardening sistem dengan konfigurasi keamanan yang tepat
- Mengimplementasikan VPN dasar menggunakan OpenVPN
- Melakukan monitoring dan analisis traffic jaringan
Teori Pendukung
Packet Filtering
Menyaring paket berdasarkan rules tertentu (source/destination IP, port, protocol)
Stateful Inspection
Melacak status koneksi jaringan untuk memutuskan apakah paket diperbolehkan
Network Address Translation (NAT)
Menyembunyikan jaringan internal dari jaringan eksternal
Symmetric Encryption
Kunci sama untuk enkripsi dan dekripsi (AES, DES, 3DES)
Asymmetric Encryption
Kunci publik dan privat berbeda (RSA, DSA, ECC)
Digital Certificate
Verifikasi identitas menggunakan Certificate Authority (CA)
Jenis Firewall di Linux
| Tool |
Kelebihan |
Kekurangan |
Use Case |
| iptables |
Sangat fleksibel, powerful |
Konfigurasi kompleks |
Server produksi, network gateway |
| UFW |
User-friendly, mudah digunakan |
Fitur terbatas |
Desktop, server sederhana |
| firewalld |
Dynamic, zone-based |
Hanya di RHEL/CentOS |
Enterprise environment |
| nftables |
Modern, menggantikan iptables |
Belum banyak digunakan |
System modern |
Konfigurasi Firewall dengan iptables
1. Basic iptables Concepts
filter
nat
mangle
raw
INPUT
OUTPUT
FORWARD
2. Reset dan Setup Policy Default
sudo iptables -F
sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT
3. Allow Traffic Necessary
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A OUTPUT -o lo -j ACCEPT
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 2222 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -p udp --dport 53 -j ACCEPT
4. Implementasi NAT dan Port Forwarding
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
sudo iptables -t nat -A POSTROUTING -o ens33 -j MASQUERADE
sudo iptables -A FORWARD -i ens33 -o ens33 -j ACCEPT
sudo iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80
5. Save iptables Rules
sudo apt install iptables-persistent -y
sudo netfilter-persistent save
sudo netfilter-persistent reload
Konfigurasi UFW (Uncomplicated Firewall)
1. Install dan Setup UFW
sudo apt install ufw -y
sudo ufw disable
sudo ufw --force reset
2. Konfigurasi Basic Rules
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 2222/tcp comment 'SSH Custom Port'
sudo ufw allow 80/tcp comment 'HTTP'
sudo ufw allow 443/tcp comment 'HTTPS'
sudo ufw allow 53/udp comment 'DNS'
sudo ufw --force enable
3. Advanced UFW Configuration
sudo ufw limit 2222/tcp
sudo ufw allow from 192.168.200.20 to any port 22
sudo ufw deny from 192.168.200.100
sudo ufw allow from 192.168.100.0/24
4. Monitoring UFW
sudo ufw status verbose
sudo ufw show added
sudo tail -f /var/log/ufw.log
sudo ufw status numbered
Implementasi Enkripsi dengan GPG
1. Generate GPG Key Pair
gpg --full-generate-key
gpg --batch --generate-key << EOF
Key-Type: RSA
Key-Length: 4096
Subkey-Type: RSA
Subkey-Length: 4096
Name-Real: Admin Sistem
Name-Email: admin@company.local
Expire-Date: 1y
%commit
EOF
2. Manage Keys
gpg --list-keys
gpg --list-secret-keys
gpg --armor --export admin@company.local > public.key
gpg --import public.key
gpg --delete-secret-keys admin@company.local
gpg --delete-keys admin@company.local
3. Enkripsi dan Dekripsi File
echo "Data sensitif perusahaan" > confidential.txt
gpg --encrypt --recipient admin@company.local confidential.txt
gpg --decrypt confidential.txt.gpg > decrypted.txt
gpg --clearsign confidential.txt
gpg --verify confidential.txt.asc
4. GPG untuk Email dan Backup
tar -czf - /important/data | gpg --encrypt --recipient admin@company.local > backup.tar.gz.gpg
gpg --decrypt backup.tar.gz.gpg | tar -xzf -
Konfigurasi SSL/TLS dengan OpenSSL
1. Generate Certificate Authority (CA)
sudo mkdir /etc/ssl/ca
cd /etc/ssl/ca
sudo openssl genrsa -out ca.key 4096
sudo openssl req -new -x509 -days 3650 -key ca.key -out ca.crt \
-subj "/C=ID/ST=West Sumatra/L=Padang/O=Techninovate/CN=Techninovate CA"
2. Generate Server Certificate
sudo openssl genrsa -out server.key 2048
sudo openssl req -new -key server.key -out server.csr \
-subj "/C=ID/ST=West Sumatra/L=Padang/O=Techninovate/CN=firewall-server.local"
sudo openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key \
-CAcreateserial -out server.crt
3. Verify Certificates
sudo openssl verify -CAfile ca.crt server.crt
sudo openssl x509 -in server.crt -text -noout
sudo openssl rsa -in server.key -check -noout
4. Implementasi di Web Server
sudo cp server.crt /etc/ssl/certs/
sudo cp server.key /etc/ssl/private/
sudo chmod 600 /etc/ssl/private/server.key
sudo cp server.crt /etc/nginx/ssl/
sudo cp server.key /etc/nginx/ssl/
sudo chmod 600 /etc/nginx/ssl/server.key
Implementasi VPN dengan OpenVPN
1. Install OpenVPN
sudo apt update
sudo apt install openvpn easy-rsa -y
2. Setup PKI (Public Key Infrastructure)
sudo cp -r /usr/share/easy-rsa/ /etc/openvpn/
cd /etc/openvpn/easy-rsa
sudo ./easyrsa init-pki
sudo ./easyrsa build-ca nopass
sudo ./easyrsa gen-req server nopass
sudo ./easyrsa sign-req server server
sudo ./easyrsa gen-dh
3. Generate Client Certificates
sudo ./easyrsa gen-req client1 nopass
sudo ./easyrsa sign-req client client1
sudo openvpn --genkey --secret pki/ta.key
4. Konfigurasi OpenVPN Server
sudo nano /etc/openvpn/server.conf
port 1194
proto udp
dev tun
ca /etc/openvpn/easy-rsa/pki/ca.crt
cert /etc/openvpn/easy-rsa/pki/issued/server.crt
key /etc/openvpn/easy-rsa/pki/private/server.key
dh /etc/openvpn/easy-rsa/pki/dh.pem
server 10.8.0.0 255.255.255.0
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
keepalive 10 120
cipher AES-256-CBC
user nobody
group nogroup
persist-key
persist-tun
status /var/log/openvpn-status.log
verb 3
5. Start OpenVPN Service
sudo systemctl start openvpn@server
sudo systemctl enable openvpn@server
sudo systemctl status openvpn@server
Monitoring dan Analisis Keamanan
1. Monitor Network Traffic
sudo apt install tshark -y
sudo tshark -i ens33 -f "tcp port 80" -V
sudo tshark -i ens33 -Y "http.request" -T fields -e http.host -e http.request.uri
2. Analyze Firewall Logs
sudo tail -f /var/log/ufw.log
sudo grep -i "drop" /var/log/kern.log
sudo journalctl -u ufw --since "1 hour ago"
3. Check for Suspicious Activities
sudo grep "Failed password" /var/log/auth.log
sudo grep "authentication failure" /var/log/auth.log
sudo netstat -tulnp | grep LISTEN
sudo ss -tulnp
sudo lsof -i
sudo ps aux | grep -E "(ssh|ftp|telnet)"
4. Security Scanning dengan Nmap
sudo apt install nmap -y
nmap -sS -sV -O 192.168.200.10
nmap -p- --min-rate 1000 192.168.200.10
nmap --script vuln 192.168.200.10
Tugas dan Evaluasi
- Jelaskan perbedaan antara firewall stateful dan stateless!
- Apa keuntungan menggunakan UFW dibandingkan iptables langsung?
- Kapan sebaiknya menggunakan enkripsi symmetric dan asymmetric?
- Bagaimana cara memverifikasi bahwa koneksi VPN berjalan dengan aman?
- Buat skenario: Perusahaan membutuhkan firewall yang membatasi akses SSH hanya dari IP tertentu, serta enkripsi untuk data sensitif. Tulis konfigurasi lengkapnya!
Security Best Practices
- Default deny all incoming traffic
- Hanya buka port yang diperlukan
- Gunakan rate limiting untuk SSH
- Implementasi geolocation blocking jika perlu
- Regular audit firewall rules
- Gunakan application-level filtering
- Gunakan strong encryption algorithms (AES-256)
- Rotate keys secara berkala
- Secure key storage dengan permissions yang tepat
- Gunakan certificate expiration
- Implementasi perfect forward secrecy
- Audit encryption strength secara berkala
Case Study: E-commerce Security
echo "Implementing security measures for e-commerce server..."
ufw enable
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp comment 'SSH'
ufw allow 80/tcp comment 'HTTP'
ufw allow 443/tcp comment 'HTTPS'
ufw allow 25/tcp comment 'SMTP'
ufw allow 465/tcp comment 'SMTPS'
ufw allow 993/tcp comment 'IMAPS'
ufw limit 22/tcp
ufw logging on
apt install fail2ban -y
systemctl enable fail2ban
systemctl start fail2ban
apt install certbot python3-certbot-nginx -y
certbot --nginx -d example.com -d www.example.com
echo "Security implementation completed!"