Routage du sous-réseau distant Dedibox vers mon infrastructure LAN
Fonctionnel :
DediBox LAN <--> OpenVPN <--> Internet <--> Freebox Home <--> Rooter-01 VM (Debian)
VM Name : Rooter-01 - IP : 192.168.1.252
Installation d'OpenVPN :
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# apt install openvpn
Démarrage & Activation au démarrage d'OpenVPN
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# systemctl start openvpn && systemctl enable openvpn
Installation d'IPTables
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# apt install iptables iptables-persistent
Activation d'IP Forwarding sur Debian :
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward=1
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# sysctl -p /etc/sysctl.conf
Configuration des routes sur IPTables :
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# iptables -t nat -I PREROUTING -i ens18 -d 10.35.42.0 -j DNAT --to-destination 10.8.0.1
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# iptables-save > /etc/iptables/rules.v4
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# screen
root@Rooter-01[PROD:192.168.1.252][0][11:42:27]:~# openvpn --config ~/OpenVPN_Certs/Infra.ovpn
root@Cli-01[PROD:192.168.1.48][0][11:50:27]:~# ip route add 10.35.42.0/24 via 192.168.1.252 dev ens18
Pour rajouter la route de manière persistante, et qu'elle soit prise en compte à chaque reboot :
root@Cli-01[PROD:192.168.1.252][0][11:42:27]:~# vi /etc/network/if-up.d/route
#!/bin/bash
route add -net 10.35.42.0/24 gw 192.168.1.252 dev ens18
Le rendre executable :
root@Cli-01[PROD:192.168.1.252][0][11:42:27]:~# chmod +x /etc/network/if-up.d/route
Done.