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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like