Skip to contentSkip to conversation

iptables links

DISCUSSION Jonathan Tripathy 3 participants 5 messages Jun 23, 2011 – Jul 18, 2011

lore
Share & tools
lore
#0 lore raw

Hi Everyone,

Is there any quick command that I can use with iptables to remove all links to a chain, as well as removing the chain itself?

Or would I need to hack this in?

Thanks

#1 lore raw
Quoted 4 lines · Jonathan Tripathy

Hi Everyone,

Is there any quick command that I can use with iptables to remove all links to a chain, as well as removing the chain itself?

No, -F would clean the chain, and -X would remove them, which are currently two separate operations with the iptables(8) frontend.

#2 lore raw
Quoted 8 lines · Jan Engelhardt
Quoted 4 lines · Jonathan Tripathy

Hi Everyone,

Is there any quick command that I can use with iptables to remove all links to a chain, as well as removing the chain itself?

No, -F would clean the chain, and -X would remove them, which are currently two separate operations with the iptables(8) frontend.

Hi There,

Thanks for this, however I already knew those commands. I'm looking for a command to clear the links to the chain (the commands above clear the chain itself), however I'm guessing is there none?

Thanks

#3 lore raw
Quoted 9 lines · Jonathan Tripathy
Quoted 7 lines · Jan Engelhardt
Quoted 5 lines · Jonathan Tripathy

Hi Everyone,

Is there any quick command that I can use with iptables to remove all links to
a chain, as well as removing the chain itself?

Quoted 7 lines
Quoted 2 lines

No, -F would clean the chain, and -X would remove them, which are currently two separate operations with the iptables(8) frontend.

Hi There,

Thanks for this, however I already knew those commands. I'm looking for a command to clear the links to the chain (the commands above clear the chain itself), however I'm guessing is there none?

Indeed there are none.

#4 lore raw

I've had the need for the same functionality, so I wrote the script below. It takes one argument - the name of the chain for which you want to delete any rules that reference it. It prints the iptables commands to run to delete the respective rules.

#!/bin/bash

# unlink-chain.sh
# Erik Schorr 2010
# Permission to use, modify, and redistribute granted to anyone for any purpose.
# Use this program at your own risk.
# Author disclaims any responsibility for quality or usefulness of this program.
PATH=/sbin:/usr/sbin:$PATH
SEARCHCHAIN=$1
if [ "$SEARCHCHAIN" ]; then
  for n in nat filter raw; do
    iptables -t $n -S | grep -e "^-A.*-j $SEARCHCHAIN " | sed -e 
"s/^-A/-D/g" -e "s/^/iptables -t $n /g"
  done
else
  echo "usage: $0 <target chain>"
fi

### snip

# ./unlink-chain.sh DROP_SPYWARE
iptables -t filter -D EGRESS_OUT -d x.x.x.x/32 -p tcp -m comment --comment "SPYWARE 20110215" -j DROP_SPYWARE

Enjoy.

Quoted 22 lines · Jan Engelhardt
Quoted 8 lines · Jonathan Tripathy
Quoted 7 lines · Jan Engelhardt
Quoted 5 lines · Jonathan Tripathy

Hi Everyone,

Is there any quick command that I can use with iptables to remove all links to
a chain, as well as removing the chain itself?

Quoted 7 lines
Quoted 2 lines

No, -F would clean the chain, and -X would remove them, which are currently two separate operations with the iptables(8) frontend.

Hi There,

Thanks for this, however I already knew those commands. I'm looking for a command to clear the links to the chain (the commands above clear the chain itself), however I'm guessing is there none?

Indeed there are none.
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html