Configurando o firewall do Linux com nftables
Controle o tráfego de entrada e saída em um host Linux usando nftables e a interface simplificada ufw para proteger seus serviços de rede.
Configurando o firewall do Linux com nftables é uma aula grátis de Linux Networking & TCP/IP for Developers no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Linux Networking & TCP/IP for Developers, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Linux Networking & TCP/IP for Developers inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Why a Host Firewall?
A host firewall decides which packets are allowed in or out of a single machine. It is your last line of defense, protecting services even when the network perimeter is breached.
From iptables to nftables
Modern Linux uses nftables as the kernel packet-filtering framework, replacing the older iptables. It uses tables, chains, and rules but with a cleaner, unified syntax.
Tables, Chains, and Rules
In nftables a table holds chains, a chain holds ordered rules, and each rule matches packets and takes an action like accept or drop. Chains hook into traffic at points such as input and output.
Listing the Ruleset
See the entire active configuration with a single command. This is always your first step before changing anything.
sudo nft list rulesetA Simple Input Policy
Create a table and an input chain with a default drop policy, then allow only what you need. Default-deny is the secure baseline.
sudo nft add table inet filter
sudo nft add chain inet filter input { type filter hook input priority 0 \; policy drop \; }Allowing SSH
Add a rule to accept incoming TCP on port 22 so you do not lock yourself out before allowing anything else.
sudo nft add rule inet filter input tcp dport 22 acceptAllowing Established Traffic
Permit replies to connections you initiated by accepting established and related traffic. Without this, outbound requests get no responses.
sudo nft add rule inet filter input ct state established,related acceptThe Easier Way: ufw
For everyday use, ufw (Uncomplicated Firewall) is a friendly front-end. It manages the underlying rules with simple commands.
sudo ufw allow 22/tcp
sudo ufw enableChecking ufw Status
Verify which rules ufw has applied and whether it is active.
sudo ufw status verbosePersisting Rules
nftables rules added at the command line vanish on reboot. Save them to /etc/nftables.conf and enable the service so they reload automatically.
sudo nft list ruleset | sudo tee /etc/nftables.conf
sudo systemctl enable nftablesLogging Dropped Packets
Add a logging rule before the final drop so you can see what is being blocked. This is invaluable when a service mysteriously cannot be reached.
sudo nft add rule inet filter input log prefix "dropped: "Quick Check
Test your firewall knowledge.
Recap
You learned to configure the Linux firewall.
- nftables uses tables, chains, and rules with a default-deny baseline.
- Always allow SSH and established traffic before locking down.
- ufw simplifies common rules; persist nftables to survive reboots.
Aprenda Linux Networking & TCP/IP for Developers com um tutor de IA — grátis
Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.
- Cursos
- 12
- Aulas
- 48
Perguntas Frequentes
A aula “Configurando o firewall do Linux com nftables” é grátis?
Sim — o texto completo de “Configurando o firewall do Linux com nftables” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Linux Networking & TCP/IP for Developers, atualize para CoddyKit PRO. O curso de Linux Networking & TCP/IP for Developers inclui 4 aulas no total.
O que vou aprender em “Configurando o firewall do Linux com nftables”?
Controle o tráfego de entrada e saída em um host Linux usando nftables e a interface simplificada ufw para proteger seus serviços de rede. Você pratica Linux Networking & TCP/IP for Developers com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Linux Networking & TCP/IP for Developers?
Nenhuma experiência prévia é necessária. Linux Networking & TCP/IP for Developers no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Configurando o firewall do Linux com nftables”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Linux Networking & TCP/IP for Developers?
Sim. Cada aula de Linux Networking & TCP/IP for Developers inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Gerenciando Interfaces de Rede
- Tabelas de Roteamento e Gateways
- Configuração e Resolução de DNS
- Configurando o firewall do Linux com nftables