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