# Best practice to add custom IPtables?

**URL:** https://forum.yunohost.org/t/best-practice-to-add-custom-iptables/10238
**Category:** Discuss
**Tags:** iptables, english
**Created:** [February 6, 2020, 12:38pm UTC](https://forum.yunohost.org/t/best-practice-to-add-custom-iptables/10238 "2020-02-06T12:38:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ashledombos](https://forum.yunohost.org/user_avatar/forum.yunohost.org/ashledombos/32/2583_2.png) [@ashledombos](https://forum.yunohost.org/u/ashledombos)
#### Post date: [February 6, 2020, 12:38pm UTC](https://forum.yunohost.org/t/best-practice-to-add-custom-iptables/10238/1 "2020-02-06T12:38:48Z")

</div>

Hello,

I have a set of IPtables rules that I need to activate once after every other rules are set (and also after VPN tunnel is up)

These rules let forward containers requests towards the tunnel, and add some protections against DDOS attacks.

I’m not sure about the best practice: to regenerate a full list of rules with iptables-restore, or just append/insert some rules with a script. And when? After a specific service? Maybe after an amount of time?

---

<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: [February 6, 2020, 2:29pm UTC](https://forum.yunohost.org/t/best-practice-to-add-custom-iptables/10238/2 "2020-02-06T14:29:46Z")

</div>

For me the best pratice in yunohost is to setup a hooks triggered after yunohost add its iptables rules:

```auto
mkdir /etc/yunohost/hooks.d/post_iptable_rules
touch /etc/yunohost/hooks.d/post_iptable_rules/95-HOOKNAME

```

/etc/yunohost/hooks.d/post\_iptable\_rules/95-HOOKNAME

```auto
#!/bin/bash

# PUT you rules here (bellow an example)
iptables -w -A vpnclient_in -p icmp -j ACCEPT

exit 0

```

---

<div class="post-metadata">

### Author: ![ashledombos](https://forum.yunohost.org/user_avatar/forum.yunohost.org/ashledombos/32/2583_2.png) [@ashledombos](https://forum.yunohost.org/u/ashledombos)
#### Post date: [February 6, 2020, 7:26pm UTC](https://forum.yunohost.org/t/best-practice-to-add-custom-iptables/10238/3 "2020-02-06T19:26:12Z")

</div>

> [@ljf](#):
>
> /etc/yunohost/post\_iptable\_rules

I see a directory /etc/yunohost/hooks.d/post\_iptable\_rules, i guess I should put the hook there?

---

<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: [February 6, 2020, 8:24pm UTC](https://forum.yunohost.org/t/best-practice-to-add-custom-iptables/10238/4 "2020-02-06T20:24:27Z")

</div>

indeed i made a small mistake a edit my answer
