-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·77 lines (58 loc) · 2.56 KB
/
setup.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
#!/bin/bash -e
. env.sh
if [[ $# -lt 1 ]] ; then
echo 'routing type is missing!'
exit 0
fi
ROUTING_PROTO=$1
NAT=$2
echo "Creating the namespaces"
sudo ip netns add $CON1
sudo ip netns add $CON2
echo "Creating the veth pairs"
sudo ip link add veth10 type veth peer name veth11
sudo ip link add veth20 type veth peer name veth21
echo "Adding the veth pairs to the namespaces"
sudo ip link set veth11 netns $CON1
sudo ip link set veth21 netns $CON2
echo "Configuring the interfaces in the network namespaces with IP address"
sudo ip netns exec $CON1 ip addr add $IP1/24 dev veth11
sudo ip netns exec $CON2 ip addr add $IP2/24 dev veth21
echo "Enabling the interfaces inside the network namespaces"
sudo ip netns exec $CON1 ip link set dev veth11 up
sudo ip netns exec $CON2 ip link set dev veth21 up
echo "Creating the bridge"
sudo ip link add name br0 type bridge
echo "Adding the network namespaces interfaces to the bridge"
sudo ip link set dev veth10 master br0
sudo ip link set dev veth20 master br0
echo "Assigning the IP address to the bridge"
sudo ip addr add $BRIDGE_IP/24 dev br0
echo "Enabling the bridge"
sudo ip link set dev br0 up
echo "Enabling the interfaces connected to the bridge"
sudo ip link set dev veth10 up
sudo ip link set dev veth20 up
echo "Setting the loopback interfaces in the network namespaces"
sudo ip netns exec $CON1 ip link set lo up
sudo ip netns exec $CON2 ip link set lo up
echo "Setting the default route in the network namespaces"
sudo ip netns exec $CON1 ip route add default via $BRIDGE_IP dev veth11
sudo ip netns exec $CON2 ip route add default via $BRIDGE_IP dev veth21
# ------------------- Step 3 Specific Setup --------------------- #
if [ $ROUTING_PROTO == "static" ];then
echo "Setting the route on the node to reach the network namespaces on the other node"
sudo ip route add $TO_BRIDGE_SUBNET via $TO_NODE_IP dev eth1
elif [ $ROUTING_PROTO == "bgp" ];then
echo "Setting the bgp route with bird"
envsubst < bird.conf | sudo tee /etc/bird/bird.conf
sudo systemctl restart bird
fi
echo "Enables IP forwarding on the node"
sudo sysctl -w net.ipv4.ip_forward=1
echo "Setup iptable rules"
#sudo iptables --append FORWARD --in-interface eth1 --out-interface veth11 --jump ACCEPT
#sudo iptables --append FORWARD --in-interface eth1 --out-interface veth21 --jump ACCEPT
#sudo iptables --append FORWARD --in-interface veth11 --out-interface eth1 --jump ACCEPT
#sudo iptables --append FORWARD --in-interface veth21 --out-interface eth1 --jump ACCEPT
sudo iptables --append POSTROUTING --table nat --out-interface $INTERFACE --jump MASQUERADE