Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Bringing up the iptables /etc/init.d script *before* eth0
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Rylan
n00b
n00b


Joined: 08 May 2002
Posts: 41

PostPosted: Thu Jun 06, 2002 3:30 pm    Post subject: Bringing up the iptables /etc/init.d script *before* eth0 Reply with quote

I just started playing around with init scripts. So if I do something boneheaded in this tip, I'd like to know. With that in mind, here's how I got my iptables ruleset to load before bringing up my external interface.

In my box I have eth0 connected to my cablemodem (uses dhcp) and eth1 connected to my internal network (which is NAT'd).

First, setup whatever iptables rules you need. I modified this script to suite my needs. http://www.linuxguruz.org/iptables/scripts/rc.DHCP.firewall.txt. Make sure you modfie the
Code:
$IPTABLES -A INPUT -p ALL -i $LO_IFACE -s $INET_IP -j ACCEPT
rule, because $INET_IP isn't defined by default.

When you have a working set of rules
Code:
mkdir /var/lib/iptables
iptables-save > /var/lib/iptables/rules-save
rc-update add iptables default

I had to make the /var/lib/iptables directory because it didn't exist, and the /etc/conf.d/iptables automatically looks there. Alternatively, you could just change where the /etc/conf.d/iptables file looks for saved rulesets.

Next, in /etc/init.d/net.eth0, change the depend section so that
Code:
depend() {
        use pcmcia
}
looks like
Code:
depend() {
        need iptables
        use pcmcia
}


After a reboot eth0 came up after iptables, but eth1 was still coming up before both of them!
I tried many things with net.eth1 to make it come up *after* eth0 but nothing worked ("need net.eth0" "need iptables" "after net.eth0" etc). Now maybe I'm anal-retentive (note the use of the hypen :)), but I wanted eth1 to come up after eth0. Here's how I fixed it.
In /etc/init.d/iptables it has this depend section
Code:
depend() {
        need net logger
}

Aha! So it was starting net.eth1 because it needed net! It doesn't really so just remove net from there and it works.

I also added my echo "1" > /proc/sys/net/ipv4/ip_forward command to the iptables runscript, just so I didn't have to use it in /etc/conf.d/local.start.
I felt this was more gentoo-ish than the rc.local firewall method I was using ;).
Back to top
View user's profile Send private message
james
n00b
n00b


Joined: 24 Apr 2002
Posts: 56
Location: Middle Smithfield, PA

PostPosted: Thu Jun 06, 2002 7:52 pm    Post subject: Reply with quote

Nice.

I renamed iptables to biptables.

Now it starts before E;-)

J
_________________
17 Opps It's 19 now ;-) Gentoo's and counting
Back to top
View user's profile Send private message
headly
n00b
n00b


Joined: 21 Jun 2002
Posts: 46

PostPosted: Thu Jul 04, 2002 10:17 pm    Post subject: ip_forward Reply with quote

it is also possible to use /etc/sysctl.conf to set ip_forward.

it is parsed by some script in boot runlevel.
Back to top
View user's profile Send private message
cbrese
Tux's lil' helper
Tux's lil' helper


Joined: 12 Jul 2002
Posts: 126
Location: San Diego, CA

PostPosted: Thu Dec 19, 2002 7:51 pm    Post subject: Reply with quote

What I did was modify /etc/init.d/iptables to remove
Code:

need net

and then in /etc/init.d/net.eth0 I added
Code:

need iptables

I wonder why it wasn't setup that way to begin with, did I do something wrong?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum