Ana içeriğe geç
Kategoriye Dön

iptables vs nftables: Karşılaştırma ve Geçiş Rehberi

iptables ve nftables karşılaştırması, nftables sözdizimi, geçiş rehberi, yaygın kural eşdeğerleri ve hangi durumda hangisini kullanacağınıza dair kapsamlı rehber.

Okuma süresi: 13 dk Güvenlik
iptablesnftablesfirewalllinuxağ güvenliğipaket filtrelemenetfiltergüvenlik duvarı

İçindekiler

iptables vs nftables: Karşılaştırma ve Geçiş Rehberi

Linux'ta paket filtreleme için uzun yıllar boyunca iptables kullanıldı. Ancak nftables, 2014'ten itibaren Linux çekirdeğine dahil edildi ve modern dağıtımlarda iptables'ın yerini almaya başladı. Bu rehberde iki aracı karşılaştıracak, nftables sözdizimini öğrenecek ve iptables'tan nftables'a geçiş yapacaksınız.

Karşılaştırma Tablosu

Özellikiptablesnftables
İlk sürüm19982014
SözdizimiKarmaşık, tutarsızTutarlı, okunabilir
IPv4/IPv6Ayrı araçlar (iptables/ip6tables)Tek araç
PerformansKural başına değerlendirmeOptimize edilmiş
Atomik güncellemelerHayırEvet
Kural setleriAyrı tablolarBirleşik
Varsayılan (Ubuntu 20.04+)HayırEvet
Varsayılan (Debian 10+)HayırEvet

iptables Temel Kavramlar

hljs bash
# iptables mevcut kuralları görüntüle
sudo iptables -L -n -v
sudo iptables -L -n -v --line-numbers

# Tablolar: filter, nat, mangle, raw
sudo iptables -t nat -L -n -v

# Zincirler: INPUT, OUTPUT, FORWARD, PREROUTING, POSTROUTING

# Temel kurallar
sudo iptables -A INPUT -p tcp --dport 22 -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 -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -P INPUT DROP

# Kuralları kaydet
sudo iptables-save > /etc/iptables/rules.v4
sudo ip6tables-save > /etc/iptables/rules.v6

nftables Temel Kavramlar

nftables'da yapı şöyledir: table → chain → rule

hljs bash
# nftables kurulumu
sudo apt install nftables -y
sudo systemctl enable nftables
sudo systemctl start nftables

# Mevcut kuralları görüntüle
sudo nft list ruleset

# Tüm tabloları listele
sudo nft list tables

# Belirli tabloyu görüntüle
sudo nft list table inet filter

nftables Yapılandırma Dosyası

hljs bash
sudo nano /etc/nftables.conf
#!/usr/sbin/nft -f

# Mevcut kuralları temizle
flush ruleset

# inet ailesi hem IPv4 hem IPv6'yı kapsar
table inet filter {
    chain input {
        type filter hook input priority 0; policy drop;
        
        # Loopback arayüzüne izin ver
        iif lo accept
        
        # Mevcut bağlantılara izin ver
        ct state established,related accept
        
        # ICMP (ping)
        ip protocol icmp accept
        ip6 nexthdr icmpv6 accept
        
        # SSH
        tcp dport 22 accept
        
        # HTTP/HTTPS
        tcp dport { 80, 443 } accept
        
        # Reddet ve logla
        log prefix "nftables-drop: " drop
    }
    
    chain forward {
        type filter hook forward priority 0; policy drop;
    }
    
    chain output {
        type filter hook output priority 0; policy accept;
    }
}
hljs bash
# Yapılandırmayı uygula
sudo nft -f /etc/nftables.conf

# Sözdizimini kontrol et (uygulamadan)
sudo nft -c -f /etc/nftables.conf

Kural Eşdeğerleri

Temel Kurallar

iptablesnftables
iptables -A INPUT -p tcp --dport 22 -j ACCEPTnft add rule inet filter input tcp dport 22 accept
iptables -A INPUT -s 192.168.1.0/24 -j ACCEPTnft add rule inet filter input ip saddr 192.168.1.0/24 accept
iptables -A INPUT -j DROPnft add rule inet filter input drop
iptables -P INPUT DROPtype filter hook input priority 0; policy drop;

NAT Kuralları

hljs bash
# iptables NAT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.1.10:80

# nftables NAT eşdeğeri
table ip nat {
    chain prerouting {
        type nat hook prerouting priority -100;
        
        # Port yönlendirme (DNAT)
        tcp dport 80 dnat to 192.168.1.10:80
        tcp dport 443 dnat to 192.168.1.10:443
    }
    
    chain postrouting {
        type nat hook postrouting priority 100;
        
        # Masquerade (NAT)
        oif eth0 masquerade
    }
}

Rate Limiting

hljs bash
# iptables rate limiting
sudo iptables -A INPUT -p tcp --dport 22 -m limit --limit 3/min --limit-burst 5 -j ACCEPT

# nftables rate limiting
chain input {
    # SSH rate limiting
    tcp dport 22 limit rate 3/minute burst 5 packets accept
    tcp dport 22 drop
    
    # HTTP rate limiting
    tcp dport 80 limit rate 100/second burst 200 packets accept
}

IP Seti Kullanımı

hljs bash
# iptables ipset
sudo apt install ipset -y
sudo ipset create blocked_ips hash:ip
sudo ipset add blocked_ips 1.2.3.4
sudo iptables -A INPUT -m set --match-set blocked_ips src -j DROP

# nftables set (yerleşik)
table inet filter {
    # IP seti tanımla
    set blocked_ips {
        type ipv4_addr
        elements = { 1.2.3.4, 5.6.7.8, 10.0.0.0/8 }
    }
    
    chain input {
        type filter hook input priority 0; policy drop;
        
        # Engellenen IP'leri reddet
        ip saddr @blocked_ips drop
        
        # Diğer kurallar...
        tcp dport 22 accept
    }
}

iptables'tan nftables'a Geçiş

Otomatik Dönüştürme

hljs bash
# iptables-translate aracı ile dönüştür
sudo apt install iptables-nftables-compat -y

# Mevcut iptables kurallarını nftables formatına çevir
iptables-save | iptables-restore-translate -f /etc/nftables.conf

# ip6tables kurallarını da çevir
ip6tables-save | ip6tables-restore-translate >> /etc/nftables.conf

# Oluşturulan dosyayı incele
cat /etc/nftables.conf

Manuel Geçiş Adımları

hljs bash
# 1. Mevcut iptables kurallarını yedekle
sudo iptables-save > /root/iptables-backup.txt
sudo ip6tables-save > /root/ip6tables-backup.txt

# 2. nftables yapılandırmasını oluştur
sudo nano /etc/nftables.conf

# 3. Yapılandırmayı test et
sudo nft -c -f /etc/nftables.conf

# 4. nftables'ı etkinleştir
sudo systemctl enable nftables
sudo nft -f /etc/nftables.conf

# 5. iptables'ı devre dışı bırak
sudo systemctl disable iptables
sudo systemctl stop iptables

# 6. Kuralları doğrula
sudo nft list ruleset

Hangisini Kullanmalısınız?

iptables Kullanın:

  • Eski sistemler (CentOS 7, Ubuntu 18.04)
  • Mevcut iptables scriptleri varsa
  • Ekip iptables'a aşinaysa
  • Üçüncü parti araçlar iptables gerektiriyorsa

nftables Kullanın:

  • Yeni kurulumlar (Ubuntu 20.04+, Debian 10+)
  • IPv4 ve IPv6 birlikte yönetmek istiyorsanız
  • Daha temiz sözdizimi istiyorsanız
  • Atomik kural güncellemeleri gerekiyorsa

Ubuntu 20.04 ve Debian 10'dan itibaren iptables komutu aslında iptables-nft wrapper'ını çalıştırır — yani arka planda nftables kullanır. Gerçek iptables için iptables-legacy kullanın.

Sonuç

nftables, modern Linux sistemlerde iptables'ın yerini almaktadır. Daha tutarlı sözdizimi, IPv4/IPv6 birleşik yönetimi ve daha iyi performans sunar. Yeni kurulumlar için nftables tercih edin; mevcut iptables altyapısı için geçiş planı yapın.