# Executing iptables command from module

**URL:** <https://www.ruby-forum.com/t/executing-iptables-command-from-module/221321>\
**Category:** NGINX\
**Created:** [July 9, 2012, 4:57am UTC](https://www.ruby-forum.com/t/executing-iptables-command-from-module/221321 "2012-07-09T04:57:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [July 9, 2012, 4:57am UTC](https://www.ruby-forum.com/t/executing-iptables-command-from-module/221321/1 "2012-07-09T04:57:07Z")

</div>

I would like to implement iptables into my module, now I want to know if  
I should even try to do this. I know the worker processes don’t run as  
root but the master does. So this most likely means I would need to  
utilize the system() command using the master process?

Is this the right way to go about this, or do I just need to stop  
pursuing this and let other stuff as fail2ban.

If it’s possible to pursue I just need some quick guidance on how I  
could achieve this.

Posted at Nginx Forum:

> **[Executing iptables command from module](https://forum.nginx.org/read.php?2,228416,228416#msg-228416)**
>
> I would like to implement iptables into my module, now I want to know if I should even try to do this. I know the worker processes don't run as root but the master does. So this most likely means I would need to utilize the system() command using the...

---

<div class="post-metadata">

**Author:** ![arosolino](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@arosolino](https://www.ruby-forum.com/u/arosolino)\
**Post date:** [July 10, 2012, 6:59am UTC](https://www.ruby-forum.com/t/executing-iptables-command-from-module/221321/2 "2012-07-10T06:59:55Z")

</div>

Nevermind I found a way to do this.

Posted at Nginx Forum:

> **[Re: Executing iptables command from module](https://forum.nginx.org/read.php?2,228416,228459#msg-228459)**
>
> I would like to implement iptables into my module, now I want to know if I should even try to do this. I know the worker processes don't run as root but the master does. So this most likely means I would need to utilize the system() command using the...

---

<div class="post-metadata">

**Author:** ![arosolino](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@arosolino](https://www.ruby-forum.com/u/arosolino)\
**Post date:** [July 10, 2012, 8:48am UTC](https://www.ruby-forum.com/t/executing-iptables-command-from-module/221321/3 "2012-07-10T08:48:38Z")

</div>

Is there a way to detect if the module is quitting versus reloading. I  
know how to tell if it’s quitting by attaching a method to the exit  
process. But I can not tell if it’s for a reload?

Posted at Nginx Forum:

> **[Re: Executing iptables command from module](https://forum.nginx.org/read.php?2,228416,228460#msg-228460)**
>
> I would like to implement iptables into my module, now I want to know if I should even try to do this. I know the worker processes don't run as root but the master does. So this most likely means I would need to utilize the system() command using the...

---

<div class="post-metadata">

**Author:** ![arosolino](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@arosolino](https://www.ruby-forum.com/u/arosolino)\
**Post date:** [July 12, 2012, 3:06am UTC](https://www.ruby-forum.com/t/executing-iptables-command-from-module/221321/4 "2012-07-12T03:06:26Z")

</div>

On 7/10/2012 7:59 AM, arosolino wrote:

> Nevermind I found a way to do this.
> 
> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,228416,228459#msg-228459](http://forum.nginx.org/read.php?2,228416,228459#msg-228459)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

can you share how and what you did?  
it seems like one thing i would like to know about nginx.

Thanks,  
Eliezer

–  
Eliezer C.

> **[דף הבית של אליעזר](https://www.ngtech.co.il/index/)**

IT consulting for Nonprofit organizations  
eliezer ngtech.co.il

---

<div class="post-metadata">

**Author:** ![arosolino](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9e8a1a/32.png) [@arosolino](https://www.ruby-forum.com/u/arosolino)\
**Post date:** [July 12, 2012, 7:25am UTC](https://www.ruby-forum.com/t/executing-iptables-command-from-module/221321/5 "2012-07-12T07:25:18Z")

</div>

Well if you are running nginx as a non root user. Then you need to add  
the following lines to /etc/sudoers  
Defaults:nginx !requiretty  
nginx ALL=(root) NOPASSWD: /sbin/iptables

The above is necessary because iptables can only be modified as root.

I can’t dump the code here for my module because it’s irrelevant, but  
you can basically use the system() command at this point to add an entry  
from IP tables.

Posted at Nginx Forum:

> **[Re: Executing iptables command from module](https://forum.nginx.org/read.php?2,228416,228523#msg-228523)**
>
> I would like to implement iptables into my module, now I want to know if I should even try to do this. I know the worker processes don't run as root but the master does. So this most likely means I would need to utilize the system() command using the...
