Every once in awhile I have wanted to be able to run a specific script automatically when Linux starts regardless of the user. Typically, I have also wanted that script to run as root because I’m doing random odd things like unusual mountings or whatever. In this case, I wanted to set up an IPv4 tunnel to an IPv6 host so that I could access IPv6 only web sites.
So, while the focus of this article will be the startup script, I will also briefly discuss the IPv6 setup. So, to start, you want to create a shell script that will execute the commands you need. In this case we’ll call it LaunchIPv6Tunnel.sh and here are it’s contents:
ifconfig sit0 up
ifconfig sit0 inet6 tunnel ::126.96.36.199
ifconfig sit1 up
ifconfig sit1 inet6 add 2001:470:1f10:5ba::2/64
route -A inet6 add ::/0 dev sit1
Now, I am going to need to be root to do these next steps. Here’s how to become root:
Then type in your password when prompted. Next you want to copy your file to the /usr/sbin folder. Now, make it so it runs always as SuperUser (root) by doing the following command:
chmod +s LaunchIPv6Tunnel.sh
Now, the real trick to launching this script is in editing the /etc/rc.local file. Simply add the path and name of your script before the return 0 and you are good to go. Mine looks like this:
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0” on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# By default this script does nothing.
The next time you start your machine the script will run and away you go. You may want to test your script manually first to make sure it doesn’t cause any errors. As a side note, if you want your own IPv6 tunnel, you can go to http://www.tunnelbroker.net to get a free tunnel connection.