-
Notifications
You must be signed in to change notification settings - Fork 25
/
build_net.sh
85 lines (73 loc) · 3.52 KB
/
build_net.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
79
80
81
82
83
84
85
Step 1: add network namespace
sudo ip netns add h1
sudo ip netns add h2
sudo ip netns add h3
sudo ip netns add h4
# Step 2 (optional)
sudo ip netns exec h1 ip link set lo up
sudo ip netns exec h2 ip link set lo up
# ---------------------------------------------------------- h1 ----------------------------------------------------------
# build first link: s1-eth1 <-> h1-eth0
sudo ip link add s1-eth1 type veth peer name h1-eth0
# sudo ip link set s1-eth1 netns s1
sudo ip link set h1-eth0 netns h1
# activate with IP address assign
sudo ip netns exec h1 ip link set dev h1-eth0 up
sudo ip netns exec h1 ip link set h1-eth0 address 00:0a:00:00:01:01
sudo ip netns exec h1 ip addr add 10.0.1.1/24 dev h1-eth0
# sudo ip netns exec s1 ip link set dev s1-eth1 up
sudo ip link set dev s1-eth1 up
# sudo ip netns exec s1 ip link set s1-eth1 address 00:00:00:00:10:10
sudo ip link set s1-eth1 address 00:00:00:00:10:10
#sudo ip netns exec s1 ip addr add 10.0.1.2/24 dev s1-eth1
sudo ip addr add 10.0.1.2/24 dev s1-eth1
# ---------------------------------------------------------- h2 ----------------------------------------------------------
# build second link: s1-eth2 <-> h2-eth0
sudo ip link add s1-eth2 type veth peer name h2-eth0
# sudo ip link set s1-eth2 netns s1
sudo ip link set h2-eth0 netns h2
# activate with IP address assign
sudo ip netns exec h2 ip link set dev h2-eth0 up
sudo ip netns exec h2 ip link set h2-eth0 address 00:0a:00:00:02:02
sudo ip netns exec h2 ip addr add 10.0.2.1/24 dev h2-eth0
sudo ip link set dev s1-eth2 up
sudo ip link set s1-eth2 address 00:a0:00:00:02:02
sudo ip addr add 10.0.2.2/24 dev s1-eth2
# ---------------------------------------------------------- h3 ----------------------------------------------------------
# build link: s1-eth3 <-> h3-eth0
sudo ip link add s1-eth3 type veth peer name h3-eth0
# sudo ip link set s1-eth3 netns s1
sudo ip link set h3-eth0 netns h3
# activate with IP address assign
sudo ip netns exec h3 ip link set dev h3-eth0 up
sudo ip netns exec h3 ip link set h3-eth0 address 00:0b:00:00:02:02
sudo ip netns exec h3 ip addr add 10.0.3.1/24 dev h3-eth0
sudo ip link set dev s1-eth3 up
sudo ip link set s1-eth3 address 00:b0:00:00:02:02
sudo ip addr add 10.0.3.2/24 dev s1-eth3
# ---------------------------------------------------------- h4 ----------------------------------------------------------
# build link: s1-eth4 <-> h4-eth0
sudo ip link add s1-eth4 type veth peer name h4-eth0
# sudo ip link set s1-eth3 netns s1
sudo ip link set h4-eth0 netns h4
# activate with IP address assign
sudo ip netns exec h4 ip link set dev h4-eth0 up
sudo ip netns exec h4 ip link set h4-eth0 address 00:0c:00:00:02:02
sudo ip netns exec h4 ip addr add 10.0.4.1/24 dev h4-eth0
sudo ip link set dev s1-eth4 up
sudo ip link set s1-eth4 address 00:c0:00:00:02:02
sudo ip addr add 10.0.4.2/24 dev s1-eth4
## disable all ipv6
sudo ip netns exec h1 sysctl net.ipv6.conf.h1-eth0.disable_ipv6=1
sudo ip netns exec h2 sysctl net.ipv6.conf.h2-eth0.disable_ipv6=1
sudo ip netns exec h3 sysctl net.ipv6.conf.h3-eth0.disable_ipv6=1
sudo ip netns exec h4 sysctl net.ipv6.conf.h4-eth0.disable_ipv6=1
sudo sysctl net.ipv6.conf.s1-eth1.disable_ipv6=1
sudo sysctl net.ipv6.conf.s1-eth2.disable_ipv6=1
sudo sysctl net.ipv6.conf.s1-eth3.disable_ipv6=1
sudo sysctl net.ipv6.conf.s1-eth4.disable_ipv6=1
## setting routing table
sudo ip netns exec h1 ip route add default via 10.0.1.2
sudo ip netns exec h2 ip route add default via 10.0.2.2
sudo ip netns exec h3 ip route add default via 10.0.3.2
sudo ip netns exec h4 ip route add default via 10.0.4.2