First get the line numbers
$ sudo iptables -nL --line-numbers
Assuming you have a DROP
all line on line 2002 and you want to add a new rule just before that:
$ sudo iptables -I INPUT 201 -i eth0 -p tcp --dport 3002 -j ACCEPT -m comment --comment "Port 3000 for nodejs site"
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"