Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to allow user to check how many rules are present in filter table, but not able to view actual rules, is that possible?

literally I mean iptables -L | wc -l (I know it's faulty), but sudo doesn't seem to support pipe commands like that, I mean, currently If I wanted to allow that, I need to grant permission to run iptables -L instead of iptables -L | wc -l

Any thoughts?

share|improve this question
    
not sure what shell you are using but I'am able to run the following: sudo iptables -L|egrep -v 'Chain|target'|wc -l without any problem –  BitsOfNix Jan 2 '13 at 13:48
    
@AlexandreAlves updated question ... –  warl0ck Jan 2 '13 at 13:54
    
The reason that pipe commands do not work with sudo, is because it is actually two separate commands... –  Gert van den Berg Jan 2 '13 at 14:06
add comment

1 Answer 1

up vote 3 down vote accepted

Create a script that runs the commands to get the number of iptables rules. I would suggest something like this:

#!/bin/sh
/sbin/iptables -L | grep -Ecv '^$|^Chain |^target'

Save script in /usr/local/bin, make it executable and check that only root can write to it. Recommended mode: 0555

Edit sudoers to allow the user to run that script using sudo.

share|improve this answer
    
Looks easy to do that! But anyway, I modified iptables program to do the counting ... thanks anyway, scripting is a good ideas to problems like this –  warl0ck Jan 2 '13 at 15:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.