Configuración del firewall de Linux con nftables
Controle el tráfico entrante y saliente de un host Linux mediante nftables y la interfaz simplificada ufw para proteger sus servicios de red.
Configuración del firewall de Linux con nftables es una lección gratuita de Linux Networking & TCP/IP for Developers en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Linux Networking & TCP/IP for Developers, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Linux Networking & TCP/IP for Developers incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en 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.
Aprende Linux Networking & TCP/IP for Developers con un tutor de IA — gratis
Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.
- Cursos
- 12
- Lecciones
- 48
Preguntas frecuentes
¿La lección «Configuración del firewall de Linux con nftables» es gratis?
Sí — el texto completo de «Configuración del firewall de Linux con nftables» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Linux Networking & TCP/IP for Developers, actualiza a CoddyKit PRO. El curso de Linux Networking & TCP/IP for Developers incluye 4 lecciones en total.
¿Qué aprenderé en «Configuración del firewall de Linux con nftables»?
Controle el tráfico entrante y saliente de un host Linux mediante nftables y la interfaz simplificada ufw para proteger sus servicios de red. Practicas Linux Networking & TCP/IP for Developers con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Linux Networking & TCP/IP for Developers?
No se requiere experiencia previa. Linux Networking & TCP/IP for Developers en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Configuración del firewall de Linux con nftables»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Linux Networking & TCP/IP for Developers?
Sí. Cada lección de Linux Networking & TCP/IP for Developers incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Gestión de interfaces de red
- Tablas de enrutamiento y gateways
- Configuración y resolución de DNS
- Configuración del firewall de Linux con nftables