Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run a script during boot up...?

Status
Not open for further replies.

Trekkie

Technical User
Apr 29, 2000
150
CA
hi,

i have setup a linux box as firewall/router, but i have type "#echo 1> /proc/sys/net/ipv4/ip_forward" everytime i boot up the linux boot.

is there a boot script where i can place this script, so that it runs automatically everytime it boots up?

Thx
 
Hi,

Yes - depends on distro to some extent - but for redhat & mandrake you'd add your local customisation to :

/etc/rc.d/rc.local

On Suse it might be /etc/rc.d/boot.local in some versions.

Hope this helps
 
You must be running a script to start firewalling cammands (ipchains or iptables) so it may be more appropriate to put it there.
 
Hi,

Not sure I understand the last comment - you can quite happily enter iptables commands from the root shell prompt (#).

Anyway, /etc/rc.d/rc.local is certainly a script - it fact it says at the top :

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

Regards
 
and be sure that you dont add number sign (#) at line start, it means comment ;)
it means "echo 1> /proc/sys/net/ipv4/ip_forward" instead of "#echo 1> /proc/sys/net/ipv4/ip_forward"
 
Hi, yes you can happily enter iptables commands at the prompt but the point I was trying to make was that as the system is most probably running a firewall script containing th iptables/upchains commands, putting the command to enable ip forwarding in the same script would be the most 'appropriate'. Especially as any interactive alterations to the 'firewalling' settings could then be effectively reset by restarting the firewall script alone.

The locatation of a firewall script is dependent upon the distribution and any tools used to configure a firewall (bastille, etc) - Have a look in /etc/rc.d/rc.firewall, /etc/sysconfig/firewall-config etc.




 
Just found this.... probably a lot simpler.







To enable/disable ip_forwarding:

Temporary solution:

echo ?1? > /proc/sys/net/ipv4/ip_forward :enable

echo ?0? > /proc/sys/net/ipv4/ip_forward :disable

Permanent solution:

For Debian: In /etc/network/option file, set ip_forward=yes.

For RedHat: In /etc/sysconfig/network file, set forward_ipv4=true.
 
Hi,

Makes more sense now ! But it doesn't do any harm if that bit is set more than once in multiple scripts - as long as no other script sets it to zero !

The '/etc/sysconfig/network' setting you mentioned also applies to Mandrake. It just causes the network startup script to do the same thing but the config is more user friendly - the /proc filesystem only exists in memory so that value must be reset after a reboot however you achieve it.


Regards





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top