# IPTables and UFW problems

**URL:** https://meta.discourse.org/t/iptables-and-ufw-problems/312878
**Category:** Self-hosting
**Created:** [June 20, 2024, 12:42pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878 "2024-06-20T12:42:40Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Arnold](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arnold/32/389492_2.png) [@Arnold](https://meta.discourse.org/u/Arnold)
#### Post date: [June 20, 2024, 12:42pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/1 "2024-06-20T12:42:40Z")

</div>

Hi Discourse Community,

usually when I run a webserver I will use this script in combination with cloudflare:

[https://github.com/Paul-Reed/cloudflare-ufw](https://github.com/Paul-Reed/cloudflare-ufw)

Im not a fan of a public backend IP since it can easily be found with Censys or similar even if its behind cloudflare reverse proxy.

I tried many ways to reproduce this with discourse, but it just won’t work.

I also tried this with IPTables:

> <https://gist.github.com/Manouchehri/cdd4e56db6596e7c3c5a>

Got somebody a similar solution working with discourse?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 20, 2024, 2:49pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/2 "2024-06-20T14:49:58Z")

</div>

Docker does stuff that breaks IP tables. You should Google that, I think.

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [June 20, 2024, 7:27pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/3 "2024-06-20T19:27:59Z")

</div>

I also agree with him, wish discourse works like this: if you visit direct ip you see a white screen or literally anything, drop the connection without a domain idk

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 20, 2024, 7:31pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/4 "2024-06-20T19:31:41Z")

</div>

I think you could change the NGINX config so that it would accept connections only from cloudflare.

You could also change it so that it would not redirect the bare IP, but I’m not sure that would increase security by much.

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [June 20, 2024, 7:35pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/5 "2024-06-20T19:35:04Z")

</div>

> [@pfaffman](#):
>
> not sure that would increase security by much.

It sure would, prevents ip being found by dns , censys/shodan etc.  
I tried googling how to only allow cf but not much help, I don’t remember what the outcome was, plus if only allowing cf ip’s and im using the cf config to get real ip, would that mess it up? I’d really love if there was a doc.

and I don’t know how to edit the nginx config, when I enter app, can’t edit anything, im a bit of a noob sorry lol

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 20, 2024, 7:44pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/6 "2024-06-20T19:44:31Z")

</div>

The web template adds a redirect for the IP (and any connection), so you could un-do that bit.

[Allowing Cloudflare IP addresses only in Nginx | inDev. Journal](https://frankindev.com/2020/11/18/allow-cloudflare-only-in-nginx/) describes how to allow only cloudflare IPs. Figuring out how to get a template to do that is a bit of work for someone who understands the templates, but it should be possible.

> [@Genisis](#):
>
> if only allowing cf ip’s and im using the cf config to get real ip, would that mess it up? I

No. The real address is in another header.

> [@pfaffman](#):
>
> Docker does stuff that breaks IP tables. You should Google that, I think.

> **[Google Search](https://www.google.com/search?q=iptables+docker&oq=iptables+docker)**

and the first hit ([Packet filtering and firewalls | Docker Docs](https://docs.docker.com/network/packet-filtering-firewalls/)) describes

> **[Packet filtering and firewalls](https://docs.docker.com/engine/network/packet-filtering-firewalls/)**
>
> How Docker works with packet filtering, iptables, and firewalls

> [@](#):
>
> By default, all external source IPs are allowed to connect to the Docker host. To allow only a specific IP or network to access the containers, insert a negated rule at the top of the `DOCKER-USER` filter chain. For example, the following rule restricts external access from all IP addresses except `192.168.1.1`

So you’d need to change the cloudflare script accordingly.

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [June 20, 2024, 7:49pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/7 "2024-06-20T19:49:05Z")

</div>

this is way above my brain power, I do appreciate your response, will read those docs soon, hope someone sees this who have time and could write something up, ive seen quite a few posts here already regarding this issue

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 20, 2024, 7:54pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/8 "2024-06-20T19:54:29Z")

</div>

Unless you run a community that has a history of DDOS attacks for some particular reason and you expect more, I’d not use any more of your brain on it. It would take me an hour or three to figure it out and document it. I have been setting up Discourse for people for a long time and have never worked with someone for whom DDOS was an actual problem.

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [June 20, 2024, 7:56pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/9 "2024-06-20T19:56:53Z")

</div>

I do run a forum thats been targeted before, thanks to cf they helped (using pro plan), but it would be great to “prepare” for it before it happens, gotta have the best security right? but yeah I get it, its a lot of work.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [June 20, 2024, 7:58pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/10 "2024-06-20T19:58:20Z")

</div>

I think ChatGPT and the script from the first post could solve it.

---

<div class="post-metadata">

### Author: ![Genisis](https://avatars.discourse-cdn.com/v4/letter/g/f475e1/32.png) [@Genisis](https://meta.discourse.org/u/Genisis)
#### Post date: [June 20, 2024, 7:59pm UTC](https://meta.discourse.org/t/iptables-and-ufw-problems/312878/11 "2024-06-20T19:59:59Z")

</div>

I see, hopefully OP can attempt that, I’ll have a look later too, appreciate your help
