About nixCraft

Topics

How Do I run firewall script as soon as eth0 interface brings up?

Posted by Vivek Gite [Last updated: February 20, 2007]

At home I connect to Internet via ADSL modem.

As soon as my eth0 comes up I would like to have my firewall script get executed and setup IPTABLE for me :)

Earlier I used to type command /root/fs.dsl.start via sudo. However while reading man page of interface file I came across post-up option. Following step demonstrates usage of post-up option:

1) Copy firewall script to /etc/network/if-up.d/ directory:
# mv /root/fw.dsl.start /etc/network/if-up.d/

2) Open Debian networking configuration file /etc/network/interfaces:
# vi /etc/network/interfaces

3) Setup post-up option, append following line to eth0 configuration section:
# post-up /etc/network/if-up.d/fw.dsl.start

Where,

Here is my /etc/network/interfaces after modification:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
name Ethernet LAN card
address 192.168.1.1
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0
gateway 192.168.1.254
post-up /etc/network/if-up.d/fw.dsl.start

4) Save file and restart networking:
# /etc/init.d/networking restart

5)Verify that iptables rules are loaded:
# iptables -L -n

Tip if you are new to Ethernet (LAN network) configuration under Debian Linux use following etherconf package to configure or reconfigure network. If etherconf is not installed use apt-get to install it:

a) Install etherconf:
# apt-get install etherconf

b) Configure network under Debian Linux:
# dpkg-reconfigure etherconf

E-mail this to a friend      Printable version

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Jevin Ramjattan Says:

    How do I do this on Fedora?

  2. nixcraft Says:

    Jevin,

    Use /etc/eth0/ip-up.local
    file.

    HTH

  3. Tahder Says:

    How do i use it in Ubuntu? why isn’t working when it is a Debian based….

  4. Gabor Says:

    In section 3) hash mark should be removed from line
    # post-up /etc/network/if-up.d/fw.dsl.start

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.