From: Roberto Nibali Date: Thu, 16 Dec 2004 14:58:53 +0000 Subject: Re: [LARTC] how to remove rules Message-Id: <41C1A2AD.5080202@drugphish.ch> List-Id: References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: lartc@vger.kernel.org Hi, > : I've had the same problem. I sorta wish there was an "ip rule flush" > : command that would leave only the default rules. Would be nice. > I have a function called "flush" which flushes all tables and all rules > other than the main routing table. Here's the "rule" flush portion. It > won't win any points for elegance, but it should get the job done: > > ip rule show | grep -Ev '^(0|32766|32767):' \ > | while read PRIO RULE; do > ip rule del prio ${PRIO%%:*} $( echo $RULE | sed 's|all|0/0|' ) > done This is what I've used in my iproute2 shell library package, maybe it's a bit more elegant (only one fork involved). Since we change our local, main and default table in our distro to different values I've added a KEEP variable. Prepend it to adjust to your settings. : ${KEEP:="local main default"} while read prio rule; do continue=0 for keep in ${KEEP}; do if [ "${rule//lookup ${keep}/}" != "${rule}" ]; then continue=1 fi done if [ ${continue} -eq 0 ]; then ip rule del prio ${prio%%:*} ${rule//all/0/0} fi done < <(ip rule show) Best regards, Roberto Nibali, ratz -- echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc _______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/