Bad Iptables Argument

I'm trying to defend Portmap using IPtables. For this I should deny receiving packages from all IPs but 192.168.0.0/24 on TCP and UDP.

For doing this I've written such IPtables rules:

iptables -A INPUT -p tcp -s! 192.168.0.0/24  --dport 111 -j DROP
iptables -A INPUT -p udp -s! 192.168.0.0/24  --dport 111 -j DROP

But I got such error:

Bad argument `192.168.0.0/24'
Try `iptables -h' or 'iptables --help' for more information.

How can I edit rules to get correct ones?

1 Answer

Syntax is wrong. You have to make a rule like:

iptables -A INPUT -p tcp ! -s 192.168.0.0/24  --dport 111 -j DROP

Exclamation mark needs to be prefixed, when you are trying to make oposite match.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest