Gelişmiş Güvenlik Duvarı Kuralları (nftables)
Daha esnek ve güçlü paket filtreleme ile ağ adresi çevirisi için `iptables` kullanımının ötesine geçerek `nftables` öğrenin.
Gelişmiş Güvenlik Duvarı Kuralları (nftables), CoddyKit'te ücretsiz bir Linux Networking & TCP/IP for Developers dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Linux Networking & TCP/IP for Developers öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Linux Networking & TCP/IP for Developers kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Meet nftables: The Modern Firewall
Welcome to nftables, the modern packet filtering framework for Linux! It's designed to be more flexible and easier to use than its predecessor, iptables.
While iptables uses separate tools for IPv4, IPv6, and bridging, nftables provides a unified syntax. This means you can manage all your firewall rules with a single command-line utility: nft.
Organizing with Families, Tables, Chains
nftables organizes rules into a clear hierarchy:
- Families: Define the network layer (e.g.,
ipfor IPv4,ip6for IPv6,bridgefor Layer 2,netdevfor Layer 1/2). - Tables: Containers for chains, belonging to a specific family. You can have multiple tables.
- Chains: Sequences of rules that packets are evaluated against. Chains can be "base chains" (entry points for kernel hooks) or "regular chains" (called by other chains).
Listing Existing nftables Rules
To see the current nftables ruleset on your system, you use the nft list ruleset command. If you're just starting, it might be empty or contain default rules.
Let's take a look:
nft list rulesetSetting Up Your First Firewall
Before adding rules, we need a table and a chain. A common practice is to create a table for the ip family (IPv4) and a base chain named input for incoming traffic.
We'll set the default policy for this chain to drop, meaning any packet not explicitly allowed will be discarded. This is a secure "deny by default" approach.
#!/bin/bash
# Add an 'ip' family table named 'filter'
nft add table ip filter
# Add a base chain 'input' to the 'filter' table
# Type 'filter', hook 'input', priority 0, policy 'drop'
nft add chain ip filter input { type filter hook input priority 0 \; policy drop \; }
nft list rulesetAllowing Basic Inbound Traffic
Now that our input chain drops everything by default, we need to add rules to allow necessary traffic. A common first step is to permit inbound SSH connections (port 22) so you can manage your server remotely.
We'll also allow established and related connections to ensure ongoing communication works, which is crucial for most network interactions.
#!/bin/bash
# Allow established and related connections
nft add rule ip filter input ct state established,related accept
# Allow inbound SSH traffic (TCP port 22)
nft add rule ip filter input tcp dport 22 accept
nft list rulesetEnabling Outgoing Connections
Most systems need to initiate outbound connections (e.g., to fetch updates, browse the web). We typically create an output base chain.
For simplicity, let's create an output chain and allow all outgoing IPv4 traffic. In production, you might restrict this more tightly.
#!/bin/bash
# Add a base chain 'output' to the 'filter' table
# Type 'filter', hook 'output', priority 0, policy 'accept'
nft add chain ip filter output { type filter hook output priority 0 \; policy accept \; }
nft list rulesetSource NAT (SNAT) with nftables
Network Address Translation (NAT) allows multiple devices on a private network to share a single public IP address. Source NAT (SNAT) changes the source IP of outgoing packets.
This is commonly used on routers to allow internal clients to access the internet. Here, we set up a basic SNAT rule for traffic going out through eth0, masquerading it with the public IP of eth0.
#!/bin/bash
# Add an 'ip' family table named 'nat'
nft add table ip nat
# Add a base chain 'postrouting' to the 'nat' table
# Type 'nat', hook 'postrouting', priority 100
nft add chain ip nat postrouting { type nat hook postrouting priority 100 \; }
# Add a rule to masquerade (SNAT) traffic leaving 'eth0'
nft add rule ip nat postrouting oifname "eth0" masquerade
nft list rulesetDestination NAT (DNAT) with nftables
Destination NAT (DNAT), also known as port forwarding, changes the destination IP address and/or port of incoming packets. This allows external users to access services on an internal server.
For example, you might forward external port 80 to an internal web server at 192.168.1.5 on port 80. This rule would be placed in the prerouting chain.
#!/bin/bash
# Add a base chain 'prerouting' to the 'nat' table
# Type 'nat', hook 'prerouting', priority -100
nft add chain ip nat prerouting { type nat hook prerouting priority -100 \; }
# Forward external TCP port 80 to internal server 192.168.1.5:80
nft add rule ip nat prerouting tcp dport 80 dnat to 192.168.1.5:80
nft list rulesetSaving Your Firewall Configuration
Rules added with nft directly on the command line are temporary and will be lost after a reboot. To make them permanent, you need to save them to a configuration file.
The standard way is to save the current ruleset to /etc/nftables.conf and ensure the nftables service is enabled to load it on boot. You can then restore them with nft -f /etc/nftables.conf.
#!/bin/bash
# Save the current ruleset to the default configuration file
nft list ruleset > /etc/nftables.conf
echo "Configuration saved to /etc/nftables.conf"
# On a real system, you'd typically also enable the service:
# sudo systemctl enable nftables
# sudo systemctl start nftablesTest Your nftables Knowledge
You've learned about nftables structure and basic rules. Let's test your understanding.
nftables: Modern Firewalling
Great job! You've taken your first steps with nftables, the powerful and flexible successor to iptables.
- You learned about its unified structure using families, tables, and chains.
- You practiced adding basic filter rules for inbound and outbound traffic.
- You explored configuring Source NAT (SNAT) and Destination NAT (DNAT).
- Finally, you understood how to save your rules for persistence across reboots.
Keep experimenting with nftables to secure and manage your Linux network!
Yapay zeka eğitmeniyle Linux Networking & TCP/IP for Developers öğren — ücretsiz
Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.
- Kurslar
- 12
- Dersler
- 48
Sıkça Sorulan Sorular
“Gelişmiş Güvenlik Duvarı Kuralları (nftables)” dersi ücretsiz mi?
Evet — “Gelişmiş Güvenlik Duvarı Kuralları (nftables)” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Linux Networking & TCP/IP for Developers kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Linux Networking & TCP/IP for Developers kursu toplamda 4 dersten oluşur.
“Gelişmiş Güvenlik Duvarı Kuralları (nftables)” dersinde ne öğreneceğim?
Daha esnek ve güçlü paket filtreleme ile ağ adresi çevirisi için `iptables` kullanımının ötesine geçerek `nftables` öğrenin. Linux Networking & TCP/IP for Developers ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Linux Networking & TCP/IP for Developers öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Linux Networking & TCP/IP for Developers, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.
“Gelişmiş Güvenlik Duvarı Kuralları (nftables)” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Linux Networking & TCP/IP for Developers dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Linux Networking & TCP/IP for Developers dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Gelişmiş Güvenlik Duvarı Kuralları (nftables)
- VPN Kavramları ve Yapılandırması
- Ağ Saldırı Tespiti (IDS)
- SSH Güçlendirme ve Anahtar Tabanlı Kimlik Doğrulama