Buyukweb
VDS Sunucuda Firewall Yapılandırması: iptables Rehberi

VDS Sunucuda Firewall Yapılandırması: iptables Rehberi

VDS sunucunuzu iptables ile güvence altına alın. Temel kurallar, NAT yapılandırması, saldırı önleme ve UFW alternatifi.

Büyükweb Teknik Ekibi31 Ekim 20257 dakika okuma

VDS Sunucuda Firewall Yapılandırması: iptables Rehberi

Sunucunuz internete açık bir hizmet çalıştırıyorsa, firewall yapılandırması güvenliğin temelidir. iptables, Linux çekirdeğine entegre güçlü bir paket filtreleme aracıdır. Bu rehberde iptables'ın temellerini ve pratik konfigürasyonları öğreneceksiniz.


iptables Temel Kavramları

Tablolar ve Chain'ler

iptables üç ana tablo üzerinde çalışır:

Tablo Açıklama
filter Paket kabul/red kararları (varsayılan)
nat Ağ adresi çevirisi (NAT/port forwarding)
mangle Paket başlık değiştirme

Her tabloda chain (zincir) bulunur:

  • INPUT: Sunucuya gelen paketler
  • OUTPUT: Sunucudan çıkan paketler
  • FORWARD: İletilen paketler (router görevi)

Politikalar

# Mevcut kuralları listele
iptables -L -v -n --line-numbers

# Belirli zincir
iptables -L INPUT -v -n

Güvenli Varsayılan Firewall Yapılandırması

#!/bin/bash
# /opt/firewall.sh - Temel güvenli firewall scripti

# Mevcut kuralları temizle
iptables -F
iptables -X
iptables -Z

# Varsayılan politikalar: her şeyi engelle
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

# ----------------
# TEMEL İZİNLER
# ----------------

# Loopback (localhost) trafiğine izin ver
iptables -A INPUT -i lo -j ACCEPT

# Mevcut bağlantıları kabul et (established/related)
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

# ICMP (ping) - rate limiting ile
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/second --limit-burst 3 -j ACCEPT

# ----------------
# SSH ERİŞİMİ
# ----------------

# SSH - Brute force koruması (dakikada 4 deneme)
iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -m recent --set
iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 4 -j DROP
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

# ----------------
# WEB SERVİSLERİ
# ----------------

# HTTP ve HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

# ----------------
# VERİTABANLARI (sadece yerel ağ)
# ----------------

# MySQL/MariaDB - Sadece localhost
iptables -A INPUT -p tcp --dport 3306 -s 127.0.0.1 -j ACCEPT

# PostgreSQL - Sadece localhost
iptables -A INPUT -p tcp --dport 5432 -s 127.0.0.1 -j ACCEPT

# ----------------
# DDoS KORUMALARI
# ----------------

# SYN flood koruması
iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 3 -j ACCEPT
iptables -A INPUT -p tcp --syn -j DROP

# Port scan koruması
iptables -A INPUT -m recent --name portscan --rcheck --seconds 86400 -j DROP
iptables -A FORWARD -m recent --name portscan --rcheck --seconds 86400 -j DROP
iptables -A INPUT -m recent --name portscan --remove
iptables -A FORWARD -m recent --name portscan --remove
iptables -A INPUT -p tcp -m tcp --dport 139 -m recent --name portscan --set -j DROP

# ----------------
# KARA LİSTE
# ----------------

# Belirli IP'leri engelle
# iptables -A INPUT -s 1.2.3.4 -j DROP
# iptables -A INPUT -s 192.168.1.0/24 -j DROP

echo "Firewall kuralları uygulandı."
iptables -L -n --line-numbers
chmod +x /opt/firewall.sh
bash /opt/firewall.sh

Kuralları Kalıcı Hale Getirme

Ubuntu/Debian ile iptables-persistent

# iptables-persistent kur
apt install -y iptables-persistent

# Mevcut kuralları kaydet
netfilter-persistent save

# Yeniden yükleme
netfilter-persistent reload

Systemd ile Manuel Kayıt

# Kuralları dışa aktar
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6

# Yükleme servisi oluştur
cat > /etc/systemd/system/iptables-restore.service << 'EOF'
[Unit]
Description=Restore iptables rules
Before=network.target

[Service]
Type=oneshot
ExecStart=/sbin/iptables-restore /etc/iptables/rules.v4
ExecStart=/sbin/ip6tables-restore /etc/iptables/rules.v6
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF

systemctl enable iptables-restore

NAT ve Port Forwarding

# IP forwarding aktifleştir
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p

# Masquerade (internet paylaşımı)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

# Port forwarding: dışarıdan 8080 → yerel 80
iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80

# Farklı sunucuya yönlendirme
iptables -t nat -A PREROUTING -p tcp --dport 3000 -j DNAT --to-destination 10.0.0.2:3000
iptables -A FORWARD -p tcp -d 10.0.0.2 --dport 3000 -j ACCEPT

UFW: Daha Kolay Firewall Yönetimi

UFW (Uncomplicated Firewall), iptables üzerinde çalışan kolay arayüzdür:

# UFW kur ve aktifleştir
apt install -y ufw
ufw default deny incoming
ufw default allow outgoing

# Temel izinler
ufw allow ssh
ufw allow 80/tcp
ufw allow 443/tcp

# Belirli IP'den erişim
ufw allow from 203.0.113.0/24 to any port 22

# UFW'yi etkinleştir
ufw enable

# Durum kontrol
ufw status verbose

fail2ban ile Brute Force Koruması

# fail2ban kur
apt install -y fail2ban

# Konfigürasyon
cat > /etc/fail2ban/jail.local << 'EOF'
[DEFAULT]
bantime  = 3600
findtime = 600
maxretry = 5
ignoreip = 127.0.0.1/8

[sshd]
enabled  = true
port     = 22
filter   = sshd
logpath  = /var/log/auth.log
maxretry = 3
bantime  = 86400

[nginx-http-auth]
enabled  = true
port     = http,https
filter   = nginx-http-auth
logpath  = /var/log/nginx/error.log
maxretry = 3
EOF

systemctl restart fail2ban
systemctl enable fail2ban

# Yasaklı IP'leri görüntüle
fail2ban-client status sshd

Sık Kullanılan iptables Komutları

# Tüm kuralları listele (numaralarla)
iptables -L -v -n --line-numbers

# Belirli satırı sil (INPUT zincirinin 5. kuralı)
iptables -D INPUT 5

# Kural ekle (en başa)
iptables -I INPUT 1 -s 1.2.3.4 -j DROP

# Kuralları sıfırla
iptables -F
iptables -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

Buyukweb VDS ile Güvenlik

Buyukweb E5v4 VDS ve E5v2 VDS sunucularında donanım düzeyinde DDoS koruması mevcuttur. Ancak uygulama düzeyinde iptables yapılandırması her zaman önerilir.


Sonuç

iptables, Linux sunucuların güvenliğinin temelidir. Temel kuralları doğru yapılandırdıktan sonra fail2ban ve UFW gibi araçlarla yönetimi kolaylaştırabilirsiniz. SSH portunu her zaman açık tutmayı unutmayın - aksi hâlde sunucunuza erişiminizi kaybedebilirsiniz.


Ilgili Buyukweb Hizmetleri:


VDS Performans Optimizasyonu

VDS sunucunuzdan maksimum verimi almak icin asagidaki optimizasyonlari uygulayin.

Kernel Parametreleri

sysctl ile TCP buffer boyutlari, dosya tanimlayici limitleri ve bellek yonetimi ayarlarini optimize edin. net.core.somaxconn degerini artirarak yuksek trafik altinda daha iyi performans elde edin.

Disk I/O Optimizasyonu

NVMe SSD diskler SATA SSD'lere kiyasla 5-6 kat daha yuksek IOPS sunar. noatime mount secenegi ile gereksiz disk yazma islemlerini azaltin. I/O scheduler olarak mq-deadline kullanin.

Bellek Yonetimi

Swappiness degerini 10'a dusurerek RAM kullanımını optimize edin. OOM Killer ayarlarini yapilandirarak kritik servislerin korunmasini garantileyin.

Web Sunucu Tuning

Nginx worker_processes ve worker_connections degerlerini optimize edin. Brotli sikistirma etkinlestirin. Fastcgi cache ile PHP uygulamalarini hizlandirin.

Yedekleme Stratejisi

rsync, borgbackup veya restic ile sifrelenmis yedekler olusturun. 3-2-1 kuralini uygulayin. KVM snapshot ile anlik geri donme noktasi olusturun.

Sik Sorulan Sorular

VDS ne kadar surede kurulur?

Buyukweb VDS sunuculari otomatik provisioning ile dakikalar icerisinde kurulur.

VDS sunucuma nasil erisirim?

Linux icin SSH (port 22), Windows icin RDP (port 3389) kullanin.

Sonuc

VDS performans optimizasyonu, teknik bilgi gerektiren ama sonuclari tatmin edici bir surectir. Sunucunuzun potansiyelini tam kullanin.

VDS Sunucu Ilk Kurulum Kontrol Listesi

Yeni bir VDS sunucu aldiktan sonra yapmaniz gereken ilk islemler:

1. Sistem Guncellemesi

Isletim sistemini ve tum paketleri guncelleyin. Bu bilinen guvenlik aciklarini kapatir.

2. Yeni Kullanici Olusturma

Root disinda yonetici kullanici olusturun ve sudo yetkisi verin.

3. SSH Guvenligi

SSH portunu degistirin, parola ile girisi kapatin, anahtar tabanli dogrulamaya gecin. fail2ban kurun.

4. Guvenlik Duvari

UFW veya firewalld ile sadece gerekli portlari acin.

5. Zaman Senkronizasyonu

NTP ile sunucu saatini senkronize edin.

6. Yedekleme Ayarlari

Otomatik yedekleme yapilandirin. Uzak sunucuya yedek gondermeyi unutmayin.

7. Monitoring

Netdata veya benzeri izleme araci kurun. Alarm esiklerini tanimlayin.

E5-V4 vs E5-V2 Performans Farki

E5-V4 islemciler E5-V2'ye kiyasla:

  • %30-40 daha yuksek tek cekirdek performansi
  • DDR4 RAM destegi (DDR3'e kiyasla %50 daha yuksek bant genisligi)
  • Gelismis AVX2 komut seti destegi
  • Daha dusuk guc tuketimi

Uretim ortamlari ve yuksek performans gerektiren uygulamalar icin E5-V4 kesinlikle oneriyoruz.

Etiketler:

#VDS#Firewall#iptables#UFW#fail2ban#Güvenlik#Linux

Bu yazıyı paylaş