aboutsummaryrefslogtreecommitdiffstats
path: root/Network/tap-add.sh
blob: 0d7ba0c0c247e44b8b02834ab55926f553eedfa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
########################################################################################################################
# tap-add.sh
########################################################################################################################
#
# All rights reserved Ⓒ 2017-2023 sdxlive.com
#
# Written by Jean-Christophe Manciot <jcmanciot@sdxlive.com>
#
########################################################################################################################

########################################################################################################################
#
# Adding a tap interface.
#
########################################################################################################################
#
# Requirements:
# ------------
#
# We assume that the following packages are already installed:
#       - iproute2
#
########################################################################################################################
#
# Parameters:
# ----------
#
# - <tap_number>: integer for the tap<tap_number> interface
# - <tap_ip_address>: IPv4 address of the tap<tap_number> interface
#
#######################################################################################################################
#
# Usage: example
# --------------
#
# tap-add.sh 0 172.31.255.1
#
########################################################################################################################
# set -x

tap_number=$1
tap_ip_address=$2
PARAMETERS_NUMBER=2

case "$#" in
        ${PARAMETERS_NUMBER})
                ;;
        *)
                echo -e ''$_{1..180}'\b-'
                echo The number and IPv4 address of the tap interface are expected as arguments
                echo -e ''$_{1..180}'\b-'
                exit 1
                ;;
esac

sudo ip tuntap add dev tap${tap_number} mode tap user root

sudo ip addr add ${tap_ip_address}/24 dev tap${tap_number}

exit $?