Cisco IOS ACLの基本的な使い方

スポンサーリンク

Cisco IOSのACLの設定方法をまとめます。ping, tracerouteのプロトコル理解、ルーティングプロトコルの仕様、ワイルドカードの特殊な指定方法など、やや高度は内容が多めです。もともとはCisco CCIE向けの学習コンテンツでしたので、やや実践レベルを超過する内容がある事はご了承ください。

コマンド一覧

このシナリオで重要なコマンド一覧は以下の通りです。

Router(config)# ip access-list extended <acl_name>
Router(config-ext-nacl)# permit udp any any eq rip
Router(config-ext-nacl)# permit eigrp any any
Router(config-ext-nacl)# permit ospf any any
Router(config-ext-nacl)# permit tcp any any eq bgp
Router(config-ext-nacl)# permit tcp any eq bgp any
Router(config-ext-nacl)# permit icmp any any echo
Router(config-ext-nacl)# permit icmp any any echo-reply
Router(config-ext-nacl)# permit icmp any any time-exceeded
Router(config-ext-nacl)# permit icmp any any port-unreachable
Router(config-ext-nacl)# permit udp any any range 33434 33524
Router(config-ext-nacl)# permit icmp any any packet-too-big
Router(config-ext-nacl)# permit gre any any
Router(config-ext-nacl)# permit udp any any eq syslog
Router(config-ext-nacl)# permit udp any any eq snmp
Router(config-ext-nacl)# permit udp any any eq snmptrap
Router(config-ext-nacl)# permit udp any any eq tftp
Router(config-ext-nacl)# permit tcp any any eq www 443
Router(config-ext-nacl)# permit tcp any any eq smtp
Router(config-ext-nacl)# permit tcp any any eq ftp ftp-data

構成図

以下の構成で動作確認を行います。検証の都合上、以下仕様のやや複雑な構成にします。

  • R1, R2間でOSPF neighborを確立します。
  • R2, R3間でiBGP neighborを確立します。
  • R2においてOSPF, BGP間の再配送を行います。
  • R1, R3間でGRE tunnelを確立します。
  • R3に複数のLoopback interfaceを作成します。
 [physical diagram]
            e0/0    e0/1      e0/0    e0/1
    +--------+.1    .2+--------+.2    .3+--------+
    |   R1   +--------+   R2   +--------+   R3  | 
    +--------+        +--------+        +--------+
          192.168.12.0/24   192.168.23.0/24

    Loopback 0        Loopback 0        Loopback 0
    10.1.1.1/32       10.2.2.2/32       10.3.3.3/32

 [gre tunnel]
            tu13      tu13
    +--------+::1    ::2+--------+
    |   R1   +----------+   R3  | 
    +--------+          +--------+
           192.168.13.0/24
 [R1]
interface Tunnel13
 ip address 192.168.13.1 255.255.255.0
 tunnel source Loopback0
 tunnel destination 10.3.3.3
!
router ospf 1
 network 10.1.1.1 0.0.0.0 area 0
 network 192.168.12.1 0.0.0.0 area 0

 [R2]
router ospf 1
 redistribute connected subnets
 redistribute bgp 230 subnets
 network 10.1.1.1 0.0.0.0 area 0
 network 192.168.12.2 0.0.0.0 area 0
!
router bgp 230
 no synchronization
 bgp redistribute-internal
 redistribute ospf 1
 neighbor 192.168.23.3 remote-as 230
 no auto-summary

 [R3]
interface Tunnel13
 ip address 192.168.13.3 255.255.255.0
 tunnel source Loopback0
 tunnel destination 10.1.1.1
!
router bgp 230
 no synchronization
 bgp router-id 10.3.3.3
 redistribute connected
 neighbor 192.168.23.2 remote-as 230
 no auto-summary

設定全文は下記ファイルです。詳細設定は下記を参照ください。

R1
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R1
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
memory-size iomem 5
!
!
ip cef
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface Loopback0
 ip address 10.1.1.1 255.255.255.255
!
interface Tunnel13
 ip address 192.168.13.1 255.255.255.0
 tunnel source Loopback0
 tunnel destination 10.3.3.3
!
interface Ethernet0/0
 ip address 192.168.12.1 255.255.255.0
 half-duplex
!
interface Ethernet0/1
 no ip address
 shutdown
 half-duplex
!
interface Ethernet0/2
 no ip address
 shutdown
 half-duplex
!
interface Ethernet0/3
 no ip address
 shutdown
 half-duplex
!
!
router ospf 1
 log-adjacency-changes
 network 10.1.1.1 0.0.0.0 area 0
 network 192.168.12.1 0.0.0.0 area 0
!
ip http server
ip forward-protocol nd
!
!
!
!
!
!
control-plane
!
!
!
!
mgcp behavior g729-variants static-pt
!
!
!
!
!
line con 0
line aux 0
line vty 0 4
 login
!
!
end
R2
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R2
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
memory-size iomem 5
!
!
ip cef
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface Loopback0
 ip address 10.2.2.2 255.255.255.255
!
interface Ethernet0/0
 ip address 192.168.23.2 255.255.255.0
 half-duplex
!
interface Ethernet0/1
 ip address 192.168.12.2 255.255.255.0
 half-duplex
!
interface Ethernet0/2
 no ip address
 shutdown
 half-duplex
!
interface Ethernet0/3
 no ip address
 shutdown
 half-duplex
!
!
router ospf 1
 log-adjacency-changes
 redistribute connected subnets
 redistribute bgp 230 subnets
 network 10.1.1.1 0.0.0.0 area 0
 network 192.168.12.2 0.0.0.0 area 0
!
router bgp 230
 no synchronization
 bgp log-neighbor-changes
 bgp redistribute-internal
 redistribute ospf 1
 neighbor 192.168.23.3 remote-as 230
 no auto-summary
!
ip http server
ip forward-protocol nd
!
!
!
!
!
!
control-plane
!
!
!
!
mgcp behavior g729-variants static-pt
!
!
!
!
!
line con 0
line aux 0
line vty 0 4
 login
!
!
end
R3
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R3
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
memory-size iomem 5
!
!
ip cef
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
interface Loopback0
 ip address 10.3.3.3 255.255.255.255
!
interface Loopback100
 ip address 172.16.10.3 255.255.255.255
!
interface Loopback101
 ip address 172.16.11.3 255.255.255.255
!
interface Loopback102
 ip address 172.16.12.3 255.255.255.255
!
interface Loopback103
 ip address 172.16.13.3 255.255.255.255
!
interface Loopback104
 ip address 172.16.14.3 255.255.255.255
!
interface Loopback105
 ip address 172.16.15.3 255.255.255.255
!
interface Loopback106
 ip address 172.16.16.3 255.255.255.255
!
interface Loopback107
 ip address 172.16.17.3 255.255.255.255
!
interface Loopback108
 ip address 172.16.18.3 255.255.255.255
!
interface Tunnel13
 ip address 192.168.13.3 255.255.255.0
 tunnel source Loopback0
 tunnel destination 10.1.1.1
!
interface Ethernet0/0
 no ip address
 shutdown
 half-duplex
!
interface Ethernet0/1
 ip address 192.168.23.3 255.255.255.0
 half-duplex
!
interface Ethernet0/2
 no ip address
 shutdown
 half-duplex
!
interface Ethernet0/3
 no ip address
 shutdown
 half-duplex
!
!
router bgp 230
 no synchronization
 bgp router-id 10.3.3.3
 bgp log-neighbor-changes
 redistribute connected
 neighbor 192.168.23.2 remote-as 230
 no auto-summary
!
ip http server
ip forward-protocol nd
!
!
!
!
!
!
control-plane
!
!
!
!
mgcp behavior g729-variants static-pt
!
!
!
!
!
line con 0
line aux 0
line vty 0 4
 login
!
!
end

仕様説明

ルーティングプロトコルの許可

CCIE R&Sの定番の出題がルーティングプロトコルの許可です。ACLを使用する場合はルーティングプロトコルなどの制御パケットをdropしないよう注意を払う必要があります。

IGPを許可する設定は以下の通りです。

Router(config)# ip access-list extended <acl_name>
Router(config-ext-nacl)# permit udp any any eq rip
Router(config-ext-nacl)# permit eigrp any any
Router(config-ext-nacl)# permit ospf any any

BGPを許可する設定は以下の通りです。

Router(config)# ip access-list extended <acl_name>
Router(config-ext-nacl)# permit tcp any any eq bgp
Router(config-ext-nacl)# permit tcp any eq bgp any

BGPは宛先ポートがbgp(179)であるパケットと送信元ポートがbgp(179)であるパケットの両方を許可しなければならない事に注意して下さい。BGP update messageの一部は送信元ポートがbgp(179)となります。

No.     Time        Source                Destination           Protocol Length Info
     32 70.862000   192.168.23.3          192.168.23.2          BGP      154    UPDATE Message

Frame 32: 154 bytes on wire (1232 bits), 154 bytes captured (1232 bits)
Ethernet II, Src: cc:02:0f:b8:00:01 (cc:02:0f:b8:00:01), Dst: cc:01:0f:b8:00:00 (cc:01:0f:b8:00:00)
Internet Protocol Version 4, Src: 192.168.23.3 (192.168.23.3), Dst: 192.168.23.2 (192.168.23.2)
Transmission Control Protocol, Src Port: bgp (179), Dst Port: 58463 (58463), Seq: 84, Ack: 139, Len: 100
Border Gateway Protocol

icmp traceroute

ping, tracerouteを許可するには以下のプロトコルを許可しなければなりません。なお、OSによってping, tracerouteの仕様が異なるため、実践では以下コマンドがいつも有用とは言えません。

Router(config-ext-nacl)# permit icmp any any echo
Router(config-ext-nacl)# permit icmp any any echo-reply
Router(config-ext-nacl)# permit icmp any any time-exceeded
Router(config-ext-nacl)# permit icmp any any port-unreachable
Router(config-ext-nacl)# permit udp any any range 33434 33524 

PMTU Discoveryの理解を確認する出題もよく見ますので、PMTU Discoveryも合わせて理解しておきましょう。(PMTU Discoveryの説明は省略します)

Router(config-ext-nacl)# permit icmp any any packet-too-big

その他プロトコル

その他のプロトコルにも注意する必要があります。例えば、ACLを設定した経路をGRE tunnelが通っているとすればGREを許可しなければなりません。出題される可能性が高いプロトコルをまとめると以下の通りです。FTPに関しては、active modeなのかpassive modeなのかも注意が必要です。

Router(config-ext-nacl)# permit gre any any
Router(config-ext-nacl)# permit udp any any eq syslog
Router(config-ext-nacl)# permit udp any any eq snmp
Router(config-ext-nacl)# permit udp any any eq snmptrap
Router(config-ext-nacl)# permit udp any any eq tftp
Router(config-ext-nacl)# permit tcp any any eq www 443
Router(config-ext-nacl)# permit tcp any any eq smtp
Router(config-ext-nacl)# permit tcp any any eq ftp ftp-data

複雑なwildcard指定

CCIE R&Sの試験では、wildcardの仕様を理解しているかどうかを確認するためにかなり複雑なwildcard指定が求められます。

例えば、以下のようなstandard access-listならば、第一オクテットが奇数であるIPアドレスを表します。

Router(config-std-nacl)# permit 1.0.0.0 254.255.255.255.255

以下のようなstandard access-listならば、150.1.1.0/24, 150.1.3.0/24, 150.1.5.0/24, 150.1.7.0/24を表します。

Router(config-std-nacl)# permit 150.1.1.0 0.0.6.255
</pre
<h2>諸問題の確認</h2>
<h3>設定投入</h3>
<p>
ACLを設定する際は関連するプロトコルを拒否しないように注意を払う必要があります。関連するプロトコルの許可が漏れるとどのよな事態になるのかを観察しましょう。
</p>
<p>
R3 Loopback100 (172.16.10.3)経由の通信のみ許容するような設定をR2に投入します。
</p>

 [R2]
ip access-list extended ACL_FROM_R1
 10 permit ip any host 172.16.10.3
 99 deny ip any any
!
ip access-list extended ACL_FROM_R3
 10 permit ip host 172.16.10.3 any
 99 deny ip any any
!
interface Ethernet 0/1
 ip access-group ACL_FROM_R1 in
!
interface Ethernet 0/0
 ip access-group ACL_FROM_R3 in

動作確認

しばらく待つと、OSPF neighbor, BGP neighborが切断された事が分かります。

 [R2]
R2(config-if)#
*Mar  1 00:13:30.331: %OSPF-5-ADJCHG: Process 1, Nbr 10.1.1.1 on Ethernet0/1 from FULL to DOWN, Neighbor Down: Dead timer expired
*Mar  1 00:15:54.947: %BGP-5-ADJCHANGE: neighbor 192.168.23.3 Down BGP Notification sent
*Mar  1 00:15:54.947: %BGP-3-NOTIFICATION: sent to neighbor 192.168.23.3 4/0 (hold time expired) 0 bytes
R2(config-if)#

ルーティングプロトコルの許可

設定投入

ルーティングプロトコルの許可設定をR2に追加します。

 [R2]
ip access-list extended ACL_FROM_R1
 10 permit ip any host 172.16.10.3
 20 permit ospf any any
 99 deny ip any any
!
ip access-list extended ACL_FROM_R3
 10 permit ip host 172.16.10.3 any
 20  permit tcp any any eq bgp
 30 permit tcp any eq bgp any
 99 deny ip any any
!
interface Ethernet 0/1
 ip access-group ACL_FROM_R1 in
!
interface Ethernet 0/0
 ip access-group ACL_FROM_R3 in

動作確認

しばらく待つと、OSPF neighbor, BGP neighborが確立された旨のメッセージが出力されます。

 [R2]
R2(config-ext-nacl)#
*Mar  1 00:19:39.739: %OSPF-5-ADJCHG: Process 1, Nbr 10.1.1.1 on Ethernet0/1 from LOADING to FULL, Loading Done
R2(config-ext-nacl)#
R2(config-ext-nacl)#
*Mar  1 00:20:33.395: %BGP-5-ADJCHANGE: neighbor 192.168.23.3 Up
R2(config-ext-nacl)#

R3 Loopback100 (172.16.10.3) 経由の通信が可能になった事を確認します。

R3#ping 10.1.1.1 source 172.16.10.3

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 172.16.10.3
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/48/80 ms
R3#

ping traceroute

設定投入

これまでのACLでは許可されたIPアドレス (172.16.10.3) 以外からのping, tracerouteを受け付けません。

 [R3]
R3#ping 10.1.1.1 source 10.3.3.3

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 10.3.3.3
U.U.U
Success rate is 0 percent (0/5)
R3#

ping, tracerouteについては無条件で許可する設定をR2に投入します。

 [R2]
ip access-list extended ACL_FROM_R1
 10 permit ip any host 172.16.10.3
 20 permit ospf any any
 40 permit icmp any any echo
 41 permit icmp any any echo-reply
 42 permit icmp any any time-exceeded
 43 permit icmp any any port-unreachable
 44 permit udp any any range 33434 33524 
 99 deny ip any any
!
ip access-list extended ACL_FROM_R3
 10 permit ip host 172.16.10.3 any
 20 permit tcp any any eq bgp
 30 permit tcp any eq bgp any
 40 permit icmp any any echo
 41 permit icmp any any echo-reply
 42 permit icmp any any time-exceeded
 43 permit icmp any any port-unreachable
 44 permit udp any any range 33434 33524 
 99 deny ip any any
!
interface Ethernet 0/1
 ip access-group ACL_FROM_R1 in
!
interface Ethernet 0/0
 ip access-group ACL_FROM_R3 in

動作確認

ping, tracerouteが可能になった事を確認します。

 [R3]
R3#ping 10.1.1.1 source 10.3.3.3

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 10.3.3.3
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 32/48/68 ms
R3#
R3#
R3#traceroute 10.1.1.1 source 10.3.3.3

Type escape sequence to abort.
Tracing the route to 10.1.1.1

  1 192.168.23.2 40 msec 48 msec 20 msec
  2 192.168.12.1 44 msec *  24 msec
R3#

その他のプロトコル

設定投入

これまでのACLでは、GRE経由の通信が許可されていません。

 [R3]
R3#ping 192.168.13.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.13.1, timeout is 2 seconds:
...
Success rate is 0 percent (0/3)
R3#

GREを許可する設定をR2に追加します。

 [R2]
ip access-list extended ACL_FROM_R1
 10 permit ip any host 172.16.10.3
 20 permit ospf any any
 40 permit icmp any any echo
 41 permit icmp any any echo-reply
 42 permit icmp any any time-exceeded
 43 permit icmp any any port-unreachable
 44 permit udp any any range 33434 33524 
 80 permit gre any any
 99 deny ip any any
!
ip access-list extended ACL_FROM_R3
 10 permit ip host 172.16.10.3 any
 20  permit tcp any any eq bgp
 30 permit tcp any eq bgp any
 40 permit icmp any any echo
 41 permit icmp any any echo-reply
 42 permit icmp any any time-exceeded
 43 permit icmp any any port-unreachable
 44 permit udp any any range 33434 33524 
 80 permit gre any any
 99 deny ip any any
!
interface Ethernet 0/1
 ip access-group ACL_FROM_R1 in
!
interface Ethernet 0/0
 ip access-group ACL_FROM_R3 in

動作確認

GRE経由の通信が可能になった事を確認します。

 [R2]
R3#ping 192.168.13.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.13.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/53/116 ms
R3#

複雑なwildcard指定

設定投入

R3には以下のloopback interfaceが接続させています。

 [R3]
R3#show ip interface brief | include Loopback10
Loopback100                172.16.10.3     YES NVRAM  up                    up  
Loopback101                172.16.11.3     YES NVRAM  up                    up  
Loopback102                172.16.12.3     YES manual up                    up  
Loopback103                172.16.13.3     YES manual up                    up  
Loopback104                172.16.14.3     YES manual up                    up  
Loopback105                172.16.15.3     YES manual up                    up  
Loopback106                172.16.16.3     YES manual up                    up  
Loopback107                172.16.17.3     YES manual up                    up  
Loopback108                172.16.18.3     YES manual up                    up  
R3#

これらLoopbackのうち、172.16.10.3/32, 172.16.11.3/32, 172.16.14.3/32, 172.16.15.3/32を1エントリのACLで設定する方法について考察します。(CCIE R&Sでは「1エントリ, 最小行数のACLで設定しなさい」との出題パターンもあります)

1エントリのACLでの設定について考察するには、まずIPアドレスを10進数から2進数に変換して考えます。

10進数 2進数
172.16.10.3 11000000 00010000 00001010 00000011
172.16.11.3 11000000 00010000 00001011 00000011
172.16.14.3 11000000 00010000 00001110 00000011
172.16.15.3 11000000 00010000 00001111 00000011

2進数をよく観察すると、第三オクテットの1の位と4の位以外は全部同じ数になっている事が分かります。従ってaddressとwildcardは以下のようになります。

10進数 2進数
address 172.16.10.3 11000000 00010000 00001010 00000011
wildcard 0.0.5.0 00000000 00000000 00000101 00000000

一部のLoopbackのみをredistributeするACLを設定します。BGPにextended ACLを適用する場合は送信元アドレスがIPアドレスに対応し、宛先アドレスがサブネットマスクに対応します。

 [R3]
ip access-list extended ACL_CONNECTED_TO_BGP
 10 permit ip 172.16.10.3 0.0.5.0 host 255.255.255.255
!
route-map RMAP_CONNECTED_TO_BGP
 match ip address ACL_CONNECTED_TO_BGP
!
router bgp 230
 redistribute connected route-map RMAP_CONNECTED_TO_BGP

動作確認

一部のprefixのみがredistributeされている事を確認します。

R3#show ip bgp
BGP table version is 6, local router ID is 10.3.3.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 172.16.10.3/32   0.0.0.0                  0         32768 ?
*> 172.16.11.3/32   0.0.0.0                  0         32768 ?
*> 172.16.14.3/32   0.0.0.0                  0         32768 ?
*> 172.16.15.3/32   0.0.0.0                  0         32768 ?
*>i192.168.12.0     192.168.23.2             0    100      0 ?
R3#
タイトルとURLをコピーしました