Score:0

Create iptable rule to match UDP traffic with multiple source ports and a single destination port

bs flag

I am trying to create an iptable rule that will match multiple source ports and a single destination port. I have tried the following rule but am met with this error:

iptables -A INPUT -p udp -m multiport --sports 30000:65535 --dport 3074 -j ACCEPT
iptables v1.4.21: multiport: option "--source-ports" cannot be used together with "--destination-ports".

I saw a post similar to this one where someone asked about routing traffic from certain ports and/or IP's to a single port/IP however that is not what I am trying to do. I want only traffic coming from those source ports going to that single destination port to be accepted.

I am using a default drop all policy, if anyone can help that would be greatly appreciated!

Score:1
us flag

Dport is matching as a multiport option here, you should put it before:

iptables -A INPUT -p udp --dport 3074 -m multiport --sports 30000:65535 -j ACCEPT

john avatar
bs flag
Thanks worked perfectly!
A.B avatar
cl flag
A.B
Indeed. Then `--dport` becomes a parameter to the implicit `-m udp` match (which appears back when using `iptables -S INPUT` or `iptables-save`). This would also have worked: `iptables -A INPUT -p udp -m multiport --sports 30000:65535 -m udp --dport 3074 -j ACCEPT`
john avatar
bs flag
Ah okay I understand now how the kernel would read the rule, thanks for clearing that up for me I really appreciate the help!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.