Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BR]: firewallcmd-ipset.conf multiport invalid port/service `1-65535' specified #3047

Closed
kowach opened this issue Jun 25, 2021 · 7 comments
Closed
Labels

Comments

@kowach
Copy link

kowach commented Jun 25, 2021

fail2ban v0.11.2
firewalld v0.8.2
CentOS 8.3.2011

Here is the error log:

  exec: ipset create f2b-dovecot hash:ip timeout 0
  firewall-cmd --direct --add-rule ipv4 filter INPUT_direct 0 -p tcp -m multiport --dports "$(echo '1:65535' | sed s/:/-/g)" -m set --match-set f2b-dovecot src -j REJECT --reject-with icmp-port-unreachable
  ipset v7.1: Set cannot be created: set with the same name already exists
  Error: COMMAND_FAILED: '/usr/sbin/iptables-restore -w -n' failed: iptables-restore v1.8.4 (nf_tables): invalid port/service `1-65535' specified
  Error occurred at line: 2
  Try `iptables-restore -h' or 'iptables-restore --help' for more information.

Looks like this version of firewall-cmd does accepts dports delimiter "-" in "1-65535" and it should be left "1:65535".

Solution is to replace multiport in firewallcmd-ipset.conf:
multiport = -p <protocol> -m multiport --dports "$(echo '<port>' | sed s/:/-/g)"
to
multiport = -p <protocol> -m multiport --dports "<port>"

@kowach kowach added the bug label Jun 25, 2021
@sebres
Copy link
Contributor

sebres commented Jun 25, 2021

Hmm...
and how one would handle this now?!

#2821 reported about vice versa situation (and therefore it was fixed in a038fd5), but not even a year later it must be reverted...

Still worse if this depends now on firewalld backend (e. g. - vs. : related to iptables vs. nftables).

But how fail2ban action must distinguish what exactly is expected (to be backwards and "forwards" compatible)?

I'm slowly tired to ask - why one uses this weird wrapper "firewalls" instead of native net-filters like iptables/ipset or nftables?

@kowach
Copy link
Author

kowach commented Jun 28, 2021

Oh, that is very messy situation.
Now I know why my iptables are empty, because nftables replaced it 😄

@kovacs-andras
Copy link

Oh, that is very messy situation. Now I know why my iptables are empty, because nftables replaced it smile

No, it isn't. You should check iptables-nft https://www.redhat.com/en/blog/using-iptables-nft-hybrid-linux-firewall

@kovacs-andras
Copy link

kovacs-andras commented Oct 30, 2021

Imho it's a matter of taste how people like to interact with their firewalls. It's probably harder to break but easier to read this way.

There is a clear statement in man firewall-cmd:
Warning: Direct rules behavior is different depending on the value of FirewallBackend. See CAVEATS in firewalld.direct(5).

We could check the backend like:
grep -q '^FirewallBackend=nftabless' /etc/firewalld/firewalld.conf

I just tested it with xtables-nft-multi and xtables-legacy-multi, both works with :.
So it seems like the best would be just revert to : from -.

sebres added a commit that referenced this issue Nov 1, 2021
…nge selector, replacing `:` with `-`;"

This reverts the incompatibility #3047 introduced by commit a038fd5 (#2821).
@sebres
Copy link
Contributor

sebres commented Nov 1, 2021

So it seems like the best would be just revert to : from -

Agree.
I'll revert a038fd5 because if someone need it with - (for nft and other backends), it is simply possible by specifying own port range. Vice versa it would be impossible (since it gets wrapped in action).
Thus the conclusion is very simple.

And I'll repeat my statement:
Why one uses this weird wrapper "firewalls" in fail2ban instead of native net-filters like iptables/ipset or nftables?
Why?!

@sebres sebres closed this as completed Nov 1, 2021
@kovacs-andras
Copy link

Many thanks!
It felt disrespectful to make a PR with this revert in it but please, let me know if I can further help!

@sebres
Copy link
Contributor

sebres commented Jan 6, 2023

Just for the record:
a038fd5 was reverted in 4b54a07 (no replacement of range separator takes place in the firewalld actions anymore).
Released in v.1.0.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants