Seguindo os passos descritos aqui , consegui configurar o servidor e o cliente VPN (eu pode pingar nos dois sentidos). Seus respectivos arquivos de configuração são:
servidor:
;local a.b.c.d
port 1194
;proto tcp
proto udp
push "redirect-gateway def1"
;dev tap
dev tun
ca ca.crt
cert certificate_server.crt
key certificate_server.key
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
;server-bridge
;push "route 192.168.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
;learn-address ./script
;push "redirect-gateway def1 bypass-dhcp"
;push "dhcp-option DNS 208.67.222.222"
;push "dhcp-option DNS 208.67.220.220"
;client-to-client
;duplicate-cn
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
;log openvpn.log
;log-append openvpn.log
cliente:
client
;dev tap
dev tun
;dev-node MyTap
;proto tcp
proto udp
remote <external_server_ip> 1194
;remote my-server-2 1194
push "dhcp-option DNS 10.8.0.1"
;remote-random
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert certificate_client.crt
key certificate_client.key
ns-cert-type server
;tls-auth ta.key 1
comp-lzo
O layout da rede é o seguinte: Estou usando um cliente para conectar-me a um servidor localizado atrás de um NAT. Encaminhei a porta 1194 no dispositivo NAT e consegui fazer ping no servidor com êxito. Agora gostaria de rotear todo o tráfego da interface eth0 do meu cliente para a interface tun0. A execução do ifconfig no cliente fornece:
eth0 Link encap:Ethernet HWaddr 01:02:03:04:05:06
inet addr:172.26.0.206 Bcast:172.26.255.255 Mask:255.255.0.0
inet6 addr: fe80::3285:a9ff:fe0b:fee8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15579878 errors:0 dropped:2 overruns:0 frame:0
TX packets:3774742 errors:0 dropped:0 overruns:0 carrier:4
collisions:0 txqueuelen:1000
RX bytes:7365014496 (7.3 GB) TX bytes:349016660 (349.0 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:132571 errors:0 dropped:0 overruns:0 frame:0
TX packets:132571 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6718530 (6.7 MB) TX bytes:6718530 (6.7 MB)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.8.0.6 P-t-P:10.8.0.5 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:1296 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 B) TX bytes:102968 (102.9 KB)
wlan0 Link encap:Ethernet HWaddr 01:01:01:01:01:01
inet addr:192.168.0.103 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::de85:deff:fe32:241f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:284664 errors:0 dropped:0 overruns:0 frame:0
TX packets:99157 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:177617284 (177.6 MB) TX bytes:32064393 (32.0 MB)
enquanto executa o comando nas saídas do servidor:
eth0 Link encap:Ethernet HWaddr 06:05:04:03:02:01
inet addr:192.168.2.7 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::219:d1ff:fefe:de8a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:44596 errors:0 dropped:0 overruns:0 frame:0
TX packets:22418 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9082333 (9.0 MB) TX bytes:5007949 (5.0 MB)
Interrupt:20 Memory:e3200000-e3220000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:394157 errors:0 dropped:0 overruns:0 frame:0
TX packets:394157 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:19763027 (19.7 MB) TX bytes:19763027 (19.7 MB)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.8.0.1 P-t-P:10.8.0.2 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:7615 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:463861 (463.8 KB) TX bytes:588 (588.0 B)
No meu cliente, o encaminhamento de pacotes IPv4 está ativado; minhas tabelas de roteamento na máquina cliente são:
cliente :
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.8.0.5 128.0.0.0 UG 0 0 0 tun0
0.0.0.0 172.26.0.1 0.0.0.0 UG 0 0 0 eth0
10.8.0.1 10.8.0.5 255.255.255.255 UGH 0 0 0 tun0
10.8.0.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
<server_external_ip> 172.26.0.1 255.255.255.255 UGH 0 0 0 eth0
128.0.0.0 10.8.0.5 128.0.0.0 UG 0 0 0 tun0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.26.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
enquanto no servidor:
servidor:
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
10.8.0.0 10.8.0.2 255.255.255.0 UG 0 0 0 tun0
10.8.0.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
Como posso encaminhar todo o tráfego de eth0 para tun0 na máquina cliente? Eu tentei adicionar uma entrada na minha tabela de roteamento:
sudo route add default gw 10.8.0.1
A saída é:
SIOCADDRT: No such process
Além disso, após essa etapa a conexão parou de funcionar, não pude mais fazer o ping do servidor a partir do cliente; o tráfego no eth0 não podia mais ser encaminhado.