Startup script for TAP interfaces
To add startup script we can use:
- System > Preferences > Sessions
- local boot script (as services start/stop in /etc/init.d/)
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”