0Pricing
Linux Networking & TCP/IP for Developers · Lección

Firewall de Linux (Netfilter/iptables)

Comprenda los conceptos básicos de los firewalls de Linux mediante `iptables` para filtrar el tráfico y proteger sus sistemas.

Firewall de Linux (Netfilter/iptables) es una lección gratuita de Linux Networking & TCP/IP for Developers en CoddyKit. Esta es la lección 3 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.

Firewalls: Your Network Guardian

What is a firewall? It's like a security guard for your network, controlling what traffic goes in and out. In Linux, the core firewall framework is called Netfilter. We use a command-line tool called iptables to manage its rules.

Netfilter: The Kernel's Core

Netfilter is a powerful framework built right into the Linux kernel. It allows different kernel modules to inspect, modify, and drop network packets.

Think of it as the engine behind the firewall. It provides "hooks" where packet processing can be intercepted.

`iptables`: Managing Firewall Rules

While Netfilter is in the kernel, iptables is the command-line utility you use to interact with it. It lets you define rules that tell Netfilter what to do with specific packets.

These rules are organized into tables and chains, which we'll explore next.

`iptables` Chains: Traffic Paths

iptables organizes rules into chains. These are ordered lists of rules that packets are checked against. The three most common built-in chains are:

  • INPUT: For packets destined for the local system.
  • OUTPUT: For packets originating from the local system.
  • FORWARD: For packets passing through the system (e.g., a router).

Default Actions: Chain Policies

Each chain has a default policy, which is the action taken if no rule in the chain matches a packet. Common policies are:

  • ACCEPT: Let the packet through.
  • DROP: Silently discard the packet (sender gets no response).
  • REJECT: Discard the packet and send an error message back to the sender.

It's common to set default policies to DROP for security.

Viewing Current `iptables` Rules

Before adding rules, it's good to see what's already there. You can list all current iptables rules with the -L option. Adding -n shows IP addresses numerically, and -v adds verbosity.

sudo iptables -L -n -v

Allowing Inbound SSH Traffic

Let's add a rule to allow incoming SSH connections (port 22). We'll append (-A) this rule to the INPUT chain, specifying TCP protocol (-p tcp) and destination port (--dport 22). The action (-j) will be ACCEPT.

sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

Blocking Outbound Ping Requests

Now, let's block all outbound ping requests (ICMP protocol). We'll append this rule to the OUTPUT chain, specifying the ICMP protocol. The action will be DROP.

This means your system won't send ping requests, but might still receive them if not blocked on INPUT.

sudo iptables -A OUTPUT -p icmp -j DROP

Making Rules Permanent

iptables rules are volatile; they disappear on reboot! To make them permanent, you need to save them. On many systems, you'd use iptables-save to export rules and iptables-restore to load them.

Some Linux distributions use specific services (like netfilter-persistent) or files (e.g., /etc/sysconfig/iptables) to manage persistence.

Firewall Chains Check

Based on what you've learned, which iptables chain would typically handle network packets that are trying to reach a service running on your local machine?

Recap: `iptables` Firewall Basics

You've learned about Netfilter, the kernel's firewall framework, and iptables, the user-space tool to manage its rules. We covered the main chains (INPUT, OUTPUT, FORWARD) and policies (ACCEPT, DROP, REJECT).

You also saw how to list, add basic rules, and the importance of saving them for persistence. This is a crucial step in securing any Linux system!

Preguntas frecuentes

¿La lección «Firewall de Linux (Netfilter/iptables)» es gratis?

Sí — el texto completo de «Firewall de Linux (Netfilter/iptables)» 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 «Firewall de Linux (Netfilter/iptables)»?

Comprenda los conceptos básicos de los firewalls de Linux mediante `iptables` para filtrar el tráfico y proteger sus sistemas. 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 3 de 4.

¿Cuánto tiempo toma la lección «Firewall de Linux (Netfilter/iptables)»?

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

  1. Captura de paquetes con Wireshark/tcpdump
  2. Herramientas de rendimiento de red
  3. Firewall de Linux (Netfilter/iptables)
  4. Diagnóstico de DNS con dig y nslookup
← Volver a Linux Networking & TCP/IP for Developers