codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐧

Linux & Bash

22 / 60 topics
20Network Configuration21Remote Access22Firewall Management
Tutorials/Linux & Bash/Firewall Management
🐧Linux & Bash

Firewall Management

Updated 2026-05-15
10 min read

Firewall Management

Introduction

In the realm of Linux and networking, managing firewall rules is a critical task. Firewalls act as gatekeepers for your system, controlling incoming and outgoing network traffic based on predetermined security policies. This tutorial will guide you through configuring firewalls using iptables, one of the most popular tools in the Linux ecosystem.

Concept

Firewall management involves setting up rules that dictate which types of traffic are allowed to pass through your system's network interface. These rules can be based on various criteria such as:

  • Protocol: TCP, UDP, ICMP, etc.
  • Source and Destination IP addresses
  • Port numbers
  • Packet content

By configuring these rules, you can enhance the security of your Linux system by blocking malicious traffic while allowing legitimate connections.

Examples

Basic Configuration with iptables

iptables is a command-line utility used to configure the Linux kernel's packet filtering capabilities. Here are some basic examples to get you started.

1. List Current Rules

To view the current firewall rules, use:

Terminal
Bash
1sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

3. Block All Incoming Traffic

To block all incoming traffic except for established connections and SSH:

Terminal
Bash
1sudo iptables -P INPUT DROP
2sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

4. Save and Restore Rules

To save your iptables rules so they persist after a reboot:

Terminal
Bash
1sudo sh -c "iptables-save > /etc/iptables/rules.v4"
2sudo iptables-restore < /etc/iptables/rules.v4

Advanced Configuration

For more advanced configurations, you can use iptables to create custom chains and rules. Here's an example of setting up a custom chain for HTTP traffic:

Terminal
Terminal
Bash
1sudo iptables -N HTTP_TRAFFIC
2sudo iptables -A INPUT -p tcp --dport 80 -j HTTP_TRAFFIC
3sudo iptables -A HTTP_TRAFFIC -s 192.168.1.0/24 -j ACCEPT
4sudo iptables -A HTTP_TRAFFIC -j DROP

In this example, a custom chain named HTTP_TRAFFIC is created to handle incoming HTTP traffic on port 80. Only traffic from the subnet 192.168.1.0/24 is allowed, and all other traffic is dropped.

What's Next?

Now that you have a basic understanding of firewall management with iptables, you can explore more advanced topics such as:

  • Scripting Basics: Automating firewall rule configurations using scripts.
  • Firewalld: A dynamic firewall daemon for Linux systems.
  • UFW (Uncomplicated Firewall): A simpler interface for managing firewall rules.

By mastering these concepts, you'll be well-equipped to manage and secure your Linux system's network traffic effectively.


PreviousRemote AccessNext Scripting Basics

Recommended Gear

Remote AccessScripting Basics