-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipip1.sh
79 lines (63 loc) · 1.88 KB
/
ipip1.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#
# simple host-to-host ipip tunnel
#
# set up 3 namespaces with diff hostnames
set -x
unshare --net --uts -r /bin/bash &
export pid_netns1=$!
sudo nsenter -t $pid_netns1 -u hostname netns1
unshare --net --uts -r /bin/bash &
export pid_netns2=$!
sudo nsenter -t $pid_netns2 -u hostname netns2
unshare --net --uts -r /bin/bash &
export pid_netns3=$!
sudo nsenter -t $pid_netns3 -u hostname netns3
# set up bridge and veth links
sudo ip link add ens192 netns $pid_netns1 type veth peer name eth1 netns $pid_netns3
sudo ip link add ens192 netns $pid_netns2 type veth peer name eth2 netns $pid_netns3
sudo nsenter -t $pid_netns3 -u -n /bin/bash -c "
brctl addbr brx
ip link set brx up
"
# set up L3
sudo nsenter -t $pid_netns1 -u -n /bin/bash -c "
ip addr add 192.168.5.1/24 brd 192.168.5.255 dev ens192
ip link set ens192 up
ip link set lo up
ip a s
"
sudo nsenter -t $pid_netns2 -u -n /bin/bash -c "
ip addr add 192.168.5.2/24 brd 192.168.5.255 dev ens192
ip link set ens192 up
ip link set lo up
ip a s
"
# finish bridge setup
sudo nsenter -t $pid_netns3 -u -n /bin/bash -c "
ip link set eth1 up
ip link set eth2 up
brctl addif brx eth1
brctl addif brx eth2
"
# tunl0 setup
sudo modprobe -v ipip
sudo nsenter -t $pid_netns1 -u -n /bin/bash -c "
ip link set tunl0 up
ip link set tunl0 mtu 1480
ip addr add 10.245.0.0/32 dev tunl0
ip route add 10.245.1.0/24 via 192.168.5.2 dev tunl0 onlink
"
sudo nsenter -t $pid_netns2 -u -n /bin/bash -c "
ip link set tunl0 up
ip link set tunl0 mtu 1480
ip addr add 10.245.1.0/32 dev tunl0
ip route add 10.245.0.0/24 via 192.168.5.1 dev tunl0 onlink
"
set +x
echo "export pid_netns1=$pid_netns1"
echo "export pid_netns2=$pid_netns2"
echo "export pid_netns3=$pid_netns3"
echo "export pid_netns4=$pid_netns4"
echo "export pid_netns5=$pid_netns5"
echo "export pid_netns6=$pid_netns6"
echo "export pid_netns7=$pid_netns7"