# \[SOLVED\] Yunohost firewall reload deletes custom rules

**URL:** https://forum.yunohost.org/t/solved-yunohost-firewall-reload-deletes-custom-rules/22173
**Category:** Support
**Tags:** yunohost-firewall, english
**Created:** [November 18, 2022, 10:54am UTC](https://forum.yunohost.org/t/solved-yunohost-firewall-reload-deletes-custom-rules/22173 "2022-11-18T10:54:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![izakis](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/i/5f8ce5/32.png) [@izakis](https://forum.yunohost.org/u/izakis)
#### Post date: [November 18, 2022, 10:54am UTC](https://forum.yunohost.org/t/solved-yunohost-firewall-reload-deletes-custom-rules/22173/1 "2022-11-18T10:54:02Z")

</div>

Hi aleks,  
i added a chain for a country block on iptables by a bash script i wrote,  
all works good, it drops all the communications in dual direction for “china” in that case, for inbound and outbound,

the problem is, when yunohost firewall reload command being executed it will flush any chains i added in whatever way, whether its through a script or manually,  
its just return all the yunohost defined configurations back,

i have tried to check into firewall.py and i found “no\_reload” in if statement  
what will check “if not no\_reload:” so return function “firewall\_reload()”  
i did change it to true to check what will happen, and it did no reload as expected but its deleting all of the chains after several seconds,  
if i try to list the chains there are nothing there, its all empty, in something about 5 seconds,  
so i did set it back to false ,

so my question is, how can i tell yunohost not to delete any of my custom firewall rules after reload?

thank you in advance!

---

<div class="post-metadata">

### Author: ![ljf](https://forum.yunohost.org/user_avatar/forum.yunohost.org/ljf/32/58_2.png) [@ljf](https://forum.yunohost.org/u/ljf)
#### Post date: [November 18, 2022, 3:22pm UTC](https://forum.yunohost.org/t/solved-yunohost-firewall-reload-deletes-custom-rules/22173/2 "2022-11-18T15:22:37Z")

</div>

You can use a `post_iptable_rules` hook to do that: [Hooks | Yunohost Documentation](https://yunohost.org/en/packaging_apps_hooks#configuration-and-firewal)

---

<div class="post-metadata">

### Author: ![izakis](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/i/5f8ce5/32.png) [@izakis](https://forum.yunohost.org/u/izakis)
#### Post date: [November 18, 2022, 3:43pm UTC](https://forum.yunohost.org/t/solved-yunohost-firewall-reload-deletes-custom-rules/22173/3 "2022-11-18T15:43:36Z")

</div>

Hello thank you for your reply

can you please explain little bit more? i think i am lost here, i didn’t got you much,  
the documentation says:  
This hooks is run at the end of the command `yunohost firewall reload` or equivalent action in webadmin

- $1: True if upnp has succeeded
- $2: True if ipv6 is available

in my case i am using upnp cause my router is limited to 15 ports only and in upnp for some reason it can open probably unlimited ports,  
so as i understand reload runs on any upnp execution,

there is something i can do on firewall.py to stop the reload without harming the function? or any other way?

---

<div class="post-metadata">

### Author: ![ljf](https://forum.yunohost.org/user_avatar/forum.yunohost.org/ljf/32/58_2.png) [@ljf](https://forum.yunohost.org/u/ljf)
#### Post date: [November 18, 2022, 5:16pm UTC](https://forum.yunohost.org/t/solved-yunohost-firewall-reload-deletes-custom-rules/22173/4 "2022-11-18T17:16:36Z")

</div>

As explained on [the beginning of this doc](https://yunohost.org/en/packaging_apps_hooks#how-to-add-a-custom-hook-), you can do

```auto
mkdir -p /etc/yunohost/hooks.d/post_iptable_rules
nano /etc/yunohost/hooks.d/post_iptable_rules/05-block-china

```

In this 05-block-china, you can put something like:

```auto
#!/bin/bash
# And call your existing bash script here to add your new iptables rules after each yunohost firewall reload

```

---

<div class="post-metadata">

### Author: ![izakis](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/i/5f8ce5/32.png) [@izakis](https://forum.yunohost.org/u/izakis)
#### Post date: [November 18, 2022, 5:22pm UTC](https://forum.yunohost.org/t/solved-yunohost-firewall-reload-deletes-custom-rules/22173/5 "2022-11-18T17:22:56Z")

</div>

oh i have been on that folder i saw its empty so i didn’t got it,

thank you so much! high appreciated, you’re awesome thank you for your time and support.

---

<div class="post-metadata">

### Author: ![izakis](https://forum.yunohost.org/letter_avatar_proxy/v4/letter/i/5f8ce5/32.png) [@izakis](https://forum.yunohost.org/u/izakis)
#### Post date: [November 18, 2022, 6:52pm UTC](https://forum.yunohost.org/t/solved-yunohost-firewall-reload-deletes-custom-rules/22173/6 "2022-11-18T18:52:26Z")

</div>

works as charm! 🙂  
thank you again.

---

<div class="post-metadata">

### Author: ![system](https://forum.yunohost.org/uploads/default/original/2X/f/f59fe8e3ee6b100b4f574d30d6e30479c68b89f0.png) [@system](https://forum.yunohost.org/u/system)
#### Post date: [December 18, 2022, 6:52pm UTC](https://forum.yunohost.org/t/solved-yunohost-firewall-reload-deletes-custom-rules/22173/7 "2022-12-18T18:52:35Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
