logIt Log Around The Clock

Startup script for TAP interfaces

To add startup script we can use:

I added the following shell script: setup-tap:

#! /bin/bash
tap_up() {
tunctl -t tap0 -u $USER
tunctl -t tap1 -u $USER
ifconfig tap0 192.168.20.1
ifconfig tap1 192.168.40.1
#iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
sysctl -w net.ipv4.ip_forward=1
}
tap_down() {
tunctl -d tap0
tunctl -d tap1
sysctl -w net.ipv4.ip_forward=0
}
case "$1" in
start)
tap_up
;;
stop)
tap_down
;;
*)
echo "Usage: $0 {start|stop}"
;;
esac
exit 0

Basically it is used as ./setup-tap start|stop. The following steps add it to boot:
copy it to /etc/init.d/setup-tap
chmod +xr setup-tap
update-rc.d setup-tap defaults

The last updating will put it in default runlevel:
setup-tap start in runlevel 2,3,4, and 5 setup-tap stop in runlevel 1 and 6.

Specific to this script itself, it didn’t run at first due to the $USER environment variable which must be set to arif (my username).


One thought on “Startup script for TAP interfaces

  1. Arif

    Removing example:
    $ sudo update-rc.d -f smstools remove
    Removing any system startup links for /etc/init.d/smstools ...
    /etc/rc0.d/K20smstools
    /etc/rc1.d/K20smstools
    /etc/rc2.d/S20smstools
    /etc/rc3.d/S20smstools
    /etc/rc4.d/S20smstools
    /etc/rc5.d/S20smstools
    /etc/rc6.d/K20smstools

    It will remove the file as well from init.d

Leave a Reply