Good evening all,
I am running ubuntu20.04 and aimed to allow only specific ip addresses on a specified port.
Single ip definition works as expected but can't set it up for multiple ip addresses.
I think the best solution here is just to flip the logic around, so that you have one rule listing the IPs from which the connection to TCP port 29999 should be accepted, and then after that rule another rule in the chain to drop all other traffic to that same port. So you'd end up with the same result, just using two rules: one to allow both your IPs, and one to block all others.
Great, glad to hear that helped. One thing to remember about iptables chains is that they are processed in order, with processing terminating on the first matching rule in the chain. So you'll want all your ACCEPT rules for this TCP port to come before your DROP rule, otherwise you'll end up dropping all traffic and accepting none, since the DROP rule will match all packets, and any further packet filtering for that port will then stop there.
You can use the -m iprange module to specify a range of IP addresses. The syntax for this module is -m iprange --src-range IP-IP. For example, to block incoming traffic from IP addresses 149.202.11.22 to 149.202.11.24 on port 29999, you can use the following command:
You can also use the -m iprange module to specify multiple ranges of IP addresses. For example, to block incoming traffic from IP addresses 149.202.11.22 to 149.202.11.24 and 94.20.30.40 to 94.20.30.44 on port 29999, you can use the following command: