Supponiamo di avere 4 router interconnessi tra di loro, R0-R1-R2-R3 (come nella figura) e di voler offrire connettività (accesso ad internet e/o risorse locali) ad un terminale connesso su R3:
Procediamo come segue:
Sul router R0
- Configuriamo il router in modo che possa avere connettività internet:
- Codice: Seleziona tutto
/ip address
add address=192.168.1.254/24 interface=ether1
add address=192.168.200.1/30 interface=ether2
/ip route
add dst-address=0.0.0.0 gateway=192.168.1.1
/ip firewall nat add chain=srcnat out-interface=ether1 action=masquerade
/system identity set name=R0
- Attiviamo OSPF:
- Codice: Seleziona tutto
/routing ospf instance
set distribute-default=always-as-type-1 name=R0 redistribute-connected=as-type-1 \
router-id=192.168.200.1
/routing ospf network add area=backbone network=192.168.200.0/30
Sul router R1
- Aggiungiamo le subnet
- Codice: Seleziona tutto
/ip address
add address=192.168.200.2/30 interface=ether1
add address=192.168.201.1/30 interface=ether2
/system identity set name=R1
- Attiviamo OSPF
- Codice: Seleziona tutto
/routing ospf area add area-id=0.0.0.1 name=area1
/routing ospf instance set name=R1 redistribute-connected=as-type-1 router-id=192.168.200.2
/routing ospf network
add area=backbone network=192.168.200.0/30
add area=area1 network=192.168.201.0/30
Sul router R2
- Aggiungiamo le subnet
- Codice: Seleziona tutto
/ip address
add address=192.168.201.2/30 interface=ether1
add address=192.168.202.1/30 interface=ether2
/system identity set name=R2
- Attiviamo OSPF
- Codice: Seleziona tutto
/routing ospf area
add area-id=0.0.0.1 name=area1
/routing ospf instance
set name=R2 redistribute-connected=as-type-1 router-id=192.168.201.2
/routing ospf network
add area=area1 network=192.168.201.0/30
add area=area2 network=192.168.202.0/30
Con questi step R0 R1 ed R2 inizieranno a scambiarsi i LSas fino a popolare la main routing table con tutte le rotte (con la dicitura DAo, dynamic active ospf, con distance 110 ) che sono state decise nelle instance per ogni router (nel nostro caso soltanto le connected route con distance 0).
Per interconnettere R3 che appartiene ad una area differente da "area1" è necessario instaurare un virtual-link tra R1 ed R2 in modo da garantire la stretta connessione alla backbone area.
Per fare ciò sarebbe necessario (semplicemente) attivare un virtual link utilizzando la sezione:
routing ospf virtual-link
imposteremo come transit-area "area1" e come neighbor ID il router adiacente (sia su R1 che su R2)
Putroppo questa funzione è affetta da bug a cominciare dalla versione 4.x fino alla 6.x (nella 3.30 funziona egregiamente)
Pertanto in questi casi si rende necessario l'utilizzo di un tunnel per collegare la backbone area all'area2, come segue:
Sul router R1
- Instauriamo un tunnel EOIP Verso R2
- Codice: Seleziona tutto
/interface eoip add local-address=192.168.201.1 name=eoip-tunnel1 \
remote-ddress=192.168.201.2 tunnel-id=1
- Assegniamo un indirizzo ip a questa nuova interfaccia
- Codice: Seleziona tutto
/ip address add address=192.168.255.1/30 interface=eoip-tunnel1
- Aggiungiamo la network in ospf
- Codice: Seleziona tutto
/routing ospf network add area=backbone network=192.168.255.0/30
Sul router R2
- Instauriamo un tunnel EOIP Verso R1
- Codice: Seleziona tutto
/interface eoip
add local-address=192.168.201.2 name=eoip-tunnel1 remote-address=192.168.201.1 tunnel-id=1
- Assegniamo un indirizzo ip a questa nuova interfaccia
- Codice: Seleziona tutto
/ip address add address=192.168.255.2/30 interface=eoip-tunnel1
- Aggiungiamo la network compreso l'area2 in ospf
- Codice: Seleziona tutto
/routing ospf network add area=backbone network=192.168.255.0/30
/routing ospf area add area-id=0.0.0.2 name=area2
Fatto ciò possiamo passare a configurare il router R3
Sul router R3
- Aggiungiamo le subnet
- Codice: Seleziona tutto
/ip address
add address=192.168.202.2/30 interface=ether1
add address=192.168.203.1/24 comment=HOST interface=ether2
/system identity
set name=R3
- Attiviamo OSPF
- Codice: Seleziona tutto
/routing ospf area add area-id=0.0.0.2 name=area2
/routing ospf instance set name=R3 redistribute-connected=as-type-1 router-id=192.168.202.2
/routing ospf network
add area=area2 network=192.168.202.0/30
Collegandoci all'interfaccia ether2 avremo la facoltà di poter raggiungere tutte le risorse, sia in quella rete che verso internet.
La guida appena illustrata è soltanto a scopo dimostrativo volta a capire il funzionamento di questo protocollo, pertanto è esclusa qualsiasi forma di configurazione avanzata.
Per poter comprendere al meglio questa guida o OSPF è possibile consultare il wiki ufficiale dove è possibile visionare il case study: OSPF Case Study, oppure consultare la rfc2328 sul portale del ietf.
Configurazioni veloci (copia e incolla):
RO
- Codice: Seleziona tutto
/ip address
add address=192.168.1.254/24 interface=ether1
add address=192.168.200.1/30 interface=ether2
/ip route
add dst-address=0.0.0.0 gateway=192.168.1.1
/ip firewall nat add chain=srcnat out-interface=ether1 action=masquerade
/system identity set name=R0
/routing ospf instance
set distribute-default=always-as-type-1 name=R0 redistribute-connected=as-type-1 \
router-id=192.168.200.1
/routing ospf network add area=backbone network=192.168.200.0/30
R1
- Codice: Seleziona tutto
/ip address
add address=192.168.200.2/30 interface=ether1
add address=192.168.201.1/30 interface=ether2
/system identity set name=R1
/routing ospf area add area-id=0.0.0.1 name=area1
/routing ospf instance set name=R1 redistribute-connected=as-type-1 router-id=192.168.200.2
/routing ospf network
add area=backbone network=192.168.200.0/30
add area=area1 network=192.168.201.0/30
/routing ospf network add area=backbone network=192.168.255.0/30
/interface eoip add local-address=192.168.201.1 name=eoip-tunnel1 \
remote-ddress=192.168.201.2 tunnel-id=1
/ip address add address=192.168.255.1/30 interface=eoip-tunnel1
R2
- Codice: Seleziona tutto
/ip address
add address=192.168.201.2/30 interface=ether1
add address=192.168.202.1/30 interface=ether2
/system identity set name=R2
/routing ospf area
add area-id=0.0.0.1 name=area1
add area-id=0.0.0.2 name=area2
/routing ospf instance
set name=R2 redistribute-connected=as-type-1 router-id=192.168.201.2
/routing ospf network
add area=area1 network=192.168.201.0/30
add area=area2 network=192.168.202.0/30
add area=backbone network=192.168.255.0/30
/interface eoip
add local-address=192.168.201.2 name=eoip-tunnel1 remote-address=192.168.201.1 tunnel-id=1
/ip address add address=192.168.255.2/30 interface=eoip-tunnel1
R3
- Codice: Seleziona tutto
/ip address
add address=192.168.202.2/30 interface=ether1
add address=192.168.203.1/24 comment=HOST interface=ether2
/system identity
set name=R3
/routing ospf area add area-id=0.0.0.2 name=area2
/routing ospf instance set name=R3 redistribute-connected=as-type-1 router-id=192.168.202.2
/routing ospf network
add area=area2 network=192.168.202.0/30