By msnorm
Hi guys. Can anyone tell me exactly how this rule would translate into UFW:
iptables -N udp-flood iptables -A OUTPUT -p udp -j udp-flood iptables -A udp-flood -p udp -m limit --limit 50/s -j RETURN iptables -A udp-flood -j LOG --log-level 4 --log-prefix 'UDP-flood attempt: ’ iptables -A udp-flood -j DROP
It is to prevent massive UDP flood attacks on our server. At the moment I have a rule that simply blocks all ports apart from some specific service ports I need open. However, this is too restrictive.
My current rule : -A ufw-after-output -p udp -j DROP
Thanks for any help!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Thank you for the quick response. :)
The floods are not inbound they are outbound which is why I have set a rule to deny all outbound UDP packets. I already have been the target of such attacks and setting the above UFW rule has solved the problem, ie stopped the UDP floods, but because it’s too restrictive it has caused problems with some of the software I run.
First of all I can see a foreign ip port scanning my ip, then many UDP Fragment (1500) from <ip> to <ip> on eth0.
I don’t think cloudflare will help as I don’t run a public website that someone might think to attack.
Any suggestions how I can convert the rate limit rule to a UFW format?
Thanks.
Heya,
Translating custom iptables rules into UFW (Uncomplicated Firewall) configuration can be challenging because UFW is designed to simplify firewall configuration and doesn’t natively support complex rule sets, especially ones involving custom chains like your UDP flood protection setup. However, you can integrate custom iptables rules with UFW by adding them to UFW’s user rules files.
Here’s how you can adapt your iptables rules for UDP flood protection to work alongside UFW on your server:
Create the Custom Chain and Rules in iptables:
udp-flood) and add the necessary rules to manage the UDP traffic.Integrate with UFW:
/etc/ufw/. The files before.rules and after.rules are particularly useful for adding custom iptables rules.after.rules file.Editing the UFW Rules File:
/etc/ufw/after.rules file with a text editor (like nano or vim):sudo nano /etc/ufw/after.rules
At the end of this file, before the COMMIT line, add your custom iptables rules. It will look something like this:
*filter
:udp-flood - [0:0]
-A OUTPUT -p udp -j udp-flood
-A udp-flood -p udp -m limit --limit 50/s -j RETURN
-A udp-flood -j LOG --log-prefix "UDP-flood attempt: "
-A udp-flood -j DROP
COMMIT
Reload UFW:
sudo ufw reload
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.