Table des matières

Simulations réseau et essais techniques

Quelques essais d'archi faits en octobre et novembre 2015 avec l'outil GNS3.

Hypothèses

Schémas

:technique:archives:capture-simu-gns3.png

Problématiques à envisager

Problèmes rencontrés

Solution en routage statique

Configs

hosts
127.0.0.1	localhost
192.168.90.222	rt_mitterand
192.168.91.222	rt_zac
6.5.4.1		rt_tls
rt_tls_network-interface
# The loopback network interface
auto lo
iface lo inet loopback
	up ip addr add 6.5.4.1 dev $IFACE
 
auto eth0
iface eth0 inet static
	# Pour les besoin de la simulation, NAT de mon aDSL, sinon rmmod iptables conseillé, cf h7
	address 192.168.1.42
	netmask 255.255.255.0
	gateway 192.168.1.254
	up sysctl -w net.ipv4.ip_forward=1
	up iptables -t nat -F POSTROUTING
	up iptables -t nat -A POSTROUTING -o $IFACE -j MASQUERADE
 
auto eth1
iface eth1 inet static
	address 192.168.90.223
	netmask 255.255.255.0
	up ip route add 6.5.4.0/24 via 192.168.90.222
 
auto eth2
iface eth2 inet static
	address 192.168.91.223
	netmask 255.255.255.0
	up ip route add 6.5.5.0/24 via 192.168.91.222
rt_mitterand_network-interface
# The loopback network interface
auto lo
iface lo inet loopback
 
auto eth0
iface eth0 inet static
	address 192.168.90.222
	netmask 255.255.255.0
	gateway 192.168.90.223
 
auto eth1
iface eth1 inet static
	address 172.16.0.1
	netmask 255.255.0.0
 
#auto eth1:253
iface eth1:253 inet static
	address 172.16.0.253
	netmask 255.255.0.0
	up /root/setup_routing.sh
 
auto eth1:254
iface eth1:254 inet static
	address 172.16.0.254
	netmask 255.255.0.0
	up /root/setup_routing.sh
rt_zac_network-interface
# The loopback network interface
auto lo
iface lo inet loopback
 
auto eth0
iface eth0 inet static
	address 192.168.91.222
	netmask 255.255.255.0
	gateway 192.168.91.223
	up sysctl -w net.ipv4.ip_forward=1
 
auto eth1
iface eth1 inet static
	address 172.16.0.2
	netmask 255.255.0.0
 
auto eth1:253
iface eth1:253 inet static
	address 172.16.0.253
	netmask 255.255.0.0
	up /root/setup_routing.sh
 
#auto eth1:254
iface eth1:254 inet static
	address 172.16.0.254
	netmask 255.255.0.0
	up /root/setup_routing.sh
adt1_network-interface
# The loopback network interface
auto lo
iface lo inet loopback
 
# Simule l'antenne en bridge
auto eth0
iface eth0 inet static
	address 172.16.10.10
	netmask 255.255.0.0
 
# Simule le routeur OpenWRT avec IP publiques
auto eth1
iface eth1 inet static
	address 6.5.4.10
	netmask 255.255.255.255
	up ip route replace default via 172.16.0.254 src 6.5.4.10 dev eth0
	up sysctl -w net.ipv4.ip_forward=1
adt2_network-interface
# The loopback network interface
auto lo
iface lo inet loopback
 
# Simle l'antenne en bridge
auto eth0
iface eth0 inet static
	address 172.16.10.11
	netmask 255.255.0.0
 
# Simule le routeur OpenWRT avec IP publiques
auto eth1
iface eth1 inet static
	address 6.5.5.10
	netmask 255.255.255.255
	up ip route replace default via 172.16.0.253 src 6.5.5.10 dev eth0
	up sysctl -w net.ipv4.ip_forward=1

Scripts

setup_routing.sh
#!/bin/bash
 
function adt() {
	adt_num=$1
	adt_etat=$2
	adt_nom=$3
	ip4_nexthop=$4
	ip4_public=$5
	dev=eth1
	SELF=$(basename $0)
	INFO="logger -p notice -t $SELF --"
	CRIT="logger -p crit -t $SELF --"
 
	echo "$ip4_public	${adt_nom}.pub4	adt$adt_num" >> /etc/hosts.adt
	echo "$ip4_nexthop	${adt_nom}.gw4	hop$adt_num" >> /etc/hosts.adt
 
	case $adt_etat in
		actif)
			regex="^$ip4_public via [0-9.]+ dev $dev"
			ip route get $ip4_public | grep -qE "$regex"
			res=$?
			out=$(ip route replace $ip4_public via $ip4_nexthop dev $dev)
			res2=$?
			if [ $res2 -eq 0 ]; then
					if [ $res -eq 1 ]; then
						$INFO "Accès ajouté : adt $*"
					fi
			else
					$CRIT "ERREUR : adt $adt_num $adt_etat $adt_nom : pb remplacement route : '$out'"
			fi
			;;
		resilie)
			out=$(ip route delete $ip4_public 2>&1)
		   	res=$?	
			case $res in
				0) $INFO "Accès supprimé : adt $*" ;;
				2) : ;; # Route non trouvée, routage déjà supprimé
				*) $CRIT "ERREUR : adt $adt_num $adt_etat $adt_nom : pb suppression route : '$out'" ;;
			esac
			;;
		*)
			$CRIT "ERREUR : adt $adt_num $adt_etat $adt_nom : '$adt_etat' n'est pas un état reconnu"
			;;
	esac
}
 
function main() {
		> /etc/hosts.adt
		sysctl -w net.ipv4.ip_forward=1
		source /root/config_adt.sh
		cat /etc/hosts.system /etc/hosts.adt > /etc/hosts
}
 
main
config_adt.sh
#!/bin/bash
# set ts=4
# Généré le 2015-11-29 21:08:50+01:00
 
#adt <num>  <etat>  <NOM_Prenom>           <ip4_nexthop>   <ip4_public>
adt 0001    actif   Dxxxxx_Laurent         172.16.10.10    6.5.4.10
adt 0002    actif   Pxxxxx_Daniel          172.16.10.11    6.5.5.10
#[...]
config_adt_gen.sh
#!/bin/bash
SELF=$(basename $0)
INFO="logger -p notice -t $SELF --"
CRIT="logger -p crit -t $SELF --"
 
TMP=$(mktemp)
ssh automated@chd.sx sudo mysql --defaults-file=/etc/mysql/debian.cnf -BN -D gestion <<< 'SELECT * FROM v_config_adt;' >$TMP
 
if [ $? -eq 0 -a -s $TMP ]
then	$INFO "Base de donnée lue avec succès"
else	$CRIT "Echec de récupération des données depuis la base de données"
	exit 2
fi
 
cat - $TMP >/root/config_adt.sh <<EOT
#!/bin/bash
# set ts=4
# Généré le $DATE
 
#adt <num>  <etat>  <NOM_Prenom>           <ip4_nexthop>   <ip4_public>
EOT
rm $TMP