본문으로 바로가기
반응형
정적 경로 (Static Route)

특정 목적지 네트워크로 가는 경로를 관리자가 직접 지정하는 방법을 정적 경로 (Static Route)라고 한다. 일반적으로 규모가 작은 네트워크에서 주로 정적 경로를 사용하고 있다.

  • 참고 Topology


기본 설정, 및 IP 설정은 생략.

Static Route Settings

기본 설정 후 show ip route 명령어를 통해 R1의 라우팅 테이블을 확인한다.
R1#sh ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is not set

      1.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C        1.1.10.0/24 is directly connected, FastEthernet0/0
L        1.1.10.1/32 is directly connected, FastEthernet0/0
C        1.1.12.0/24 is directly connected, Serial1/1
L        1.1.12.1/32 is directly connected, Serial1/1

R1과 같은 R2, R3도 라우팅 테이블이 비슷하게 되어있는 것을 확인할 수 있다. 여기서 R2 s1/1에 ping을 보내면 정상적으로 ping이 가지만, R2 s1/2, R3는 ping이 가지 않는다. 이유는 위의 R1의 라우팅 테이블에 R2 s1/2와 R3에 관한 네트워크 정보가 없기 때문이다.

R1#ping 1.1.12.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.12.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/19/24 ms
R1#
R1#ping 1.1.20.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.20.2, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)

R1에다가 ip route 명령어를 사용하여 정적 경로를 지정해준다. ip route <destination network ip address> <destination network subnet-mask> <next-hop ip address> 쉽게 설명해서, <destination network ip address> <destination network subnet-mask> 여기로 가고 싶으면 <next-hop ip address> 이 방향으로 나가면 된다라는 뜻이다.

R1(config)#ip route 1.1.20.0 255.255.255.0 1.1.12.2
R1(config)#ip route 1.1.23.0 255.255.255.0 1.1.12.2
R1(config)#ip route 1.1.30.0 255.255.255.0 1.1.12.2

1.1.20.0 255.255.255.0의 네트워크로 가고 싶으면 1.1.12.2를 통해서 나가면 된다라는 뜻이다. 마찬가지, 1.1.23.0과 1.1.30.0도 1.1.12.2를 통해서 나가야 도착할 수 있으므로 1.1.12.2를 입력해준다. 입력 후 라우팅 테이블을 확인해보면 Static의 약자인 S로 1.1.20.0, 1.1.23.0, 1.1.30.0이 입력되어있는 것을 확인할 수 있다.

R1#sh ip route    
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is not set

      1.0.0.0/8 is variably subnetted, 7 subnets, 2 masks
C        1.1.10.0/24 is directly connected, FastEthernet0/0
L        1.1.10.1/32 is directly connected, FastEthernet0/0
C        1.1.12.0/24 is directly connected, Serial1/1
L        1.1.12.1/32 is directly connected, Serial1/1
S        1.1.20.0/24 [1/0] via 1.1.12.2
S        1.1.23.0/24 [1/0] via 1.1.12.2
S        1.1.30.0/24 [1/0] via 1.1.12.2
정적 경로이므로 AD(Administrative Distance)값이 1로 나와있으며, via는 ~를 통해서 이다. 즉, 1.1.20.0/24 네트워크로 가고싶으면 1.1.12.2를 통해서 갈 수 있다는 뜻이다. R2도, R3도 같은식으로 설정해준다.
R2(config)#ip route 1.1.10.0 255.255.255.0 1.1.12.1
R2(config)#ip route 1.1.30.0 255.255.255.0 1.1.23.3

R3(config)#ip route 1.1.10.0 255.255.255.0 1.1.23.2
R3(config)#ip route 1.1.12.0 255.255.255.0 1.1.23.2
R3(config)#ip route 1.1.20.0 255.255.255.0 1.1.23.2
R2#sh ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is not set

      1.0.0.0/8 is variably subnetted, 8 subnets, 2 masks
S        1.1.10.0/24 [1/0] via 1.1.12.1
C        1.1.12.0/24 is directly connected, Serial1/1
L        1.1.12.2/32 is directly connected, Serial1/1
C        1.1.20.0/24 is directly connected, FastEthernet0/0
L        1.1.20.2/32 is directly connected, FastEthernet0/0
C        1.1.23.0/24 is directly connected, Serial1/2
L        1.1.23.2/32 is directly connected, Serial1/2
S        1.1.30.0/24 [1/0] via 1.1.23.3

R3#sh ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is not set

      1.0.0.0/8 is variably subnetted, 7 subnets, 2 masks
S        1.1.10.0/24 [1/0] via 1.1.23.2
S        1.1.12.0/24 [1/0] via 1.1.23.2
S        1.1.20.0/24 [1/0] via 1.1.23.2
C        1.1.23.0/24 is directly connected, Serial1/2
L        1.1.23.3/32 is directly connected, Serial1/2
C        1.1.30.0/24 is directly connected, FastEthernet0/0
L        1.1.30.3/32 is directly connected, FastEthernet0/0
3개의 라우터에 설정 후 R1에서 R2, R3의 네트워크로 ping을 보내면 빠지지 않고 정상적으로 가는 것을 확인할 수 있다.
R1#ping 1.1.20.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.20.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/11/16 ms
R1#ping 1.1.23.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.23.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/9/12 ms
R1#ping 1.1.30.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.30.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/28/40 ms


Loopback Interface

루프백 인터페이스논리적인 인터페이스로, 여러 가지 설정에서 Router ID로 사용되며 테스트를 위한 추가 네트워크를 만들 때도 사용된다. 또한 장비 자신을 의미하는 루프백 주소, CSU 등에서 신호를 되돌려주는 루프백 테스트 등과 같이 사용된다. 각 라우터에 interface loopback 명령어를 사용하여 루프백 인터페이스를 추가해준다.

R1(config)#int lo 0
R1(config-if)#
*Aug  4 08:50:13.423: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
R1(config-if)#ip add 1.1.1.1 255.255.255.0
R1(config-if)#

R2(config)#int lo 0
R2(config-if)#
*Aug  4 08:50:38.291: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
R2(config-if)#ip add 1.1.2.2 255.255.255.0
R2(config-if)#

R3(config)#int lo 0
R3(config-if)#
*Aug  4 08:50:52.151: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
R3(config-if)#ip add 1.1.3.3 255.255.255.0
R3(config-if)#
루프백 번호는 0부터 21억 사이의 적당한 번호를 사용한다. 보통은 인터페이스를 하나만 만드는 경우에는 0을 사용하며, 위의 시스템 메세지 (%LINEPROTO-5-UPDOWN)와 같이 루프백 인터페이스에 들어가게 되면 자동으로 상태(state)가 UP으로 동작하게 되므로 no shutdown을 해줄 필요가 없다. 설정 후 R1의 라우팅 테이블을 확인해보면 lo 0의 루프백 인터페이스가 입력되어있는 것을 확인할 수 있다.
R1#sh ip route 
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is not set

      1.0.0.0/8 is variably subnetted, 9 subnets, 2 masks
C        1.1.1.0/24 is directly connected, Loopback0
L        1.1.1.1/32 is directly connected, Loopback0
C        1.1.10.0/24 is directly connected, FastEthernet0/0
L        1.1.10.1/32 is directly connected, FastEthernet0/0
C        1.1.12.0/24 is directly connected, Serial1/1
L        1.1.12.1/32 is directly connected, Serial1/1
S        1.1.20.0/24 [1/0] via 1.1.12.2
S        1.1.23.0/24 [1/0] via 1.1.12.2
S        1.1.30.0/24 [1/0] via 1.1.12.2
R1에서 R2와 R3에 연결된 loopback Interface에 접속하기 위해서도 반드시 라우팅이 필요하다.


축약을 이용한 Static Route 설정

위와 같이 Static Route를 설정할 때 일일이 정적 경로를 설정하지 않고, 축약을 이용하여 정적 경로를 설정하면 하나의 정적 라우팅 명렁어로 특정 네트워크 경로를 설정할 수 있다.


토플로지의 네트워크를 확인해보면 1.1.0.0/16 으로 축약이 가능한 것을 확인할 수 있다.
R1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#ip route 1.1.0.0 255.255.0.0 1.1.12.2
위와 같이 입력 후 R1의 라우팅 테이블을 확인해보면 1.1.0.0/16으로 라우팅이 된 것을 확인할 수 있다.
R1#sh ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is not set

      1.0.0.0/8 is variably subnetted, 10 subnets, 3 masks
S        1.1.0.0/16 [1/0] via 1.1.12.2
C        1.1.1.0/24 is directly connected, Loopback0
L        1.1.1.1/32 is directly connected, Loopback0
C        1.1.10.0/24 is directly connected, FastEthernet0/0
L        1.1.10.1/32 is directly connected, FastEthernet0/0
C        1.1.12.0/24 is directly connected, Serial1/1
L        1.1.12.1/32 is directly connected, Serial1/1
S        1.1.20.0/24 [1/0] via 1.1.12.2
S        1.1.23.0/24 [1/0] via 1.1.12.2
S        1.1.30.0/24 [1/0] via 1.1.12.2
위와 같이 설정 후 상위에 설정한 R2의 루프백 인터페이스에 ping을 보내면 정상적으로 핑이 가는 것을 확인할 수 있다. 그러나 R3의 lo로 ping을 보내면 U(Unreached)가 뜨면서 핑이 빠지는 것을 확인할 수 있는데 그 이유는 R1에서 R2로 가는 1.1.0.0/16 네트워크가 라우팅 테이블에 있어서 통신이 되지만 R2에서 R3로 가는 1.1.0.0/16 네트워크가 라우팅 테이블에 없기 때문에 Unreachable이 뜨는 것이다. 고로 R3까지 핑이 가게 하기 위해서는 R2에 1.1.0.0/16 네트워크를 라우팅 테이블에 추가해줘야한다.


디폴트 루트를 이용한 Static Route 설정

전송하려는 패킷의 목적지가 라우팅 테이블에 존재하지 않을 때 그 패킷을 전송하는 곳을 디폴트 루트(Default Route)라고 한다. 기본적으로 라우터는 목적지에 라우팅 테이블에 존재하지 않으면 모든 패킷을 차단하지만 디폴트 루트가 있으면 디폴트 루트를 통해서 전송해버린다.


ip route 0.0.0.0 0.0.0.0 <next hop ip address> 명령어를 사용하여 R3에 디폴트 루트를 설정한다.

R3(config)#ip route 0.0.0.0 0.0.0.0 1.1.23.2
R3(config)#exit
R3#sh ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is 1.1.23.2 to network 0.0.0.0

S*    0.0.0.0/0 [1/0] via 1.1.23.2
      1.0.0.0/8 is variably subnetted, 9 subnets, 2 masks
C        1.1.3.0/24 is directly connected, Loopback0
L        1.1.3.3/32 is directly connected, Loopback0
S        1.1.10.0/24 [1/0] via 1.1.23.2
S        1.1.12.0/24 [1/0] via 1.1.23.2
S        1.1.20.0/24 [1/0] via 1.1.23.2
C        1.1.23.0/24 is directly connected, Serial1/2
L        1.1.23.3/32 is directly connected, Serial1/2
C        1.1.30.0/24 is directly connected, FastEthernet0/0
L        1.1.30.3/32 is directly connected, FastEthernet0/0

설정 후 R3의 라우팅 테이블을 확인하면 Gateway of last resort is 1.1.23.2 to network 0.0.0.0로 디폴트 루트로 설정된 것을 확인할 수 있으며, 아래의 S*에도 디폴트 루트를 확인할 수 있다. *은 Codes에 나와있듯이 candidate default, 디폴트로 당선된, 즉 디폴트로 설정된 것을 확인할 수 있다. 설정 후 R2의 lo인 1.1.2.2로 ping을 보내면 성공하는 것을 확인할 수 있으나 다른 IP들은 모두 U(Unrechable)이 뜨는 것을 확인할 수 있다. 이와 같은 디폴트 루트는 라우팅 기능이 있는 L3 장비에서 주로 사용된다.


라우팅 기능 비활성화

no ip routing 명령어를 통해서 라우팅 기능을 비활성화 할 수 있다. 본 명령어는 정적 경로 외에서도 설정할 수 있는 명령어다.

R3#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R3(config)#no ip routing
비활성화 후 라우팅 테이블을 확인하면 'ICMP redirect cache is empty' 라고 나오며 라우팅 테이블이 없는 것을 확인할 수 있다.
R3#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R3#sh ip route
Default gateway is not set

Host               Gateway           Last Use    Total Uses  Interface
ICMP redirect cache is empty

Default Gateway 설정
위와 같은 라우팅 테이블이 없는, L2장비와 같은 환경에서 사용하는 것이 바로 Default Gateway(디폴트 게이트웨이)다. 디폴트 게이트웨이는 L2장비와 같은 환경에서 Default Route(디폴트 루트) 역할을 한다. ip default-gateway 명령어를 사용하여 디폴트 게이트웨이를 설정해준다.
R3#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R3(config)#ip default-gateway 1.1.23.2
설정 후 라우팅 테이블을 확인해보면 위의 no ip routing상황의 Default gateway is not set 라우팅 테이블과는 다르게 Default gateway is 1.1.23.2라는 문구가 추가되어있는 것을 확인할 수 있다.
R3#sh ip route
Default gateway is 1.1.23.2

Host               Gateway           Last Use    Total Uses  Interface
ICMP redirect cache is empty


반응형