• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / Virtualization

How to reset iptables to the default settings

Published: September 28, 2017 | Modified: June 25, 2020



Learn how to reset iptables to default settings. The default setting of iptable is to accept all for all types of connections.

Reset iptables to default

In our last post, we saw iptables basics, where we learned about how iptables works, what are the policies, and how to configure iptables policies.

While working on iptables, if you get confused about policies and you need to start afresh then you need to reset iptables to default settings. By default, I mean to set accept all policy and flush any existing configured rules from settings.

In this article, we will walk through a set of commands to reset iptables to default settings. This can also be treated as how to reset firewall in Linux like ubuntu, centos, Redhat, Debian, etc. It’s a pretty simple 2 steps process.

Step 1 : Set accept all policy to all connections

Using the below set of commands you will set accept rule for all types of connections.

root@kerneltalks # iptables -P INPUT ACCEPT
root@kerneltalks # iptables -P OUTPUT ACCEPT
root@kerneltalks # iptables -P FORWARD ACCEPT

This will confirm, iptables gonna accept all requests for all types of connections.

Step 2 : Delete all existing rules.

Using below set of commands, delete your currently configured rules from iptables.

root@kerneltalks # iptables -F INPUT
root@kerneltalks # iptables -F OUTPUT
root@kerneltalks # iptables -F FORWARD

Or you can do it in single command –

root@kerneltalks # iptables -F

That’s it! Your iptables are reset to default settings i.e. accept all! Now, neatly and carefully design your policies and configure them.

⇠ Previous article
How to setup domain name in Linux server
Next article ⇢
How to download files from EC2 to local machine using winSCP

Related stuff:

  • AWS EC2, S3, RDS revision before the CSA exam
  • What is PDB in Kubernetes?
  • Running a pod in Kubernetes
  • AWS VPC, Route53, IAM revision before the CSA exam
  • Difference between Docker swarm and Kubernetes
  • Docker swarm cheat sheet
  • How to open port on AWS EC2 Linux server
  • How to install docker in Linux
  • What is Docker? Introduction guide to Docker
  • How to install VMware Tools on Linux guest machine
  • Docker container utilization monitoring
  • AWS CloudFront, SNS, SQS revision before the CSA exam

Filed Under: Virtualization Tagged With: linux reset firewall, reset firewall ubuntu, reset iptables centos, reset iptables centos 7, reset iptables to default ubuntu, reset iptables ubuntu 16, restore iptables to default debian

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Comments

  1. EllisGL says

    October 1, 2017 at 6:52 am

    I thought a default IPTables setup was drop all?

    Reply
    • Shrikant Lavhate says

      October 1, 2017 at 10:40 am

      Nope. Default chain policy is ACCEPT. Or else how even root admin will able to connect server over SSH (port 22)!

      Reply
  2. matttbe says

    October 1, 2017 at 11:51 am

    What about the other tables (mangle, nat, raw)? 🙂

    Also this graph is very useful to understand how IPTables works: https://en.m.wikipedia.org/wiki/Netfilter#/media/File%3ANetfilter-packet-flow.svg

    Reply
    • Shrikant Lavhate says

      October 1, 2017 at 9:26 pm

      Woah. Thats too much information for a beginners who comes here for quick command to reset all his iptable configuration mistakes!

      Reply
      • matttbe says

        October 1, 2017 at 9:43 pm

        If you say so but if a beginner copy-pasted commands that blocked him/her, he/she probably wants to reset everything ASAP, not only the part he/she can understand 🙂
        I mean hiding the user there are other tables while he/she has a problem and wants to reset everything could be even more confusing.

        And IPv6 is more and more used, especially with the small VPS

        Reply
  3. MIke says

    February 13, 2020 at 1:33 am

    if you have no connectivity after dropping everything with the -F, then run the following:

    sudo nano /etc/default/ufw
    –> make sure that IPV6=yes

    iptables -P INPUT ACCEPT;
    sudo ufw reset;
    sudo ufw disable;
    sudo ufw default deny incoming;
    sudo ufw default allow outgoing;
    sudo ufw allow ssh;
    sudo ufw allow http;
    sudo ufw allow https;
    sudo ufw enable;
    sudo ufw status;

    make sure its OK…

    Reply
  4. Me says

    January 4, 2021 at 4:11 am

    If you flush iptables the chains can drp the ssh access. For secure reset:

    rm -f /etc/sysconfig/iptables
    rm -f /etc/sysconfig/iptables.save
    touch /etc/sysconfig/iptables
    systemctl restart iptables

    Reply
  5. vinay says

    August 21, 2021 at 3:30 pm

    brother please help , how to block all outgoing tcp connections except for port 20000

    Reply
  6. Asasi says

    May 16, 2023 at 8:22 pm

    Please heeeeeeeeeeeelp
    I just ran iptables -F and every access to servers seems blocked !! I can’t even connect through SSH or even ping the IP. What should I do? :((

    Reply
  7. Victor says

    December 7, 2023 at 10:48 pm

    Thank you for this. My iptables config was hosed after trying proton VPN. This is the only thing that helped.

    Reply

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.