DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk10 min

How to List and Delete iptables Firewall Rules on Linux

A practical Linux guide to listing iptables rules, identifying the correct table and chain, deleting by number or exact specification, handling IPv6, and verifying changes without flushing the firewall.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use sudo iptables -L -v -n --line-numbers to see the IPv4 rules in the default filter table, including counters and one-based rule numbers. To remove one rule, list its chain, then run sudo iptables -D CHAIN NUMBER—for example, sudo iptables -D INPUT 3. Re-list the chain immediately afterward because the remaining rules move up. For IPv6, use the identical forms with ip6tables.

What iptables is changing

iptables and ip6tables are administration tools for packet filtering and network address translation on Linux. A rule belongs to a table and a chain. The default table is filter; common built-in chains in that table include INPUT (traffic arriving for the host), OUTPUT (traffic generated by the host), and FORWARD (traffic routed through the host). A command that omits -t therefore reads or edits filter, not every table on the system.

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The current iptables 1.8.13 manual documents the forms used here. The command edits the active in-memory ruleset. Whether those changes survive a reboot depends on the Linux distribution’s firewall or persistence mechanism; there is no single persistence command defined by the iptables manual.

Before you edit: access, scope, and a rollback record

Get administrative access

Listing may work as an unprivileged user on some systems, but editing the ruleset normally requires root privileges. Prefix commands with sudo, or open a root shell if that is how your host is administered.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Confirm the address family

iptables operates on IPv4 rules. IPv6 rules are a separate ruleset viewed and edited with ip6tables. Removing an IPv4 rule does not remove an equivalent IPv6 rule.

Record the current rule specifications

Before deleting anything, save a command-like representation of the relevant table:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo iptables -S
sudo iptables -t nat -S

-S prints rules in rule-specification form. It is useful as an audit record and provides the exact options needed for a specification-based deletion. If you are working with IPv6, substitute ip6tables.

Be certain you have an alternate session

A mistaken removal from an INPUT chain can affect remote administration. Make changes from a console or keep a second management session available so that a connectivity mistake can be corrected.

Command reference

Purpose Command What it shows or changes
List the default filter table sudo iptables -L -v -n --line-numbers All chains in filter, with counters, numeric addresses and ports, and one-based positions.
List one filter chain sudo iptables -L INPUT -v -n --line-numbers Only the INPUT chain, with details and rule numbers.
Show rule specifications sudo iptables -S Rules as command-like specifications, suitable for recording or reusing.
List a non-default table sudo iptables -t nat -L -v -n --line-numbers Rules in the nat table; replace nat with another relevant table.
Delete by position sudo iptables -D INPUT 3 Deletes rule 3 from INPUT in the default filter table.
Delete by position in another table sudo iptables -t nat -D PREROUTING 2 Deletes rule 2 from PREROUTING in nat.
Delete by specification sudo iptables -D INPUT -s 203.0.113.10 -p tcp --dport 22 -j DROP Removes the first rule whose complete specification matches.

List the rules you actually need

List every chain in the filter table

sudo iptables -L -v -n --line-numbers
  • -L lists rules.
  • -v adds verbose fields, including packet and byte counters and other details.
  • -n keeps addresses and ports numeric instead of performing reverse-DNS and service-name lookups. This is usually faster and avoids output changing because of name resolution.
  • --line-numbers prints each rule’s one-based position in its chain.

Read the chain heading before interpreting a number. Rule 3 in INPUT is unrelated to rule 3 in OUTPUT or in another table.

Inspect a single chain

Once you know where the traffic is evaluated, narrow the output:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
sudo iptables -L INPUT -v -n --line-numbers
sudo iptables -L OUTPUT -v -n --line-numbers
sudo iptables -L FORWARD -v -n --line-numbers

Use the chain-specific view when deciding which numbered entry to remove. It makes the position unambiguous and keeps unrelated chains out of the inspection.

Inspect non-filter tables

Use -t for a table other than filter. The command must specify the same table when you later delete a rule.

sudo iptables -t filter -L -v -n --line-numbers
sudo iptables -t nat -L -v -n --line-numbers
sudo iptables -t mangle -L -v -n --line-numbers
sudo iptables -t raw -L -v -n --line-numbers

Only query tables that exist and are relevant on the host. NAT rules, for example, are not shown by an unqualified -L because that command reads filter by default.

Capture an exact, reusable form

sudo iptables -S
sudo iptables -S INPUT
sudo iptables -t nat -S PREROUTING

The -S output identifies the chain and expresses each rule with its matches and target. Copy the current specification rather than reconstructing it from memory before using the specification-deletion form.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Delete one rule by its line number

Number-based deletion is the clearest choice when you have inspected the chain and want to remove exactly one entry at its current position.

  1. Choose the table and chain. Decide whether the rule is in filter, nat, mangle, or raw, and note the chain name.
  2. List that chain with numbers.
    sudo iptables -L INPUT -v -n --line-numbers
  3. Match the rule’s position and behavior. Check its source or destination, protocol, ports, interface, target, and counters. Do not rely on the number alone if another administrator may have changed the chain.
  4. Delete the numbered entry.
    sudo iptables -D INPUT 3
  5. Use the same table option for non-filter rules.
    sudo iptables -t nat -D PREROUTING 2
  6. Verify the result.
    sudo iptables -L INPUT -v -n --line-numbers

Rule positions start at 1, not 0. After a deletion, every later rule shifts toward the top of the chain. Re-list the chain before removing another number; otherwise a previously observed number can point to a different rule.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Delete by the complete rule specification

Specification-based deletion avoids counting a volatile position. Replace the original add operation’s -A with -D, keep the same chain, matches, options, and target, and include the same table selection.

sudo iptables -D INPUT -s 203.0.113.10 -p tcp --dport 22 -j DROP

This example removes the first INPUT rule that matches the source address, TCP protocol, destination port 22, and DROP target. If identical rules occur more than once, the first matching entry is deleted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Copy the live form instead of guessing

  1. Print the current specifications:
    sudo iptables -S INPUT
  2. Find the exact rule, including its target and every match option.
  3. Run the copied rule with -D in place of -A.
  4. List the chain again with counters and line numbers to confirm which entry disappeared.

The Netfilter HOWTO specifies that deletion syntax must have exactly the same options as the corresponding add, insert, or replace command. Differences in aliases, implicit modules, address notation, or option order can cause an assumed specification not to match. The live -S output is therefore the safest source for this method.

Number deletion versus specification deletion

Criterion Delete by number Delete by specification
Precision for a one-time edit High after an immediately preceding inspection; targets one current position. High when the copied specification is exact; removes the first matching rule.
Effect of other edits High susceptibility: positions change whenever an earlier rule is inserted or removed. Less dependent on position, but duplicate rules still make the first match the one removed.
Auditability The numbered list shows exactly which position was selected at the time. The command records the match and target that were intended for removal.
Ease of preparation List the chain and count; no long command needs to be reconstructed. Copy from -S; hand-typing a near-match can fail.
Blast radius One rule. One matching rule, specifically the first duplicate if duplicates exist.

For a single interactive cleanup, numbered deletion followed by verification is usually easiest. For a documented change or a script that must identify the rule by its behavior, copy the specification and use -D.

Do not confuse a single deletion with a flush

Flush a chain or table with -F

-F removes every rule from the selected chain. If no chain is named, it flushes every chain in the selected table.

sudo iptables -F INPUT
sudo iptables -t nat -F

The first command empties only INPUT in filter. The second empties all chains in nat. A flush is equivalent to deleting the rules one by one, but its blast radius is much larger than either single-rule form. Use it only when removing the complete selected set is intentional and you have a recovery plan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Remove a user-defined chain with -X

-X removes a user-defined chain only after it is empty and no other rules refer to it:

sudo iptables -X CUSTOM_CHAIN

Built-in chains such as INPUT, OUTPUT, and FORWARD are not ordinary user-defined chains and cannot be removed this way. Emptying a built-in chain with -F is a different operation from deleting the chain itself.

List and delete IPv6 rules

Use ip6tables for the IPv6 ruleset. Its list and delete forms parallel iptables:

sudo ip6tables -L -v -n --line-numbers
sudo ip6tables -L INPUT -v -n --line-numbers
sudo ip6tables -S
sudo ip6tables -D INPUT 3

Apply the same discipline: identify the table and chain, inspect the one-based position or copy the exact specification, delete only the intended rule, and re-list the chain. If the rule is in a non-default table, add the table selector to both commands, for example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo ip6tables -t nat -L -v -n --line-numbers
sudo ip6tables -t nat -D PREROUTING 2
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A repeatable, low-risk operating sequence

  1. Determine the family. Decide whether the traffic is IPv4 (iptables) or IPv6 (ip6tables).
  2. Determine the table. Start with filter unless the behavior is clearly NAT, packet mangling, or raw-table processing; explicitly inspect the relevant table with -t.
  3. Record the state. Run -S for the table and chain you will edit and retain the output in your change record.
  4. Inspect the chain. Use -L CHAIN -v -n --line-numbers and identify the target, matches, counters, and current position.
  5. Select the narrowest operation. Use -D CHAIN NUMBER for a one-time positional removal or an exact specification with -D when the rule’s behavior is the identifier. Do not use -F unless the entire chain or table must be emptied.
  6. Re-list immediately. Confirm the intended rule is gone and note the new positions of rules that remain.
  7. Exercise the affected traffic path. Test the specific connection, forwarding path, or translation that motivated the change rather than assuming a successful command means the policy is correct.
  8. Handle persistence separately. If the change must survive reboot, update the host’s distribution-specific persistence mechanism after validating the live ruleset.

Common mistakes and their fixes

The rule is not in the output

  • You may be looking at filter while the rule is in nat, mangle, or raw. Repeat the list command with the appropriate -t.
  • You may be checking IPv4 while the traffic uses IPv6. Run the corresponding ip6tables command.
  • You may have inspected the wrong chain. List INPUT, OUTPUT, or FORWARD separately, or the relevant user-defined chain.

A numbered deletion removed the wrong rule

Positions are one-based and shift after every earlier deletion or insertion. Re-list the exact chain immediately before each deletion. If concurrent changes make positions unreliable, copy the live rule from -S and delete by specification instead.

Specification deletion reports no match

Do not simplify the command. Compare it with the current -S output character for character, including source or destination notation, protocol, ports, interfaces, match modules, and target. Include the table selector if the original rule was not in filter.

The command succeeds but traffic still behaves the same

Re-list the chain and inspect counters. You may have deleted a rule in a path that is not handling the traffic, left a duplicate rule, or edited one address family while the connection uses the other. Check the relevant table and chain rather than repeating the same deletion.

Remote access stops after the edit

Use the alternate console or management session prepared before the change. Restore the intended rule using the same table, chain, and specification, then verify the chain and test access again. A numbered deletion can be reversed only after you know the original rule; this is why recording -S first matters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The change disappears after reboot

The iptables command manages the active ruleset; its manual does not define one universal save-and-restore service. Configure the persistence mechanism used by the particular Linux distribution or firewall manager, and verify the restored rules after a reboot or service restart.

Worked examples

Remove rule 3 from IPv4 INPUT

sudo iptables -S INPUT
sudo iptables -L INPUT -v -n --line-numbers
sudo iptables -D INPUT 3
sudo iptables -L INPUT -v -n --line-numbers

The first command records specifications, the second identifies the current numbered entry, the third removes only position 3, and the last confirms the result. If another rule was inserted between inspection and deletion, stop and inspect again instead of assuming that position 3 is unchanged.

Remove a specific SSH-source drop

sudo iptables -S INPUT
sudo iptables -D INPUT -s 203.0.113.10 -p tcp --dport 22 -j DROP
sudo iptables -L INPUT -v -n --line-numbers

This targets the first exact match for the source address, TCP destination port 22, and DROP target. If the rule shown by -S contains additional match options, include all of them in the deletion command.

Remove one NAT prerouting rule

sudo iptables -t nat -L PREROUTING -v -n --line-numbers
sudo iptables -t nat -D PREROUTING 2
sudo iptables -t nat -L PREROUTING -v -n --line-numbers

The -t nat option appears on every command so that listing and deletion address the same table.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the output tells you

A numbered listing gives you more than a deletion index. The verbose columns include packet and byte counters, which help show whether a rule has handled traffic. Numeric mode keeps addresses and ports literal, making it easier to compare output with logs and with the specification printed by -S. The target at the end of each rule—such as ACCEPT, DROP, or a jump to another chain—describes the action that will no longer occur after deletion.

Read those fields together. A rule with a familiar number but a different chain, table, target, or address is not the rule you intended to remove.

Key points to retain

  • Unqualified commands operate on the filter table; use -t for nat, mangle, or raw.
  • --line-numbers reports one-based positions, and positions change after deletions.
  • -D CHAIN NUMBER removes one current entry; specification deletion removes the first exact match.
  • -F flushes a chain or an entire table and is not a substitute for removing one rule.
  • iptables and ip6tables maintain separate IPv4 and IPv6 rulesets.
  • Always record with -S, verify by listing again, test the intended path, and configure persistence separately when required.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.