ashley_mitchell
ashley_mitchell 1d ago β€’ 0 views

Iptables Example: Allowing and Blocking Traffic in Linux

Hey there! πŸ‘‹ Let's dive into Iptables and how to use it to control network traffic in Linux. Iptables can seem a bit daunting at first, but with some examples and practice, you'll be blocking and allowing traffic like a pro! πŸ›‘οΈ Ready to get started?
πŸ’» Computer Science & Technology

1 Answers

βœ… Best Answer

πŸ“š Quick Study Guide

  • πŸ›‘οΈ Iptables is a user-space application program that allows a system administrator to configure the tables provided by the Linux kernel firewall (implemented as different Netfilter modules) and the chains and rules it stores.
  • 🚦 Rules are processed in order; the first matching rule determines the fate of the packet.
  • πŸšͺ Chains are predefined or user-defined sequences of rules. Common built-in chains include INPUT, OUTPUT, and FORWARD.
  • βœ… The basic syntax for iptables commands is: `iptables [-t table] COMMAND chain RULE_SPECIFICATIONS [options]`
  • πŸ”’ To allow traffic, use `-A chain -j ACCEPT`. To block traffic, use `-A chain -j DROP`.
  • 🌐 `-A` appends a new rule to the chain. `-I` inserts a new rule at a specific position. `-D` deletes a rule. `-L` lists rules.
  • πŸ’‘ Always be careful when modifying iptables rules to avoid accidentally locking yourself out of the system.

Practice Quiz

  1. Which command is used to append a new rule to the INPUT chain in iptables?
    1. iptables -I INPUT
    2. iptables -D INPUT
    3. iptables -A INPUT
    4. iptables -L INPUT
  2. What does the `-j` option in iptables specify?
    1. Jump target
    2. Justify rule
    3. Join chain
    4. Java execution
  3. Which chain is used for packets entering the system?
    1. OUTPUT
    2. FORWARD
    3. INPUT
    4. FILTER
  4. What is the default table used by iptables if no table is specified?
    1. mangle
    2. nat
    3. filter
    4. raw
  5. Which command lists all current iptables rules?
    1. iptables -A
    2. iptables -L
    3. iptables -X
    4. iptables -D
  6. How can you block all incoming traffic from a specific IP address (e.g., 192.168.1.100)?
    1. iptables -A OUTPUT -s 192.168.1.100 -j DROP
    2. iptables -A INPUT -d 192.168.1.100 -j DROP
    3. iptables -A INPUT -s 192.168.1.100 -j ACCEPT
    4. iptables -A INPUT -s 192.168.1.100 -j DROP
  7. What does the following command do? `iptables -A FORWARD -p tcp --dport 80 -j ACCEPT`
    1. Blocks all TCP traffic on port 80.
    2. Accepts all incoming TCP traffic on port 80 for the INPUT chain.
    3. Accepts all forwarding TCP traffic on port 80.
    4. Drops all outgoing TCP traffic on port 80.
Click to see Answers
  1. C
  2. A
  3. C
  4. C
  5. B
  6. D
  7. C

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! πŸš€