CiscoルータによるNAT設定



●PAT(IPマスカレード)

 PATの設定法方を記載します。
 接続構成図は下記のとおりです。

cisco-nat-pat01.png

 ルータの初期設定をします。
  :
(途中省略)
  :
!
interface FastEthernet0
 ip address 200.200.200.254 255.255.255.0
 ip virtual-reassembly in
 duplex auto
 speed auto
!
interface FastEthernet1
 ip address 192.168.0.254 255.255.255.0
 ip virtual-reassembly in
 duplex auto
 speed auto
!
  :
(途中省略)
  :
 NATの内側、外側インターフェースの指定及びroute-mapを使用したPATを設定します。
cisco1812(config)#interface FastEthernet 0
cisco1812(config-if)#ip nat outside ← NATの外側インターフェースに指定
cisco1812(config-if)#exit
cisco1812(config)#
cisco1812(config)#
cisco1812(config)#interface FastEthernet 1
cisco1812(config-if)#ip nat inside ← NATの内側インターフェースに指定
cisco1812(config-if)#exit
cisco1812(config)#
cisco1812(config)#
cisco1812(config)#ip access-list standard NAT_LIST
cisco1812(config-std-nacl)# permit 192.168.0.0 0.0.0.255
cisco1812(config-std-nacl)#exit
cisco1812(config)#
cisco1812(config)#
cisco1812(config)#route-map NAT_MAP
cisco1812(config-route-map)#match ip address NAT_LIST
cisco1812(config-route-map)#exit
cisco1812(config)#
cisco1812(config)#
cisco1812(config)#ip nat inside source route-map NAT_MAP interface FastEthernet0 overload

 疎通確認(その1)

 CentOS(192.168.0.11)からWindows XP(200.200.200.1)に向けてpingを打って確認します。
 ただし、CentOS側でstatic routeを設定します。
# route add -net 200.200.200.0/24 gw 192.168.0.254
 pingを打って応答があることがわかります。
# ping 200.200.200.1
PING 200.200.200.1 (200.200.200.1) 56(84) bytes of data.
64 bytes from 200.200.200.1: icmp_seq=1 ttl=127 time=0.961 ms
64 bytes from 200.200.200.1: icmp_seq=2 ttl=127 time=0.812 ms
64 bytes from 200.200.200.1: icmp_seq=3 ttl=127 time=0.806 ms
64 bytes from 200.200.200.1: icmp_seq=4 ttl=127 time=0.825 ms
 Windows XP側でのキャプチャ結果は下記のとおりです。

27 2013-02-26 20:28:00.943971000 200.200.200.254 200.200.200.1 ICMP 98 Echo (ping) request id=0x3615, seq=3/768, ttl=63
28 2013-02-26 20:28:00.943996000 200.200.200.1 200.200.200.254 ICMP 98 Echo (ping) reply id=0x3615, seq=3/768, ttl=128
29 2013-02-26 20:28:01.943966000 200.200.200.254 200.200.200.1 ICMP 98 Echo (ping) request id=0x3615, seq=4/1024, ttl=63
30 2013-02-26 20:28:01.943989000 200.200.200.1 200.200.200.254 ICMP 98 Echo (ping) reply id=0x3615, seq=4/1024, ttl=128
31 2013-02-26 20:28:02.943983000 200.200.200.254 200.200.200.1 ICMP 98 Echo (ping) request id=0x3615, seq=5/1280, ttl=63
32 2013-02-26 20:28:02.944005000 200.200.200.1 200.200.200.254 ICMP 98 Echo (ping) reply id=0x3615, seq=5/1280, ttl=128
33 2013-02-26 20:28:03.943956000 200.200.200.254 200.200.200.1 ICMP 98 Echo (ping) request id=0x3615, seq=6/1536, ttl=63
34 2013-02-26 20:28:03.943975000 200.200.200.1 200.200.200.254 ICMP 98 Echo (ping) reply id=0x3615, seq=6/1536, ttl=128
35 2013-02-26 20:28:04.944015000 200.200.200.254 200.200.200.1 ICMP 98 Echo (ping) request id=0x3615, seq=7/1792, ttl=63
36 2013-02-26 20:28:04.944041000 200.200.200.1 200.200.200.254 ICMP 98 Echo (ping) reply id=0x3615, seq=7/1792, ttl=128


 設定確認(その1)

 showコマンドにより、どのようにIPアドレスが変換されたのかを確認します。
cisco1812#show ip nat translations 
Pro Inside global      Inside local       Outside local      Outside global
icmp 200.200.200.254:51479 192.168.0.11:51479 200.200.200.1:51479 200.200.200.1:51479
 debugを有効にし、上記のpingが変換される様子を観察します。
cisco1812#debug ip nat
IP NAT debugging is on
cisco1812#no debug ip nat
IP NAT debugging is off
cisco1812#ter len 0
cisco1812#show log
Feb 26 21:38:26.111: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [0]
Feb 26 21:38:26.111: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [8825]
Feb 26 21:38:27.111: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [0]
Feb 26 21:38:27.111: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [8826]
Feb 26 21:38:28.115: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [0]
Feb 26 21:38:28.115: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [8827]
Feb 26 21:38:29.115: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [0]
Feb 26 21:38:29.115: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [8828]
Feb 26 21:38:30.115: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [0]
Feb 26 21:38:30.115: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [8829]

 疎通・設定確認(その2)

 CentOS(192.168.0.11)からWindows XP(200.200.200.1)へHTTP接続して確認します。
CentOS# w3m 200.200.200.1
 (テキストベースで接続していることを確認できます)
cisco1812#show ip nat translations 
Pro Inside global      Inside local       Outside local      Outside global
tcp 200.200.200.254:58899 192.168.0.11:58899 200.200.200.1:80 200.200.200.1:80
 デバッグモードの結果は以下のとおりです。
cisco1812#debug ip nat
IP NAT debugging is on
cisco1812#no debug ip nat
IP NAT debugging is off
cisco1812#ter len 0
cisco1812#show log
Feb 26 22:32:42.100: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [30163]
Feb 26 22:32:42.100: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [56792]
Feb 26 22:32:42.100: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [30164]
Feb 26 22:32:42.100: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [30165]
Feb 26 22:32:42.104: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [56793]
Feb 26 22:32:42.104: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [56794]
Feb 26 22:32:42.104: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [56795]
Feb 26 22:32:42.104: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [30166]
Feb 26 22:32:42.104: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [30167]
Feb 26 22:32:42.144: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [30168]
Feb 26 22:32:43.108: NAT*: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [30169]
Feb 26 22:32:43.108: NAT*: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [56835]
Feb 26 22:33:43.525: NAT: expiring 200.200.200.254 (192.168.0.11) tcp 58899 (58899)
 キャプチャは以下のとおりです。

1 2013-02-26 22:32:41.862909000 200.200.200.254 200.200.200.1 TCP 74 58899 > http [SYN] Seq=0 Win=14600 Len=0 MSS=1460 SACK_PERM=1 TSval=647432067 TSecr=0 WS=64
2 2013-02-26 22:32:41.862964000 200.200.200.1 200.200.200.254 TCP 78 http > 58899 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460 WS=1 TSval=0 TSecr=0 SACK_PERM=1
3 2013-02-26 22:32:41.863921000 200.200.200.254 200.200.200.1 TCP 66 58899 > http [ACK] Seq=1 Ack=1 Win=14656 Len=0 TSval=647432068 TSecr=0
4 2013-02-26 22:32:41.864085000 200.200.200.254 200.200.200.1 HTTP 286 GET / HTTP/1.0
5 2013-02-26 22:32:41.867260000 200.200.200.1 200.200.200.254 TCP 1514 [TCP segment of a reassembled PDU]
6 2013-02-26 22:32:41.867281000 200.200.200.1 200.200.200.254 HTTP 216 HTTP/1.1 200 OK (text/html)
7 2013-02-26 22:32:41.867765000 200.200.200.1 200.200.200.254 TCP 66 http > 58899 [FIN, ACK] Seq=1599 Ack=221 Win=65315 Len=0 TSval=1433201 TSecr=647432068
8 2013-02-26 22:32:41.868417000 200.200.200.254 200.200.200.1 TCP 66 58899 > http [ACK] Seq=221 Ack=1449 Win=17536 Len=0 TSval=647432072 TSecr=1433201
9 2013-02-26 22:32:41.868560000 200.200.200.254 200.200.200.1 TCP 66 58899 > http [ACK] Seq=221 Ack=1599 Win=20416 Len=0 TSval=647432072 TSecr=1433201
10 2013-02-26 22:32:41.908500000 200.200.200.254 200.200.200.1 TCP 66 58899 > http [ACK] Seq=221 Ack=1600 Win=20416 Len=0 TSval=647432113 TSecr=1433201
11 2013-02-26 22:32:42.871047000 200.200.200.254 200.200.200.1 TCP 66 58899 > http [FIN, ACK] Seq=221 Ack=1600 Win=20416 Len=0 TSval=647433075 TSecr=1433201
12 2013-02-26 22:32:42.871077000 200.200.200.1 200.200.200.254 TCP 66 http > 58899 [ACK] Seq=1600 Ack=222 Win=65315 Len=0 TSval=1433211 TSecr=647433075


 疎通・設定確認(その3)

 CentOS(192.168.0.11)からWindows XP(200.200.200.1)へFTP接続して確認します。
CentOS# ftp 200.200.200.1
Connected to 200.200.200.1 (200.200.200.1).
220 Microsoft FTP Service
Name (200.200.200.1:root): anonymous
331 Anonymous access allowed, send identity (e-mail name) as password.
Password:
230 Anonymous user logged in.
Remote system type is Windows_NT.
ftp> bye
221  
cisco1812#show ip nat translations 
Pro Inside global      Inside local       Outside local      Outside global
tcp 200.200.200.254:45836 192.168.0.11:45836 200.200.200.1:21 200.200.200.1:21
 デバッグモードの結果は以下のとおりです。
cisco1812#debug ip nat
IP NAT debugging is on
cisco1812#no debug ip nat
IP NAT debugging is off
cisco1812#ter len 0
cisco1812#show log
Feb 26 22:55:24.799: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50273]
Feb 26 22:55:24.803: NAT: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [13225]
Feb 26 22:55:24.803: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50274]
Feb 26 22:55:24.803: NAT: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [13226]
Feb 26 22:55:24.803: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50275]
Feb 26 22:55:29.959: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50276]
Feb 26 22:55:29.963: NAT: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [13309]
Feb 26 22:55:29.963: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50277]
Feb 26 22:55:35.763: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50278]
Feb 26 22:55:35.763: NAT: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [13324]
Feb 26 22:55:35.763: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50279]
Feb 26 22:55:35.763: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50280]
Feb 26 22:55:35.763: NAT: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [13325]
Feb 26 22:55:35.803: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50281]
Feb 26 22:55:38.351: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50282]
Feb 26 22:55:38.351: NAT: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [13340]
Feb 26 22:55:38.351: NAT: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [13341]
Feb 26 22:55:38.351: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50283]
Feb 26 22:55:38.351: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50284]
Feb 26 22:55:38.351: NAT: s=192.168.0.11->200.200.200.254, d=200.200.200.1 [50285]
Feb 26 22:55:38.355: NAT: s=200.200.200.1, d=200.200.200.254->192.168.0.11 [13342]
 キャプチャは以下のとおりです。

1 2013-02-26 22:55:24.540583000 200.200.200.254 200.200.200.1 TCP 74 45836 > ftp [SYN] Seq=0 Win=14600 Len=0 MSS=1460 SACK_PERM=1 TSval=648794770 TSecr=0 WS=64
2 2013-02-26 22:55:24.540629000 200.200.200.1 200.200.200.254 TCP 78 ftp > 45836 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460 WS=1 TSval=0 TSecr=0 SACK_PERM=1
3 2013-02-26 22:55:24.542095000 200.200.200.254 200.200.200.1 TCP 66 45836 > ftp [ACK] Seq=1 Ack=1 Win=14656 Len=0 TSval=648794772 TSecr=0
4 2013-02-26 22:55:24.542476000 200.200.200.1 200.200.200.254 FTP 93 Response: 220 Microsoft FTP Service
5 2013-02-26 22:55:24.543886000 200.200.200.254 200.200.200.1 TCP 66 45836 > ftp [ACK] Seq=1 Ack=28 Win=14656 Len=0 TSval=648794773 TSecr=1446828
6 2013-02-26 22:55:29.700281000 200.200.200.254 200.200.200.1 FTP 82 Request: USER anonymous
7 2013-02-26 22:55:29.700425000 200.200.200.1 200.200.200.254 FTP 138 Response: 331 Anonymous access allowed, send identity (e-mail name) as password.
8 2013-02-26 22:55:29.701875000 200.200.200.254 200.200.200.1 TCP 66 45836 > ftp [ACK] Seq=17 Ack=100 Win=14656 Len=0 TSval=648799931 TSecr=1446880
9 2013-02-26 22:55:35.501251000 200.200.200.254 200.200.200.1 FTP 95 Request: PASS user@met.kishou.go.jp
10 2013-02-26 22:55:35.501617000 200.200.200.1 200.200.200.254 FTP 97 Response: 230 Anonymous user logged in.
11 2013-02-26 22:55:35.503111000 200.200.200.254 200.200.200.1 TCP 66 45836 > ftp [ACK] Seq=46 Ack=131 Win=14656 Len=0 TSval=648805733 TSecr=1446938
12 2013-02-26 22:55:35.503393000 200.200.200.254 200.200.200.1 FTP 72 Request: SYST
13 2013-02-26 22:55:35.503460000 200.200.200.1 200.200.200.254 FTP 82 Response: 215 Windows_NT
14 2013-02-26 22:55:35.544068000 200.200.200.254 200.200.200.1 TCP 66 45836 > ftp [ACK] Seq=52 Ack=147 Win=14656 Len=0 TSval=648805774 TSecr=1446938
15 2013-02-26 22:55:38.090280000 200.200.200.254 200.200.200.1 FTP 72 Request: QUIT
16 2013-02-26 22:55:38.090419000 200.200.200.1 200.200.200.254 FTP 77 Response: 221
17 2013-02-26 22:55:38.090511000 200.200.200.1 200.200.200.254 TCP 66 ftp > 45836 [FIN, ACK] Seq=158 Ack=58 Win=65478 Len=0 TSval=1446963 TSecr=648808320
18 2013-02-26 22:55:38.092013000 200.200.200.254 200.200.200.1 TCP 66 45836 > ftp [ACK] Seq=58 Ack=158 Win=14656 Len=0 TSval=648808321 TSecr=1446963
19 2013-02-26 22:55:38.092294000 200.200.200.254 200.200.200.1 TCP 66 45836 > ftp [FIN, ACK] Seq=58 Ack=158 Win=14656 Len=0 TSval=648808321 TSecr=1446963
20 2013-02-26 22:55:38.092306000 200.200.200.1 200.200.200.254 TCP 66 ftp > 45836 [ACK] Seq=159 Ack=59 Win=65478 Len=0 TSval=1446963 TSecr=648808321
21 2013-02-26 22:55:38.092574000 200.200.200.254 200.200.200.1 TCP 66 45836 > ftp [ACK] Seq=59 Ack=159 Win=14656 Len=0 TSval=648808321 TSecr=1446963


 ルータの設定内容

cisco1812#show run
Building configuration...

Current configuration : 2885 bytes
!
! Last configuration change at 19:03:51 JST Wed Feb 20 2013
! NVRAM config last updated at 19:03:55 JST Wed Feb 20 2013
! NVRAM config last updated at 19:03:55 JST Wed Feb 20 2013
version 15.1
service timestamps debug datetime msec localtime
service timestamps log datetime msec localtime
service password-encryption
!
hostname cisco1812
!
boot-start-marker
boot-end-marker
!
!
logging buffered 32678
enable secret 5 $1$ZF5B$GGYfBVCkyE55jb/l7ZsXA1
!
no aaa new-model
!
clock timezone JST 9 0
crypto pki token default removal timeout 0
!
!
dot11 syslog
ip source-route
!
!
!
!
!
ip cef
ip domain name bigbang.dyndns.org
ip name-server 1.0.0.12
ip name-server 1.0.0.4
no ipv6 cef
!
multilink bundle-name authenticated
!
!
!
license udi pid CISCO1812-J/K9 sn FHK13427246
!
!
!
!
!
!
!
!
!
interface BRI0
no ip address
encapsulation hdlc
shutdown
!
interface FastEthernet0
ip address 200.200.200.254 255.255.255.0
ip nat outside
ip virtual-reassembly in
duplex auto
speed auto
!
interface FastEthernet1
ip address 192.168.0.254 255.255.255.0
ip nat inside
ip virtual-reassembly in
duplex auto
speed auto
!
interface FastEthernet2
switchport access vlan 2
no ip address
!
interface FastEthernet3
switchport access vlan 2
no ip address
!
interface FastEthernet4
switchport access vlan 2
no ip address
!
interface FastEthernet5
switchport access vlan 2
no ip address
!
interface FastEthernet6
switchport access vlan 2
no ip address
!
interface FastEthernet7
switchport access vlan 2
no ip address
!
interface FastEthernet8
switchport access vlan 2
no ip address
!
interface FastEthernet9
switchport access vlan 2
no ip address
!
interface Vlan1
no ip address
!
interface Vlan2
description "LOCAL-NET"
ip address 1.0.0.254 255.255.255.0
arp timeout 30
!
router ospf 1
network 1.0.0.0 0.0.0.255 area 0
default-information originate
!
ip forward-protocol nd
no ip http server
no ip http secure-server
!
!
ip nat inside source route-map NAT_MAP interface FastEthernet0 overload
ip route 0.0.0.0 0.0.0.0 1.0.0.1
!
ip access-list standard NAT_LIST
permit 192.168.0.0 0.0.0.255
!
no cdp run
!
!
!
!
route-map NAT_MAP permit 10
match ip address NAT_LIST
!
snmp-server community private RO 10
snmp-server trap-source Vlan2
snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart
snmp-server enable traps envmon
snmp-server host 1.0.0.12 bigbang
!
!
control-plane
!
!
banner login ^C
########################################
Welcom to Cisco1812
1.Model CISCO1812-J/K9
2.SW Version 151(4)M1
3.SW Image c181x-advipservicesk9-m
########################################
^C
!
line con 0
exec-timeout 180 0
password 7 1066274E53131458
line aux 0
line vty 0 4
exec-timeout 180 0
password 7 013B28530D0F005C
login
transport input all
!
ntp peer 210.173.160.27
ntp peer 210.173.160.57
ntp peer 210.173.160.87
end


●リンク

 スタティックNAT
 ダイナミックNAT
 PAT(IPマスカレード)
 重複アドレスの変換
 あて先アドレスの分散変換
 route-mapを使用したNAT, PAT設定