-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSwitched_lan.imn
More file actions
285 lines (256 loc) · 5.51 KB
/
Switched_lan.imn
File metadata and controls
285 lines (256 loc) · 5.51 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
node n1 {
type router
model router
network-config {
hostname firewall-router
!
interface eth2
ip address 10.0.2.254/24
!
interface eth1
ip address 10.0.1.254/24
!
interface eth0
ip address 10.0.0.1/24
!
}
canvas c1
iconcoords {315.5 279.5}
labelcoords {315.5 311.5}
services {IPForward DefaultRoute UserDefined Firewall}
interface-peer {eth0 n2}
custom-config {
custom-config-id service:Firewall
custom-command Firewall
config {
files=('firewall.sh', )
}
}
custom-config {
custom-config-id service:Firewall:firewall.sh
custom-command firewall.sh
config {
#!/bin/sh
# custom node firewall rules for service (security.py)
# -------- CUSTOMIZATION REQUIRED --------
#
# Below are sample iptables firewall rules that you can uncomment and edit.
# You can also use ip6tables rules for IPv6.
#
# accept returning packets from B to A, otherwise packets from B will not be forwarded
# this means that if B reach A the forward will works because it was previously established
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
# REJECT traffic from A to B, ip_forward will works but this rule will reject the packets
iptables -A FORWARD -s 10.0.1.0/24 -d 10.0.2.0/24 -j REJECT
# Add masquerade rule to NAT all the traffic from A to Internet
iptables -t nat -A POSTROUTING -s 10.0.1.0/24 -o eth0 -j MASQUERADE
# The same for B
iptables -t nat -A POSTROUTING -s 10.0.2.0/24 -o eth0 -j MASQUERADE
}
}
custom-config {
custom-config-id service:DHCP
custom-command DHCP
config {
dirs=('/etc', )
files=('/etc/dnsmasq.conf', )
cmdup=('/etc/init.d/dnsmasq start', )
cmddown=('/etc/init.d/dnsmasq stop', )
cmdval=('pidof dnsmasq', )
}
}
custom-config {
custom-config-id service:DHCP:/etc/dnsmasq.conf
custom-command /etc/dnsmasq.conf
config {
# in /etc/dnsmasq.conf
interface=eth0
interface=eth1
dhcp-range=eth1,10.0.1.1,10.0.0.240,8h
dhcp-range=eth2,10.0.2.1,10.0.2.240,8h
}
}
custom-config {
custom-config-id service:UserDefined
custom-command UserDefined
config {
files=('update_resolvconf.sh', )
cmdup=('sh update_resolvconf.sh', )
}
}
custom-config {
custom-config-id service:UserDefined:update_resolvconf.sh
custom-command update_resolvconf.sh
config {
#!/bin/bash
# oldstyle
#echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.8.8" > /etc/resolvconf/resolv.conf.d/base
resolvconf --enable-updates
resolvconf -u
}
}
custom-config {
custom-config-id service:DefaultRoute
custom-command DefaultRoute
config {
files=('defaultroute.sh', )
}
}
custom-config {
custom-config-id service:DefaultRoute:defaultroute.sh
custom-command defaultroute.sh
config {
#!/bin/sh
# auto-generated by DefaultRoute service (utility.py)
ip route add default via 10.0.0.254
}
}
interface-peer {eth1 n3}
interface-peer {eth2 n4}
}
node n2 {
type rj45
network-config {
hostname enp1s0
!
}
canvas c1
iconcoords {314.0 195.0}
labelcoords {314.0 227.0}
interface-peer {0 n1}
}
node n3 {
type lanswitch
network-config {
hostname Aswitch
!
}
canvas c1
iconcoords {217.5 306.5}
labelcoords {217.5 330.5}
interface-peer {e0 n1}
interface-peer {e1 n5}
}
node n4 {
type lanswitch
network-config {
hostname Bswitch
!
}
canvas c1
iconcoords {416.0 309.0}
labelcoords {416.0 333.0}
interface-peer {e0 n1}
interface-peer {e1 n6}
}
node n5 {
type router
model PC
network-config {
hostname A1
!
interface eth0
ip address 10.0.1.1/24
!
}
canvas c1
iconcoords {170.0 366.0}
labelcoords {170.0 398.0}
interface-peer {eth0 n3}
services {DefaultRoute}
custom-config {
custom-config-id service:DefaultRoute
custom-command DefaultRoute
config {
files=('defaultroute.sh', )
}
}
custom-config {
custom-config-id service:DefaultRoute:defaultroute.sh
custom-command defaultroute.sh
config {
#!/bin/sh
# auto-generated by DefaultRoute service (utility.py)
ip route add default via 10.0.1.254
}
}
}
node n6 {
type router
model PC
network-config {
hostname B1
!
interface eth0
ip address 10.0.2.1/24
!
}
canvas c1
iconcoords {455.5 368.5}
labelcoords {455.5 400.5}
interface-peer {eth0 n4}
services {DefaultRoute}
custom-config {
custom-config-id service:DefaultRoute
custom-command DefaultRoute
config {
files=('defaultroute.sh', )
}
}
custom-config {
custom-config-id service:DefaultRoute:defaultroute.sh
custom-command defaultroute.sh
config {
#!/bin/sh
# auto-generated by DefaultRoute service (utility.py)
ip route add default via 10.0.2.254
}
}
}
link l1 {
nodes {n2 n1}
}
link l2 {
nodes {n3 n1}
bandwidth 0
}
link l3 {
nodes {n1 n4}
bandwidth 0
}
link l4 {
nodes {n5 n3}
bandwidth 0
}
link l5 {
nodes {n4 n6}
bandwidth 0
}
canvas c1 {
name {Canvas1}
}
hook 4:runtime_hook.sh {
#!/bin/sh
# session hook script; write commands here to execute on the host at the
# specified state
BRIFNAME=$(ifconfig | grep "^b.[0-9]\{4\}.[a-z0-9]*"| awk -F' ' {'print $1'})
WANIFNAME='wlp2s0'
ifconfig $BRIFNAME 10.0.0.254/24
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 10.0.0.1 -o $WANIFNAME -j MASQUERADE
}
option global {
interface_names no
ip_addresses yes
ipv6_addresses yes
node_labels yes
link_labels yes
show_api no
background_images no
annotations yes
grid yes
traffic_start 0
}
option session {
}