(no commit message)
[wiki] / examples / simple-bridging-with-dhcp-server-side.mdwn
1 >     [[!meta title="simple-bridging-with-dhcp-server-side"]]
2 >     # Company:  PowerCraft Technology
3 >     # Author:   Copyright Jelle de Jong <jelledejong@powercraft.nl>
4 >     # Note:     Please send me an email if you enhanced the document
5 >     # Date:     2010-05-24
6 >     # License:  CC-BY-SA
7 >     
8 >     # This document is free documentation; you can redistribute it and/or
9 >     # modify it under the terms of the Creative Commons Attribution Share
10 >     # Alike as published by the Creative Commons Foundation; either version
11 >     # 3.0 of the License, or (at your option) any later version.
12 >     #
13 >     # This document is distributed in the hope that it will be useful,
14 >     # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 >     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 >     # Creative Commons BY-SA License for more details.
17 >     #
18 >     # http://creativecommons.org/licenses/by-sa/
19 >     
20 >     #-----------------------------------------------------------------------
21 >     
22 >     # for commercial support contact me, part of the revenue go back to tinc
23 >     
24 >     #-----------------------------------------------------------------------
25 >     
26 >     # http://www.tinc-vpn.org/
27 >     # http://www.tinc-vpn.org/examples/bridging
28 >     # http://www.tinc-vpn.org/documentation/tinc_toc
29 >     
30 >     #-----------------------------------------------------------------------
31 >     
32 >     # <@guus> Well all the tinc daemons together act like a single switcch
33 >     # <@guus> And each node in the VPN is connected to a port of that switch
34 >     # <@guus> And if you bridge the VPN interface with eth0, then it's like you plug a cable in a port of your eth0 LAN and the other end of that cable into the tinc switch
35 >     
36 >     #-----------------------------------------------------------------------
37 >     
38 >     unset LANG LANGUAGE LC_ALL
39 >     apt-get update; apt-get dist-upgrade
40 >     
41 >     apt-cache show tinc
42 >     apt-get install tinc
43 >     apt-get install bridge-utils
44 >     
45 >     #-----------------------------------------------------------------------
46 >     
47 >     /etc/init.d/tinc stop
48 >     
49 >     #-----------------------------------------------------------------------
50 >     
51 >     # ls -hal /dev/net/tun
52 >     crw-rw-rw- 1 root root 10, 200 May 20 20:07 /dev/net/tun
53 >     
54 >     # grep tinc /etc/services
55 >     tinc        655/tcp             # tinc control port
56 >     tinc        655/udp
57 >     
58 >     cat /usr/share/doc/tinc/README.Debian
59 >     zcat /usr/share/doc/tinc/README.gz | less
60 >     zcat /usr/share/doc/tinc/NEWS.gz | less
61 >     cat /usr/share/doc/tinc/examples/tinc-up
62 >     w3m /usr/share/doc/tinc/tinc_0.html
63 >     
64 >     cat /etc/default/tinc
65 >     less /etc/init.d/tinc
66 >     
67 >     #-----------------------------------------------------------------------
68 >     
69 >     vim /etc/default/tinc
70 >     EXTRA="-d"
71 >     cat /etc/default/tinc
72 >     
73 >     #-----------------------------------------------------------------------
74 >     
75 >     cat /etc/tinc/nets.boot
76 >     echo 'powercraft01' | tee --append /etc/tinc/nets.boot
77 >     cat /etc/tinc/nets.boot
78 >     
79 >     #-----------------------------------------------------------------------
80 >     
81 >     ls -hal /etc/tinc/scallab01/
82 >     mkdir --verbose /etc/tinc/powercraft01/
83 >     mkdir --verbose /etc/tinc/powercraft01/hosts/
84 >     touch /etc/tinc/powercraft01/tinc.conf
85 >     
86 >     #-----------------------------------------------------------------------
87 >     
88 >     vim /etc/network/interfaces
89 >     
90 >     # tinc-vpn: dhcp bridge
91 >     auto br0
92 >       iface br0 inet static
93 >       address 192.168.3.1
94 >       netmask 255.255.255.0
95 >     # pre-up /sbin/ifconfig eth2 hw ether 00:1b:21:61:af:d7
96 >     # pre-up /sbin/ifconfig eth2 0.0.0.0
97 >     # bridge_ports eth2
98 >       bridge_ports tun1
99 >       bridge_maxwait 1
100 >       bridge_fd 2.5
101 >     
102 >     cat /etc/network/interfaces
103 >     
104 >     #-----------------------------------------------------------------------
105 >     
106 >     echo 'interface "br0" {
107 >       request subnet-mask, broadcast-address, time-offset,
108 >         host-name, netbios-scope, interface-mtu, ntp-servers;
109 >     }' | tee --append /etc/dhcp3/dhclient.conf
110 >     
111 >     cat /etc/dhcp3/dhclient.conf
112 >     
113 >     #-----------------------------------------------------------------------
114 >     
115 >     vim /etc/dhcp3/dhcpd.conf
116 >     
117 >     subnet 192.168.3.0 netmask 255.255.255.0 {
118 >         range 192.168.3.200 192.168.3.240;
119 >         option routers 192.168.3.1;
120 >         option domain-name-servers 192.168.3.1;
121 >     }
122 >     
123 >     #-----------------------------------------------------------------------
124 >     
125 >     ifdown br0
126 >     ifup br0
127 >     
128 >     #-----------------------------------------------------------------------
129 >     
130 >     vim /etc/default/dhcp3-server
131 >         INTERFACES="vlan2 eth0 br0" # add the br0 to the correct location
132 >     
133 >     /etc/init.d/dhcp3-server restart
134 >     ps aux | grep dhcp
135 >     tail -n 400 -f /var/log/syslog
136 >     
137 >     #-----------------------------------------------------------------------
138 >     
139 >     ifconfig br0
140 >     route -n
141 >     brctl show
142 >     
143 >     #-----------------------------------------------------------------------
144 >     
145 >     # ifconfig br0
146 >     br0       Link encap:Ethernet  HWaddr 00:00:00:00:00:00
147 >               inet addr:192.168.3.1  Bcast:192.168.3.255  Mask:255.255.255.0
148 >               inet6 addr: fe80::dc56:d3ff:fe1a:31df/64 Scope:Link
149 >               UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
150 >               RX packets:12 errors:0 dropped:0 overruns:0 frame:0
151 >               TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
152 >               collisions:0 txqueuelen:0
153 >               RX bytes:2568 (2.5 KB)  TX bytes:1536 (1.5 KB)
154 >     
155 >     # route -n
156 >     Kernel IP routing table
157 >     Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
158 >     192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 br0
159 >     192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 vlan2
160 >     192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
161 >     84.245.3.0      0.0.0.0         255.255.255.0   U     0      0        0 eth1
162 >     0.0.0.0         84.245.3.1      0.0.0.0         UG    100    0        0 eth1
163 >     
164 >     # brctl show
165 >     bridge name bridge id       STP enabled interfaces
166 >     br0     8000.000000000000   no
167 >     
168 >     #-----------------------------------------------------------------------
169 >     
170 >     echo 'AddressFamily = ipv4
171 >     Device = /dev/net/tun
172 >     Interface = tun1
173 >     Mode = switch
174 >     Name = server01' | tee /etc/tinc/powercraft01/tinc.conf
175 >     
176 >     cat /etc/tinc/powercraft01/tinc.conf
177 >     chmod 640 /etc/tinc/powercraft01/tinc.conf
178 >     ls -hal /etc/tinc/powercraft01/tinc.conf
179 >     
180 >     echo '#!/bin/sh
181 >     ifconfig $INTERFACE 0.0.0.0
182 >     brctl addif br0 $INTERFACE' | tee /etc/tinc/powercraft01/tinc-up
183 >     
184 >     cat /etc/tinc/powercraft01/tinc-up
185 >     chmod 750 /etc/tinc/powercraft01/tinc-up
186 >     ls -hal /etc/tinc/powercraft01/tinc-up
187 >     
188 >     echo '#!/bin/sh
189 >     brctl delif br0 $INTERFACE
190 >     ifconfig $INTERFACE down' | tee /etc/tinc/powercraft01/tinc-down
191 >     
192 >     cat /etc/tinc/powercraft01/tinc-down
193 >     chmod 750 /etc/tinc/powercraft01/tinc-down
194 >     ls -hal /etc/tinc/powercraft01/tinc-down
195 >     
196 >     #-----------------------------------------------------------------------
197 >     
198 >     rm /etc/tinc/powercraft01/rsa_key.priv
199 >     rm /etc/tinc/powercraft01/hosts/server01
200 >     tincd -n powercraft01 -K
201 >     
202 >     #-----------------------------------------------------------------------
203 >     
204 >     getent services | grep 656
205 >     
206 >     #-----------------------------------------------------------------------
207 >     
208 >     vim /etc/tinc/powercraft01/hosts/server01
209 >     
210 >     # add on head of file
211 >     Compression = 9
212 >     PMTU = 1492
213 >     PMTUDiscovery = yes
214 >     Port = 656
215 >     
216 >     cat /etc/tinc/powercraft01/hosts/server01
217 >     
218 >     #-----------------------------------------------------------------------
219 >     
220 >     /etc/init.d/tinc stop
221 >     fg
222 >     /usr/sbin/tincd --net powercraft01 --no-detach --debug=5
223 >     
224 >     #-----------------------------------------------------------------------
225 >     
226 >     /etc/init.d/tinc restart
227 >     tail --line=500 --follow /var/log/syslog
228 >     
229 >     #-----------------------------------------------------------------------
230 >     
231 >     ifconfig br0
232 >     ifconfig tun1
233 >     route -n
234 >     brctl show br0
235 >     brctl showmacs br0
236 >     
237 >     #-----------------------------------------------------------------------
238 >     
239 >     # ifconfig br0
240 >     br0       Link encap:Ethernet  HWaddr 1e:eb:95:c3:04:d8
241 >               inet addr:192.168.3.1  Bcast:192.168.3.255  Mask:255.255.255.0
242 >               inet6 addr: fe80::dc56:d3ff:fe1a:31df/64 Scope:Link
243 >               UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
244 >               RX packets:17 errors:0 dropped:0 overruns:0 frame:0
245 >               TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
246 >               collisions:0 txqueuelen:0
247 >               RX bytes:3328 (3.3 KB)  TX bytes:2408 (2.4 KB)
248 >     
249 >     # ifconfig tun1
250 >     tun1      Link encap:Ethernet  HWaddr 1e:eb:95:c3:04:d8
251 >               inet6 addr: fe80::1ceb:95ff:fec3:4d8/64 Scope:Link
252 >               UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
253 >               RX packets:8 errors:0 dropped:0 overruns:0 frame:0
254 >               TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
255 >               collisions:0 txqueuelen:500
256 >               RX bytes:2627 (2.6 KB)  TX bytes:1340 (1.3 KB)
257 >     
258 >     # route -n
259 >     Kernel IP routing table
260 >     Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
261 >     192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 br0
262 >     192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 vlan2
263 >     192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
264 >     84.245.3.0      0.0.0.0         255.255.255.0   U     0      0        0 eth1
265 >     0.0.0.0         84.245.3.1      0.0.0.0         UG    100    0        0 eth1
266 >     
267 >     # brctl show br0
268 >     bridge name bridge id       STP enabled interfaces
269 >     br0     8000.1eeb95c304d8   no      tun1
270 >     
271 >     # brctl showmacs br0
272 >     port no mac addr        is local?   ageing timer
273 >       1 1e:eb:95:c3:04:d8   yes        0.00
274 >       1 86:03:27:21:2e:60   no        44.19
275 >     
276 >     #-----------------------------------------------------------------------
277 >     
278 >     ps aux | grep tincd
279 >     tincd -n powercraft01 -kUSR2
280 >     tail -n 100 /var/log/syslog
281 >     
282 >     #-----------------------------------------------------------------------
283 >     
284 >     May 24 17:29:31 ashley tinc.powercraft01[11557]: Statistics for Linux tun/tap device (tap mode) /dev/net/tun:
285 >     May 24 17:29:31 ashley tinc.powercraft01[11557]:  total bytes in:         468
286 >     May 24 17:29:31 ashley tinc.powercraft01[11557]:  total bytes out:          0
287 >     May 24 17:29:31 ashley tinc.powercraft01[11557]: Nodes:
288 >     May 24 17:29:31 ashley tinc.powercraft01[11557]:  server01 at MYSELF cipher 0 digest 0 maclength 0 compression 0 options 4 status 0018 nexthop server01 via server01 pmtu 1518 (min 0 max 1518)
289 >     May 24 17:29:31 ashley tinc.powercraft01[11557]: End of nodes.
290 >     May 24 17:29:31 ashley tinc.powercraft01[11557]: Edges:
291 >     May 24 17:29:31 ashley tinc.powercraft01[11557]: End of edges.
292 >     May 24 17:29:31 ashley tinc.powercraft01[11557]: Subnet list:
293 >     May 24 17:29:31 ashley tinc.powercraft01[11557]:  a2:63:0:96:a:c8#10 owner server01
294 >     May 24 17:29:31 ashley tinc.powercraft01[11557]: End of subnet list.
295 >     
296 >     #-----------------------------------------------------------------------
297 >     
298 >     tcpdump -n -i br0 broadcast
299 >     tcpdump -n -i tun0 broadcast
300 >     
301 >     #-----------------------------------------------------------------------
302 >     
303 >     tcpdump -n -e -i br0 icmp
304 >     tcpdump -A -p -n -i br0 port 80
305 >     tcpdump -A -p -n -i br0
306 >     
307 >     tcpdump -i br0 host 84.245.3.195 -l
308 >     
309 >     #-----------------------------------------------------------------------
310 >     
311 >     cat /var/lib/dhcp3/dhcpd.leases
312 >     
313 >     #-----------------------------------------------------------------------