Skip to main content

Removing rules in IPTables

·272 words·2 mins
system-administration tech iptables linux networking sysadmin technology
James Pettigrove
Author
James Pettigrove
Cloud Engineer with a focus on Microsoft Azure

So you’ve had a go at entering the wonderful world of iptables, with its chains, rules and of course tables. But unfortunately for you it has gone all horribly wrong and now you have no internet!

Firstly, how are you here? More importantly; Thankfully iptables is built with such a situation in mind. Simply restart your router and *smoke bomb* the newly entered rules vanish.

But you, as a fellow Sysadmin, might still have access to the router. You as a Sysadmin CAN fix this. You just need to know how right? Let’s get rid of those offending rules and back to browsing memes shall we?

Let’s look back at the list from the NAT table you produced after entering the new rules.

iptables -t nat -L --line-numbers

Can you see how there is a number at the start of each line? In the example above, the new rules are line number 8 and line number 9.

At the same prompt, enter the below to remove the rules:

iptables -t nat -D PREROUTING 9

iptables -t nat -D PREROUTING 8

If entered correctly, no prompt will be given.

When removing rules, take care to enter the removal of said rules from the highest number and then descend down the table. If you deleted rule 8 before you deleted rule 9, rule 9 would become rule 8 as it is no longer there in the table. This can lead to you deleting rules you never meant to remove.

Verify your work once more with a NAT table output:

iptables -t nat -L --line-numbers

You should be back to square one and internet restored.

Related

Using IPTables to force all DNS queries to a Pi-Hole
·756 words·4 mins
system-administration tech iptables linux networking pihole sysadmin technology
Hopefully by now you have heard the good word about Pi-Hole, set one up in a Docker container and now enjoying a substantially ad-less and speedy internet experience across all your devices.
Changing Hostnames in Linux
·328 words·2 mins
system-administration tech debian linux raspberry-pi raspbian sysadmin technology
Recently I decided to give my two Raspberry Pi devices an overhaul + change in functionality.
Docker Daemon failing to start on Raspberry Pi 1 & Zeros
·535 words·3 mins
system-administration tech containers core-dump debian docker linux raspberry-pi raspbian segmentation-fault sysadmin technology
Have you recently attempted to install the containerization platform known as Docker on to a first generation Raspberry Pi (including A+ and B+) or a Zero and found you couldn’t start up a container?