Bùi Nguyễn Hoàng Long


Thực hiện PAT với địa chỉ cổng


I. Mô tả:
Cho phép truy cập dịch vụ ngoài Internet với PAT dùng địa chỉ cổng.
Lưu ý: Router GATEWAY nhận địa chỉ động từ DHCP (dãy địa chỉ 10.215.219.0/24) do Router ADSL cấp và địa chỉ của Router ADSL là 10.215.219.254, Router ADSL không thể hiện trong mô hình nhằm mục đích đơn giản, mô hình này cũng sử dụng cho những kịch bản sau.

II. Cấu hình
1. Cấu hình trên GATEWAY
GATEWAY(config)#interface fa0/0
GATEWAY(config-if)#ip address 192.168.2.2 255.255.255.0
Cho phép nhận địa chi qua DHCP
GATEWAY(config)#interface fa0/1
GATEWAY(config-if)#ip address dhcp

Định nghĩa mạng đuợc NAT hoặc PAT
GATEWAY(config)#access-list 1 permit 192.168.2.0 0.0.0.255
GATEWAY(config)#ip nat inside source list 1 interface fa0/1

GATEWAY(config)#interface fa0/0
GATEWAY(config-if)#ip nat inside
GATEWAY(config)#interface fa0/1
GATEWAY(config-if)#ip nat outside

2. Cấu hình trên ASA
ciscoasa(config)# hostname ASA

Định nghĩa thông tin cổng inside
ASA(config)# interface e0/0
ASA(config-if)# ip address 192.168.1.1 255.255.255.0
ASA(config-if)# nameif inside
INFO: Security level for "inside" set to 100 by default.
ASA(config-if)# no shut

Định nghĩa thông tin cổng outsde
ASA(config)# interface e0/1
ASA(config-if)# ip address 192.168.2.1 255.255.255.0
ASA(config-if)# nameif outside
INFO: Security level for "outside" set to 0 by default.
ASA(config-if)# no shut

Trong truờng hợp này security-level được xác định sẵn, để thay đổi lại có thể dùng câu lệnh
security-level

Định nghĩa tuyến mặc định
ASA(config)# route outside 0 0 192.168.2.2

Xác định mạng được NAT hoặc PAT
ASA(config)# nat (inside) 1 192.168.1.0 255.255.255.0

Xác định NAT hoặc PAT trên cổng outside
ASA(config)# global (outside) 1 interface
INFO: outside interface address added to PAT pool

III. Cấu hình đầy đủ
ASA
ASA Version 8.0(2)
!
hostname ASA
enable password 8Ry2YjIyt7RRXU24 encrypted
names
!
interface Ethernet0/0
nameif inside
security-level 100
ip address 192.168.1.1 255.255.255.0
!
interface Ethernet0/1
nameif outside
security-level 0
ip address 192.168.2.1 255.255.255.0
!
interface Ethernet0/2
shutdown
no nameif
no security-level
no ip address
!
interface Ethernet0/3
shutdown
no nameif
no security-level
no ip address
!
interface Management0/0
shutdown
no nameif
no security-level
no ip address
management-only
!
passwd 2KFQnbNIdI.2KYOU encrypted
ftp mode passive
access-list PING extended permit icmp any any echo-reply
global (outside) 1 interface
nat (inside) 1 192.168.1.0 255.255.255.0
access-group PING in interface outside
route outside 0.0.0.0 0.0.0.0 192.168.2.2 1
!
class-map inspection_default
match default-inspection-traffic
!
!
policy-map type inspect dns preset_dns_map
parameters
message-length maximum 512
policy-map global_policy
class inspection_default
inspect dns preset_dns_map
inspect ftp
inspect h323 h225
inspect h323 ras
inspect rsh
inspect rtsp
inspect esmtp
inspect sqlnet
inspect skinny
inspect sunrpc
inspect xdmcp
inspect sip
inspect netbios
inspect tftp
!
service-policy global_policy global
prompt hostname context
Cryptochecksum:dba2db98f02aa720ff5cea67b371a558
: end

GATEWAY
Building configuration...

Current configuration : 726 bytes
hostname GATEWAY
!
interface FastEthernet0/0
ip address 192.168.2.2 255.255.255.0
ip nat inside
duplex auto
speed auto
!
interface FastEthernet0/1
ip address dhcp
ip nat outside
duplex auto
speed auto
!
ip nat inside source list 1 interface FastEthernet0/1 overload
ip classless
ip http server
no ip http secure-server
!
access-list 1 permit 192.168.2.0 0.0.0.255
!
line con 0
line aux 0
line vty 0 4
login
!
end


IV. Kiểm tra
Địa chỉ được nhận qua DHCP
GATEWAY#sh ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.2.2 YES manual up up
FastEthernet0/1 10.215.219.80 YES DHCP up up 

Trong truờng hợp một tuyến mặc định sẽ được tự động tạo ra, do đó không cần định nghĩa tuyến mặc định trong phần cấu hình

GATEWAY#sh ip route static
10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
S 10.215.219.254/32 [254/0] via 10.215.219.254, FastEthernet0/1
S* 0.0.0.0/0 [254/0] via 10.215.219.254

Xác địng địa chỉ IP cho PC

Truy cập Web thành công


Trạng thái bảng NAT
ASA(config)# sh xlate
7 in use, 8 most used
PAT Global 192.168.2.1(1028) Local 192.168.1.2(1066)
PAT Global 192.168.2.1(1027) Local 192.168.1.2(1065)
PAT Global 192.168.2.1(1026) Local 192.168.1.2(1064)
PAT Global 192.168.2.1(1025) Local 192.168.1.2(1063)
PAT Global 192.168.2.1(1026) Local 192.168.1.2(1060)
PAT Global 192.168.2.1(1) Local 192.168.1.2(123)
PAT Global 192.168.2.1(1025) Local 192.168.1.2(1054)

Trạng thái kết nối
ASA(config)# sh conn
6 in use, 10 most used
TCP out 118.214.2.70:80 in 192.168.1.2:1066 idle 0:00:44 bytes 1702 flags UIO
TCP out 59.37.173.11:80 in 192.168.1.2:1065 idle 0:00:44 bytes 5849 flags UIO
TCP out 69.89.22.108:80 in 192.168.1.2:1064 idle 0:00:44 bytes 137684 flags UIO
TCP out 69.89.22.108:80 in 192.168.1.2:1063 idle 0:00:44 bytes 74999 flags UIO
UDP out 192.168.4.9:6161 in 192.168.1.2:1060 idle 0:00:45 flags -
UDP out 207.46.232.182:123 in 192.168.1.2:123 idle 0:01:20 flags -

Mặc dù có thể truy phần lớn những dịch vị cần thiết ngòai Internet như http, pop3, smtp, ftp...
Nhưng với icmp thì ASA không cho phép gói echo-reply được trả về



Để giải quyết trường hợp này cần tạo chính sách cho echo-reply được trả về

ASA(config)# access-list PING permit icmp any any echo-reply
ASA(config)# access-group PING in interface outside




ASA(config)# sh xlate
1 in use, 8 most used
PAT Global 192.168.2.1(2) Local 192.168.1.2 ICMP id 512

Trạng thái bảng NAT
GATEWAY#sh ip nat translations
Pro Inside global Inside local Outside local Outside global
tcp 10.215.219.80:1027 192.168.2.1:1027 59.37.173.11:80 59.37.173.11:80
tcp 10.215.219.80:1028 192.168.2.1:1028 118.214.2.70:80 118.214.2.70:80
tcp 10.215.219.80:1025 192.168.2.1:1025 69.89.22.108:80 69.89.22.108:80
tcp 10.215.219.80:1026 192.168.2.1:1026 69.89.22.108:80 69.89.22.108:80
udp 10.215.219.80:1026 192.168.2.1:1026 192.168.4.9:6161 192.168.4.9:6161
tcp 10.215.219.80:1024 192.168.2.1:1024 64.4.52.189:80 64.4.52.189:80