VPN WLAN OpenBSD/Linux con OpenVPN
Questo piccolo paper spiega come creare una VPN in wifi fra box OpenBSD in
hostap mode e client Linux tramite OpenVPN con pre-shared key. Le istruzioni sono per OpenBSD 3.4, nella versione
3.5 OpenVPN fa parte dei ports.
# ===============
# Su OpenBSD:
# ===============
Scaricate il pacchetto
http://prdownloads.sourceforge.net/openvpn/openvpn-1.5.0.tar.gz
scompattatelo da qualche parte :)
/usr/packages/openvpn-1.5.0
Per attivare la compressione avrete bisogno delle librerie lzo, le trovate
sul sito http://www.oberhumer.com/opensource/lzo/, oppure nei ports
cd /usr/ports/archivers/lzo && make && make install
Ora compilate OpenVPN,
./configure --with-lzo-lib=/usr/local/lib --with-lzo-headers=/usr/local/include && make && make install && less README
Io ho fatto l'access point con OpenBSD, con una scheda Dlink DWL-500, che sarebbe una Dlink pcmcia dwl-650
piu' adattatore PCI. Se volete che risulti a tutti gli effetti un'access point, dovrete attivare dhcpd ed
il nat all`avvio della macchina.
il mio /etc/dhcpd.conf è più o meno cosi'
shared-network LOCAL-NET {
option domain-name "my.wlan";
option domain-name-servers 212.216.112.112;
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.10;
range 192.168.0.30 192.168.0.100;
}
}
/etc/dhcpd.interfaces contiene solo
wi0
/etc/hostname.wi0 contiene
inet 192.168.0.1 255.255.255.0 NONE
!wicontrol \$if -n 802.11bofh -t 5 -p 6 -f 6
La prima riga assegna l'ip, la seconda da il nome, -t è il trasmit rate (io l'ho messo sui 5 mbit, perchè
la scheda mi dava strani problemi col buffer, voi potete provare anche 11) -p 6 è la modalità access point
e -f 6 è il canale numero 6.(man wicontrol)
Vi conviene attivare anche il filtro sui mac address, ed è bene associare un ip fisso al mac address della
macchina che volete mettere in vpn.
Per quanto riguarda il NAT, togliete il commento in /etc/sysctl.conf a
net.inet.ip.forwarding=1 # 1=Permit forwarding (routing) of packets
e poi cambiate in /etc/rc.conf
pf=YES
Ora create una directory /etc/openvpn, in essa andranno almeno due file:
La chiave pre-shared
# openvpn --genkey --secret shared.key
ed il file di configurazione di openvpn per il vostro tunnel
# cat > vpn.conf
# ===================================
# OpenVPN 802.11b - Access Point
# ===================================
; L'ip della macchina remota
remote 192.168.0.2
; routing,
; up ./routing
secret /etc/openvpn/shared.key
; fuffa :)
dev tun0
port 5000
comp-lzo
user nobody
ping 15
persist-tun
persist-key
verb 3
; ip locale ed ip della macchina remota del tunnel
ifconfig 10.0.0.1 10.0.0.2
# ===============
# Su Linux
# ===============
# cat > /etc/openvpn/vpn.conf
# ===================================
# OpenVPN 802.11b - Client
# ===================================
remote 192.168.0.10
; routing
up ./routing.sh
; la stessa chiave che avete creato
secret /etc/openvpn/shared.key
dev tun0
port 5000
comp-lzo
user nobody
;group nobody
ping 15
persist-tun
persist-key
verb 3
; stesso di prima, ma si invertono gli ip
ifconfig 10.0.0.2 10.0.0.1
routing.sh e':
#!/bin/bash
route delete default
route add default gw 10.0.0.1
Che serve a redirigere tutto il traffico del client verso la vpn; se volete che la macchina esca anche
su internet dovrete attivare anche il nat sul server per la rete della vpn, io ho 10.0.0.0/24,
quindi in /etc/pf.conf ho
nat on vr0 from 10.0.0.0/24 to any -> vr0
Dove vr0 esce su internet.
rebootate.
Per ricaricare le regole basta fare
# pfctl -f /etc/pf.conf
Bene, ora dovete _solo_ testare il tutto.
Sul server date
# /usr/local/sbin/openvpn --verb 3 --config /etc/openvpn/vpn.conf
Mon Dec 22 01:54:36 2003 0: OpenVPN 1.5.0 i386-unknown-openbsd3.4 [SSL] [LZO] built on Dec 21 2003
Mon Dec 22 01:54:36 2003 1: Static Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Mon Dec 22 01:54:36 2003 2: Static Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Mon Dec 22 01:54:36 2003 3: Static Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Mon Dec 22 01:54:36 2003 4: Static Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Mon Dec 22 01:54:36 2003 5: LZO compression initialized
Mon Dec 22 01:54:36 2003 6: /sbin/ifconfig tun0 delete
Mon Dec 22 01:54:36 2003 7: NOTE: Tried to delete pre-existing tun/tap instance -- No Problem if failure
Mon Dec 22 01:54:36 2003 8: /sbin/ifconfig tun0 10.0.0.1 10.0.0.2 mtu 1255 netmask 255.255.255.255 up
Mon Dec 22 01:54:36 2003 9: TUN/TAP device /dev/tun0 openedMon Dec 22 01:54:36 2003 10: Data Channel MTU parms [ L:1300 D:1300 EF:45 EB:19 ET:0 ]
Mon Dec 22 01:54:36 2003 11: Local Options hash (VER=V3): '1fe7a543'
Mon Dec 22 01:54:36 2003 12: Expected Remote Options hash (VER=V3): '5d310f7c'
Mon Dec 22 01:54:36 2003 13: UID set to nobody
Mon Dec 22 01:54:36 2003 14: UDPv4 link local (bound): [undef]:5000
Mon Dec 22 01:54:36 2003 15: UDPv4 link remote: 192.168.0.2:5000
Sul client lo stesso comando.
Se il client riesce a pingare il server e viceversa, avete fatto il vostro :)
Conclusioni
Openbsd non ha il driver tap; questo non consente di usare OpenVPN come bridged vpn, non si puo' far vedere al client tutta la rete remota insomma,
non ho provato, ma i driver tap per openbsd 3.4 sono su http://diehard.n-r-g.com/, patchando il kernel dovrebbe essere possibile utilizzare OpenVPN
in modalita' bridged.
Fausto Napolitano
nk at openbeer dot it