Next-hop-router

För att konfigurera statisk routing manuellt använder man ip route kommandon följd av destinationens nätverksadress, nätmasken och next-hop routers IP-adress.

Kommandosyntax

Router(config)# ip route <destinationens nätverksadress och nätmask> <next-hop-router IP>

Generellt sett används next-hop-routerns IP-adress oavsett vilken typ av interface som används. I den nätverkstopologi som visas nedan är tre LAN nätverk anslutna via två seriella interface på routrarna R1, R2 och R3. Totalt finns det fem nätverk i topologin. Det kan också noteras att alla fem nätverk har samma nätmask eller prefix /24, vilket innebär att exemplet använder sig av klassbaserad (classful) routing.

Bild 1: Classful routing

Nätverksadresserna har delats upp enligt följande:

  • Klass B nätverksadressen 172.16.0.0/16 har utökats med 8 bitar för att få prefixet /24. I exemplet används 172.16.1.0, 172.16.2.0 och 172.16.3.0.
  • Klass C nätverksadressen 192.168.0.0/24 har delats upp fullständigt i tredje oktetten. I exemplet används 192.168.1.0 och 192.168.2.0

Konfigurationer

  • Router> enable
  • Router# configure terminal
  • Router(config)# hostname R1
  • R1(config)# service password-encryption
  • R1(config)# no ip domain-lookup
  • R1(config)# security passwords min-length 10
  • R1(config)# login block-for 120 attempts 2 within 30
  • R1(config)# enable secret digintoP@55
  • R1(config)# username admin1 privilege 15 secret admin1P@55
  • R1(config)# username admin1 privilege 15 secret admin1P@55
  • R1(config)# ip domain-name diginto.se
  • R1(config)# line console 0
  • R1(config-line)# login local
  • R1(config-line)# logging synchronous
  • R1(config-line)# exec-timeout 60
  • R1(config-line)# exit
  • R1(config-)# line vty 0 4
  • R1(config-line)# login local
  • R1(config-line)# logging synchronous
  • R1(config-line)# exec-timeout 60
  • R1(config-line)# transport input ssh
  • R1(config-line)# exit
  • R1(config)# crypto key generate rsa general-keys modulus 1024
  • R1(config)# ip ssh version 2
  • R1(config)# ip ssh time-out 120
  • R1(config)# interface fa0/0
  • R1(config-if)# description Connected to LAN 1
  • R1(config-if)# ip address 172.16.3.1 255.255.255.0
  • R1(config-if)# no shutdown
  • R1(config-if)# exit
  • R1(config)# interface s0/0/0
  • R1(config-if)# description DCE Connected to R2
  • R1(config-if)# ip address 172.16.2.1 255.255.255.0
  • R1(config-if)# clock rate 128000
  • R1(config-if)# no shutdown
  • R1(config-if)# exit
  • R1(config)# ip route 172.16.1.0 255.255.255.0 172.16.2.2
  • R1(config)# ip route 192.168.1.0 255.255.255.0 172.16.2.2
  • R1(config)# ip route 192.168.2.0 255.255.255.0 172.16.2.2
  • R1(config)# exit
  • R1# show ip interface brief
  • R1# show ip route static
  • R1# copy running-config startup-config
  • Router> enable
  • Router# configure terminal
  • Router(config)# hostname R2
  • R2(config)# service password-encryption
  • R2(config)# no ip domain-lookup
  • R2(config)# security passwords min-length 10
  • R2(config)# login block-for 120 attempts 2 within 30
  • R2(config)# enable secret digintoP@55
  • R2(config)# username admin1 privilege 15 secret admin1P@55
  • R2(config)# username admin1 privilege 15 secret admin1P@55
  • R2(config)# ip domain-name diginto.se
  • R2(config)# line console 0
  • R2(config-line)# login local
  • R2(config-line)# logging synchronous
  • R2(config-line)# exec-timeout 60
  • R2(config-line)# exit
  • R2(config-)# line vty 0 4
  • R2(config-line)# login local
  • R2(config-line)# logging synchronous
  • R2(config-line)# exec-timeout 60
  • R2(config-line)# transport input ssh
  • R2(config-line)# exit
  • R2(config)# crypto key generate rsa general-keys modulus 1024
  • R2(config)# ip ssh version 2
  • R2(config)# ip ssh time-out 120
  • R2(config)# interface fa0/0
  • R2(config-if)# description Connected to LAN 2
  • R2(config-if)# ip address 172.16.1.1 255.255.255.0
  • R2(config-if)# no shutdown
  • R2(config-if)# exit
  • R2(config)# interface s0/0/0
  • R2(config-if)# description Connected to R1
  • R2(config-if)# ip address 172.16.2.2 255.255.255.0
  • R2(config-if)# no shutdown
  • R2(config-if)# exit
  • R2(config)# interface s0/0/1
  • R2(config-if)# description DCE Connected to R3
  • R2(config-if)# ip address 192.168.1.2 255.255.255.0
  • R2(config-if)# clock rate 128000
  • R2(config-if)# no shutdown
  • R2(config-if)# exit
  • R2(config)# ip route 172.16.3.0 255.255.255.0 172.16.2.1
  • R2(config)# ip route 192.168.2.0 255.255.255.0 192.168.1.1
  • R2(config)# exit
  • R2# show ip interface brief
  • R2# show ip route static
  • R2# copy running-config startup-config
  • Router> enable
  • Router# configure terminal
  • Router(config)# hostname R3
  • R3(config)# service password-encryption
  • R3(config)# no ip domain-lookup
  • R3(config)# security passwords min-length 10
  • R3(config)# login block-for 120 attempts 2 within 30
  • R3(config)# enable secret digintoP@55
  • R3(config)# username admin1 privilege 15 secret admin1P@55
  • R3(config)# username admin1 privilege 15 secret admin1P@55
  • R3(config)# ip domain-name diginto.se
  • R3(config)# line console 0
  • R3(config-line)# login local
  • R3(config-line)# logging synchronous
  • R3(config-line)# exec-timeout 60
  • R3(config-line)# exit
  • R3(config-)# line vty 0 4
  • R3(config-line)# login local
  • R3(config-line)# logging synchronous
  • R3(config-line)# exec-timeout 60
  • R3(config-line)# transport input ssh
  • R3(config-line)# exit
  • R3(config)# crypto key generate rsa general-keys modulus 1024
  • R3(config)# ip ssh version 2
  • R3(config)# ip ssh time-out 120
  • R3(config)# interface fa0/0
  • R3(config-if)# description Connected to LAN 3
  • R3(config-if)# ip address 192.168.2.1 255.255.255.0
  • R3(config-if)# no shutdown
  • R3(config-if)# exit
  • R3(config)# interface s0/0/1
  • R3(config-if)# ip address 192.168.1.1 255.255.255.0
  • R3(config-if)# no shutdown
  • R3(config-if)# exit
  • R3(config)# ip route 172.16.1.0 255.255.255.0 192.168.1.2
  • R3(config)# ip route 172.16.2.0 255.255.255.0 192.168.1.2
  • R3(config)# ip route 172.16.3.0 255.255.255.0 192.168.1.2
  • R3(config)# exit
  • R3# show ip interface brief
  • R3# show ip route static
  • R3# copy running-config startup-config

Aggregering av statiska routes

I routing-tabeller finns en stor mängd information att hantera och att navigera genom denna information för att hitta rätt IP-adress är resurskrävande. För att underlätta detta kan man använda en representativ IP-adress istället för flera individuella IP-adresser. Detta koncept kallas ”route summarization” på engelska.

På routern R3 har vi konfigurerat tre statiska route, 172.16.1.0, 172.16.2.0 och 172.16.3.0. Dessa nätverksadresser kan aggregeras till en enda nätverksadress, 172.16.0.0. Samtidigt reduceras prefixet från /24 till /22. Metoden illustreras här nedan:

Illustrationen ger oss en arbetsmetod för att beräkna ut vägaggregering (route summarization).

  1. Skriv nätverksadresserna i binärt format.
  2. Kontrollera från vänster till höger vilka bitar i adresserna som är olika.
  3. Hitta gränsen där bitarna skiljer sig åt för alla adresser (inte lika med bitarna till vänster).
  4. Räkna ut antalet gemensamma bitar för alla adresser, vilket utgör prefixet.
  5. Sätt alla icke-gemensamma bitar till noll för att få den summerade routen.

Nu kan de tre statiska vägarna som programmerades in på router R3 ersättas med en enda statisk route. Först tas de tre statiska routerna bort och därefter skapas en ny statisk väg (route):

  • R3(config)# no ip route 172.16.1.0  255.255.255.0  192.168.1.2
  • R3(config)# no ip route 172.16.2.0  255.255.255.0  192.168.1.2
  • R3(config)# no ip route 172.16.3.0  255.255.255.0  192.168.1.2
  • R3(config)# ip route 172.16.0.0  255.255.252.0  192.168.1.2

Default statisk route

PC1 är ansluten till det lokala LANet på R1, vilket kan betraktas som ett ”stubb-nätverk” på svenska. Det innebär att LAN 1 har endast en utväg till andra nätverk via router R2. Genom att konfigurera denna enda utväg som en ”default route” kommer routern R1 att skicka alla paket direkt ut genom länken med R2, vilket förenklar och effektiviserar sökningsprocessen.

Bild 4: Default route

Först ska alla befintliga statiska route tas bort:

R1(config)# no ip route 172.16.1.0  255.255.255.0  172.16.2.2
R1(config)# no ip route 192.168.1.0  255.255.255.0 172.16.2.2
R1(config)# no ip route 192.168.2.0  255.255.255.0 172.16.2.2

Därefter implementeras en default route

R1(config)# ip route  0.0.0.0  0.0.0.0  172.16.2.2