iptables Command in Linux

Learn via video courses
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

iptables is a powerful user-space utility for Linux that allows administrators to configure, manage, and maintain the IP packet filter rules of the Linux kernel's Netfilter framework. It provides a flexible, stateful packet filtering and Network Address Translation (NAT) system to secure and control network traffic.

Linux iptables Command Syntax

The syntax for the iptables command is as follows:

Where:

  • table: Specifies the packet filtering table to be used. The default table is 'filter'. Other options are 'nat', 'mangle', and 'raw'.
  • chain: Specifies the chain in the selected table to manipulate. Common chains are 'INPUT', 'OUTPUT', 'FORWARD', 'PREROUTING', and 'POSTROUTING'.

iptables Command Options:

  • -A: Append a rule to the specified chain.
  • -D: Delete a rule from the specified chain.
  • -I: Insert a rule in the specified chain at the specified position.
  • -R: Replace a rule in the specified chain at the specified position.
  • -L: List all rules in the specified chain or all chains.
  • -F: Flush (delete) all rules in the specified chain or all chains.
  • -Z: Zero (reset) the packet and byte counters in the specified chain or all chains.
Sharpen Your Fundamentals with Free Learning

Example Usages

  • List all rules in the 'filter' table:

    Output:

    Explanation: This command lists all the rules in the 'filter' table, showing the default policies for the INPUT, FORWARD, and OUTPUT chains.

  • Block all incoming traffic from a specific IP address:

    Explanation: This command appends a rule to the INPUT chain, dropping all incoming packets from the source IP address 192.168.1.10.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Tips

  • To make iptables rules persistent across reboots, use the 'iptables-save' and 'iptables-restore' commands or the 'iptables-persistent' package.

Advanced Use Cases of iptables Command in Linux

  • Allow SSH access from a specific IP address only:

    Explanation: This command appends a rule to the INPUT chain, allowing incoming SSH (port 22) connections only from the source IP address 192.168.1.10.

  • Limit the rate of incoming connections:

    Explanation: This command appends a rule to the INPUT chain, limiting the rate of incoming connections to 1 per second, with a burst allowance of 5 connections, for TCP traffic on port 80.

  • Set up a basic NAT:

    Explanation: This command appends a rule to the POSTROUTING chain of the 'nat' table, enabling basic Network Address Translation (NAT) for outgoing traffic on the eth0 network interface.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • iptables is a powerful and flexible packet filtering tool for Linux.

  • It can be used for securing and controlling network traffic.

  • iptables rules can be made persistent across reboots.