
Espero que você possa me ajudar com meu problema. Estou construindo uma rede para uso pessoal e encontrei alguns problemas, não tenho experiência em redes. Vou explicar usando a imagem em anexo:
Diagrama de infraestrutura de rede
Problema: Não consigo acessar dispositivos em uma rede local usando o Wireguard e um roteador VPN baseado em Raspberry, que inclui serviços na rede local (câmeras, servidor web pessoal, bancos de dados).
Meta:
Acesse os dispositivos e seus serviços a partir do servidor e dos clientes remotos. Tenho pesquisado e alterado configurações, mas nenhuma funciona. Às vezes a partir de 10.6.0.1 posso chegar ao IP 172.16.0.1 e pronto.
Descrição da infraestrutura:
O servidor Wireguard (a) está localizado sobre uma instância Oracle conforme mostrado na imagem e possui os seguintes recursos:
IP público 158.43.56.3 (exemplo de IP)
IP interno 10.0.0.183 pela interface ens3
Servidor Wireguard IP 10.6.0.1 sobre interface wg0
Porta de proteção de fio 51820
Wireward instalado via pivpn
Na rede local, o modem fornece rede 192.168.100.XX (wi-fi ou ethernet)
Na rede que fornece o modem existe um Raspberry Pi 4 (b) com Ubuntu 20.04 funcionando como roteador cabeado com as seguintes funcionalidades:
- IP local 192.168.100.182 pela interface eth0
- IP Wireguard como Peer 10.6.0.5 sobre interface wg0
- Sub-rede local IP 172.16.0.1 sobre interface eth1 (adaptador usb-ethernet)
- Servidor DHCP na interface eth1
Um switch está conectado à interface eth1
Diferentes dispositivos (servidor, câmeras IP, DVR) se conectam ao switch e o DHCP fornece-lhes IP no formato 172.16.0.XX com intervalos entre 172.16.0.10 e 172.16.0.200 (ba, bb, bc por exemplo)
Dispositivos em outras redes conectados à VPN (10.6.0.3, por exemplo)
Minha configuração atual é a seguinte (como você pode ver, estou tentando):
Servidor Wireguard:
[Interface]
PrivateKey = yL743NyU0M1z7guWxA9kekW7DAOXzO8EDfkAaG+jSGQ=
Address = 10.6.0.1/24
MTU = 1420
ListenPort = 51820
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT;
PostUp = iptables -A FORWARD -o wg0 -j ACCEPT;
PostUp = iptables -t nat -A POSTROUTING -o ens3 -j MASQUERADE
PostUp = sysctl -q -w net.ipv4.ip_forward=1
#PostUp = route del -net 172.16.0.0/24 dev wg0
#iptables -t nat -A PREROUTING -d 172.16.0.0/24 -j DNAT --to-destination 10.6.0.1
#PostUp = iptables -t nat -A PREROUTING -d 172.16.0.0/24 -j DNAT --to-destination 10.6.0.1
#PostUp = iptables -t filter -A FORWARD -s 10.6.0.0/24 -d 172.16.0.0/24 -j ACCEPT
#PostUp = iptables -t nat -A POSTROUTING -s 10.6.0.0/24 -d 172.16.0.0/24 -j MASQUERADE
PostDown = sysctl -q -w net.ipv4.ip_forward=0
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT;
PostDown = iptables -D FORWARD -o wg0 -j ACCEPT;
PostDown = iptables -t nat -D POSTROUTING -o ens3 -j MASQUERADE
##PostUp = iptables -t mangle -A POSTROUTING -p tcp --tcp-flags SYN,RST SYN -o ens3 -j TCPMSS --clamp-mss-to-pmtu
##PostUp = iptables -t nat -A POSTROUTING -o ens3 -j MASQUERADE
##PostUp = iptables -A FORWARD -i ens3 -j ACCEPT
##PostUp = sysctl -q -w net.ipv4.ip_forward=1
##PostDown = sysctl -q -w net.ipv4.ip_forward=0
##PostDown = iptables -D FORWARD -i ens3 -j ACCEPT
##PostDown = iptables -t nat -D POSTROUTING -o ens3 -j MASQUERADE
##PostDown = iptables -t mangle -D POSTROUTING -p tcp --tcp-flags SYN,RST SYN -o ens3 -j TCPMSS --clamp-mss-to-pmtu
### begin huawei-device ###
[Peer]
PublicKey = WaP0UPdQWKE0uy3F750cOEeLmLkikdtw0XAw/eGcrFI=
PresharedKey = fMqhe7jxsC9ukEhymPOXCogWMWo82TzIx6Veg+8lslc=
AllowedIPs = 10.6.0.2/24
### end huawei-device ###
### begin mac ###
[Peer]
PublicKey = ZCAV6xDLswBuqYWs38JYwvx2fwvmR1uEFRIAD760pxI=
PresharedKey = JdtJFaWUG2ECAfLX05WCyz/rrcs6VWFkVgnvEqnqhHo=
AllowedIPs = 10.6.0.3/32
AllowedIPs = 172.16.0.10/32
PersistentKeepalive = 15
### end mac ###
### begin rasprouter ###
[Peer]
PublicKey = r56sl4HNKHFkz8/r+aGqOHClMuXUt9lGE34gpktP5Q4=
PresharedKey = ukAcmfZUaMuVq53ruIYWmADwDYq0W+0KNjgAQ/ojqH4=
AllowedIPs = 10.6.0.5/32
AllowedIPs = 172.16.0.10/32
PersistentKeepalive = 15
### end rasprouter ###
Roteador com fio framboesa
[Interface]
PrivateKey = SJXlysVGPfvodzG98EbwrZNvuPqo4sATLKaTB3Kqe20=
Address = 10.6.0.5/24
DNS = 1.1.1.1
###PostUp = sysctl -w net.ipv4.ip_forward=1
###PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
###PostUp = iptables -A FORWARD -o wg0 -j ACCEPT
###PostUp = iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
###PostUp = iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
###PostDown = sysctl -w net.ipv4.ip_forward=0
###PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
###PostDown = iptables -D FORWARD -o wg0 -j ACCEPT
###PostDown = iptables -t nat -D POSTROUTING -o wg0 -j MASQUERADE
###PostDown = iptables -t nat -D POSTROUTING -o eth1 -j MASQUERADE
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE; iptables -A FORWARD -o wg0 -j ACCEPT
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth1 -j MASQUERADE; iptables -D FORWARD -o wg0 -j ACCEPT
[Peer]
PublicKey = mCK/FAHGtXFBNLS5WpHhSPEBvZRwY09HohD1YkNCNSI=
PresharedKey = ukAcmfZUaMuVq53ruIYWmADwDYq0W+0KNjgAQ/ojqH4=
Endpoint = 158.43.56.3:51820
#AllowedIPs = 0.0.0.0/0, ::/1
AllowedIPs = 172.16.0.10/32
AllowedIPs = 10.6.0.0/24
PersistentKeepalive = 25
Cliente adicional (Mac na imagem) em outra LAN, distante
[Interface]
PrivateKey = YH+51/x6MoErmogdOs0UUzIF6W6Oz56t7BhhW9dFvXM=
Address = 10.6.0.3/24
DNS = 1.1.1.1
[Peer]
PublicKey = mCK/FAHGtXFBNLS5WpHhSPEBvZRwY09HohD1YkNCNSI=
PresharedKey = JdtJFaWUG2ECAfLX05WCyz/rrcs6VWFkVgnvEqnqhHo=
Endpoint = 158.43.56.3:51820
### AllowedIPs = 0.0.0.0/0, ::0/0
AllowedIPs = 172.16.0.10/32
AllowedIPs = 10.6.0.0/24
PersistentKeepalive = 25
A seguir, compartilho o estado da infraestrutura
Do servidorStatus do servidor Pastebin
Do roteador com fio RaspberryStatus de framboesa Pastebin
Testes
De a a b funciona
ubuntu@instance-20210915-wireguard:~$ ping 10.6.0.5
PING 10.6.0.5 (10.6.0.5) 56(84) bytes of data.
64 bytes from 10.6.0.5: icmp_seq=1 ttl=64 time=75.1 ms
64 bytes from 10.6.0.5: icmp_seq=2 ttl=64 time=74.8 ms
^C
--- 10.6.0.5 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 74.772/74.920/75.069/0.148 ms
De a para ba não funciona
ubuntu@instance-20210915-wireguard:~$ ping 172.16.0.1
PING 172.16.0.1 (172.16.0.1) 56(84) bytes of data.
^C
--- 172.16.0.1 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3075ms
De a a c funciona
ubuntu@instance-20210915-wireguard:~$ ping 10.6.0.3
PING 10.6.0.3 (10.6.0.3) 56(84) bytes of data.
64 bytes from 10.6.0.3: icmp_seq=1 ttl=64 time=78.5 ms
64 bytes from 10.6.0.3: icmp_seq=2 ttl=64 time=119 ms
64 bytes from 10.6.0.3: icmp_seq=3 ttl=64 time=77.9 ms
^C
--- 10.6.0.3 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 77.888/91.816/119.047/19.256 ms
De b a a funciona
ubuntu@ubuntu:~$ ping 10.6.0.1
PING 10.6.0.1 (10.6.0.1) 56(84) bytes of data.
64 bytes from 10.6.0.1: icmp_seq=1 ttl=64 time=74.3 ms
64 bytes from 10.6.0.1: icmp_seq=2 ttl=64 time=74.5 ms
^C
--- 10.6.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 74.334/74.396/74.459/0.062 ms
De c para a funciona
user@MacBook-Pro-user Downloads % ping 10.6.0.1
PING 10.6.0.1 (10.6.0.1): 56 data bytes
64 bytes from 10.6.0.1: icmp_seq=0 ttl=64 time=80.921 ms
64 bytes from 10.6.0.1: icmp_seq=1 ttl=64 time=78.086 ms
64 bytes from 10.6.0.1: icmp_seq=2 ttl=64 time=91.625 ms
^C
--- 10.6.0.1 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 78.086/83.544/91.625/5.830 ms
De b para c não funciona
ubuntu@ubuntu:~$ ping 10.6.0.3
PING 10.6.0.3 (10.6.0.3) 56(84) bytes of data.
From 10.6.0.1 icmp_seq=1 Destination Host Prohibited
From 10.6.0.1 icmp_seq=2 Destination Host Prohibited
^C
--- 10.6.0.3 ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1002ms
De c para b não funciona
user@MacBook-Pro-user Downloads % ping 10.6.0.5
PING 10.6.0.5 (10.6.0.5): 56 data bytes
92 bytes from 10.6.0.1: Dest Unreachable, Bad Code: 10
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
4 5 00 5400 25f3 0 0000 3f 01 41a3 10.6.0.3 10.6.0.5
Request timeout for icmp_seq 0
92 bytes from 10.6.0.1: Dest Unreachable, Bad Code: 10
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
4 5 00 5400 a5cc 0 0000 3f 01 c1c9 10.6.0.3 10.6.0.5
Request timeout for icmp_seq 1
^C
--- 10.6.0.5 ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss
De b para ba funciona!!
ubuntu@ubuntu:~$ ping 172.16.0.10
PING 172.16.0.10 (172.16.0.10) 56(84) bytes of data.
64 bytes from 172.16.0.10: icmp_seq=1 ttl=64 time=74.6 ms
64 bytes from 172.16.0.10: icmp_seq=2 ttl=64 time=74.5 ms
^C
--- 172.16.0.10 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 74.455/74.541/74.627/0.086 ms
Pois bem, o objetivo é conseguir atingir pelo menos do IP 10.6.0.1 ao 172.16.0.XX.
Usando o OpenVPN consigo definir a infraestrutura sem problemas, mas a largura de banda é péssima.
Sou péssimo em trabalhar com infraestruturas de rede, desculpe.
Qual é o próximo?
Use Nginx para consumir serviços e implantar Apache Airflow para processar as informações que eu gero em minha LAN.
desde já, obrigado
Edit: eu postei antes no site errado