LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Iptables at startup (https://www.linuxquestions.org/questions/linux-newbie-8/iptables-at-startup-94495/)

Johnnyboy 09-19-2003 09:22 AM

Iptables at startup
 
Hi, I'm fairly new to linux and I have a problem with starting up linux with ipforwarding. When I boot linux I always have to run these commands on linux to get my winXP box to connect to the Internet through my linux box.

iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward

How can I make it so that I don't have to write these commands every single time I boot? I know that I should make some kind of startup script and so on, but can someone give me direct instructions what to do and how because I don't have a clue?

I have a similar problem with starting apache server at startup

/etc/rc.d/init.d/httpd start

Hangdog42 09-19-2003 11:07 AM

Writing a script is easy. You do have to start with [#! /bin/bash[/B] on the first line. That tells linux that this is a bash script, so if you use a shell besides bash, you may have to change it (I don't think many people do, so try it this way and see if it works).

On the following lines, just add the lines you normally type in the console. Once your done, save the file. In order to run the script, you have to make it executable, and you can do that by chmod +x scriptname.

Once you've got your script, you can either run in manually, or put a reference to it in a startup file like /etc/rc.local. For example, on my Slackware machine, I've got a firewall script called /etc/rc.firewall (which is the standard name in Slackware and a few other distros) and in the rc.inet1 file (which starts up the network in Slack) there is a line rc.firewall. So when the script hits that during boot, it starts my firewall.

Johnnyboy 09-19-2003 02:36 PM

Thx a lot, that works! :)


All times are GMT -5. The time now is 07:46 PM.