DDoS-Protection FIVEM

hey!
For those who are users of OVH and are having issues with protecting their fivem server this is for you!
this is my own personal iptable setup that blocks a lot of attacks for a fivem server I used to own.
Please remember that iptables dont mitigate ddos attacks they simply help the server while a ddos attack is occurring so dont put this on an unprotected server and think you’ll be aight, I highly recommend this to be used with ovh’s and ovh’s only.
If your gonna ask I used ubuntu 20.04 but that doesnt matter.
heres my setup enjoy!

#protects against UDP attacks (floods , connection floods, ovh bypasses, etc)

iptables -t raw -A PREROUTING -p udp -m hashlimit --hashlimit-name periplimit --hashlimit-mode srcip,dstport --hashlimit-srcmask 32 --hashlimit-upto 50/sec --hashlimit-burst 5 --hashlimit-htable-expire 300000 -j ACCEPT

iptables -t raw -A PREROUTING -p udp -j DROP

#accept ssh (whitelisting is recommended)

iptables -t raw -A PREROUTING -p tcp --dport 22 -j ACCEPT

iptables -t mangle -A PREROUTING -p tcp --dport 22 -j ACCEPT

#accept UDP because it’s filtered in the raw chain

iptables -t mangle -A PREROUTING -p udp -j ACCEPT

#rate limit / filter NEW state syn packets to protect against tcp floods

iptables -t mangle -A PREROUTING -p tcp --syn -m state --state NEW -m hashlimit --hashlimit-name periplimit --hashlimit-mode srcip,dstport --hashlimit-srcmask 32 --hashlimit-upto 300/sec --hashlimit-burst 1 --hashlimit-htable-expire 300000 -j ACCEPT

#uncomment if the above rule doesn’t work and replace it with this rule, however if this rule does not work play around with it until it does as intended

#iptables -t mangle -A PREROUTING -p tcp --syn -m state --state NEW -m hashlimit --hashlimit-name periplimit --hashlimit-mode srcip,dstport --hashlimit-srcmask 32 --hashlimit-upto 1/sec --hashlimit-burst 1 --hashlimit-htable-expire 300000 -j ACCEPT

#accept related,established connections

iptables -t mangle -A PREROUTING -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

#drop everything that doesn’t match these rules

iptables -t mangle -P PREROUTING DROP

-Mike

update: these rules arent meant to solve your ddos attack issues they are meant to help your server perform better whilst under ddos attack.
#this is a theorized rate limit that could work. it worked for me but i dont know how it will perform for you so use it on a test server to make sure it doesn’t block any connections for you before putting it on ur main fivem server.

iptables -t raw -A PREROUTING -p udp -m hashlimit --hashlimit-name periplimit --hashlimit-mode srcip,dstport --hashlimit-srcmask 32 --hashlimit-upto 300/sec --hashlimit-burst 2 --hashlimit-htable-expire 300000 -j ACCEPT

iptables -t raw -A PREROUTING -p udp -j DROP

if ur server is having issues with udp this could help solve the issue. remember to play around with the rate limits if it doesn’t do its job that u want it to.

4 Likes

Thanks

1 Like

you are trying to solve a problem with just a copy paste meanwhile there are entire dedicated companies to stop ddos attacks i highly doubt iptables solve that

yea but it still wouldn’t defend against any ddos attacks

bro, your blood presser can be seen thru your words just relax
i told you, what you have done here is nothing, sure it does something so it’s not actual nothing, but it still has no impact in mitigating a ddos attack, thus naming this thread “ddos protection” is just bad

2 Likes

fine im sorry. ill delete my comments. I just dont want people to think this is an instant ddos mitigation method which it isnt. sorry for rude comments. thank you for your opinion. i’ll see that better disclosure is provided in next post.

2 Likes

The only thing that worked for me (as mentioned above there are companies specialising in this) is to find an affordable Hoster with the right type and size of appliance.

Check out this thread as well for some more details: Cloudflare protection for FiveM - #9 by maxcamorra

thanks

Old thread, but people still land here looking for a fix, so adding the why behind what krane said (Mike already noted in his update that these rules don’t mitigate attacks).

1. iptables runs after the damage is done. The rules run on your server, so attack traffic has already crossed your uplink by the time they see it. If the attack is 10 Gbps and your port is 1 Gbps, the link is full before a single rule runs. Dropping packets on the box doesn’t give you that bandwidth back.

2. Even under your link limit, the CPU loses. Every packet still gets pulled off the NIC and handled by the kernel, including the ones you drop. At a few million packets per second, softirq eats your cores, FXServer starts hitching and players time out. raw PREROUTING is the cheapest spot in iptables, but it’s still late in the path. XDP drops in the driver and can handle far more, but nothing on the box helps once the pipe is full.

3. Per-IP rate limits don’t match how floods look. Spoofed floods rotate through huge numbers of source IPs, and reflection attacks come from thousands of real servers each sending a little. Each source stays under 50/s and gets through. Meanwhile a tight per-IP limit can catch real players during busy moments, which is probably why the update bumps it to 300.

4. Junk on 30120 looks like real traffic to a generic rule. A plain UDP rule can’t tell a FiveM client from garbage aimed at the same port. Filtering that actually works has to understand the FiveM protocol.

5. Your origin IP is the real weak spot. If attackers know your server’s actual IP, anything you put in front of it can be skipped. Common leaks: the server list heartbeat, old DNS records, certificate logs (crt.sh), Shodan, and panels like txAdmin sitting on the same IP. On OVH specifically, traffic from inside OVH’s own network doesn’t always get scrubbed the same way, so a cheap OVH VPS can hit an OVH-hosted server harder than you’d expect.

What iptables/nftables is still good for: host hygiene. Whitelist SSH, close your database and txAdmin ports to the public, drop anything you don’t serve. Keep that, just don’t count it as DDoS protection.

What actually works: filtering upstream, on a network with more capacity than the attack, by something that understands FiveM traffic, with your origin hidden behind it. Like oranjuicejohnes said, that means either a host with a proper game-aware mitigation appliance, or a protection proxy in front of your server.

Full disclosure: I run FIVESHIELD, which is the proxy option for FiveM/RedM (XDP filtering built around the FiveM protocol). Happy to answer questions here either way, even if you go with something else.