Q:

Iptables command to check whether rule exists at specific line number

Is there a way we can check whether an iptable rule exists at specific position?
something like below:
iptables -C INPUT 1 -j ACCEPT

A:

I'm genuinely curious to know the use case for such a check.
Anyways you might use iptables -S command, which allows to indicate a rule-number.
Then it would depend on where you'd need to use the check result.
For your sample case you might for instance do:
iptables -S INPUT 1 | grep -ce '-j ACCEPT'

to get a 1 printed by grep -c (or 0 if no match).
Or in a shell, a test could be like:
[ "$(iptables -S INPUT 1)" = '-A INPUT -j ACCEPT' ]

assuming you know precisely the rule you want to check. Else you can use the [[ test with =~ operator, if your shell supports them, to look for a regexp matching that rule-number.

