ก่อนเริ่ม Config NAT (Network Address Translation ) มารู้จัก NAT กันเบื้องต้นก่อนครับ NAT ทำเพื่อช่วยให้ Private IP ที่อยู่ใน LAN สามารถออกสู่ Internet ( Public IP) ได้ และ NAT ยังเป็นการซ่อน IP address อีกด้วย
อุปกรณ์ที่ทำ NAT ได้ ได้แก่ Router , Firewall , Server เป็นต้น
Private IP แบ่งเป็น 3 ช่วง IP ได้แก่
Private IP Class A คือหมายเลข 10.0.0.0 - 10.255.255.255 (16,777,216 IP addresses)
Private IP Class B คือหมายเลข 172.16.0.0 - 172.31.255.255 (1,048,576 IP addresses)
Private IP Class C คือหมายเลข 192.168.0.0 - 192.168.255.255 (65,536 IP addresses)
ตามรูปด้านล่าง Router R1 ต้องมีการ Config NAT จึงจะทำให้ LAN ที่เป็น Private IP ออกสู่ Internet ได้
การ Config NAT บน Router CISCO นั้น มีหลายวิธี มีทั้งแบบ Static NAT , Dynamic NAT และ Overloading NAT (PAT)
ในที่นี้จะแสดงการ Config NAT แบบ Overloading NAT (PAT) ให้ดูนะครับ
วิธีที่ 1 Config NAT โดยออก Internet ด้วย Public IP ที่ interface f0/0
มีขึ้นตอนดังนี้
1) กำหนด Private IP ด้วยการทำ ACL
R1(config)#access-list 2 permit 192.168.1.0 0.0.0.255
R1(config)#access-list 2 permit 192.168.2.0 0.0.0.255
2) ประกาศ NAT
R1(config)#ip nat inside source list 2 interface f0/0 overload
3) Enable NAT ที่ Interface ให้ถูกต้อง interface ขานอกใช้ nat outside , interface ขาในใช้ nat inside
R1(config)#interface f0/0
R1(config-if)#ip nat outside
R1(config-if)#exit
R1(config)#interface f0/1
R1(config-if)#ip nat inside
R1(config-if)#interface f1/0
R1(config-if)#ip nat inside
ทำการทดสอบและตรวจสอบการใช้งานด้วยการดูตาราง NAT
R1#show ip nat translations
Pro Inside global Inside local Outside local Outside global
icmp 33.33.33.33:62855 192.168.1.1:62855 2.2.2.2:62855 2.2.2.2:62855
icmp 33.33.33.33:63111 192.168.1.1:63111 2.2.2.2:63111 2.2.2.2:63111
icmp 33.33.33.33:63623 192.168.1.1:63623 2.2.2.2:63623 2.2.2.2:63623
icmp 33.33.33.33:63879 192.168.1.1:63879 2.2.2.2:63879 2.2.2.2:63879
icmp 33.33.33.33:64135 192.168.1.1:64135 2.2.2.2:64135 2.2.2.2:64135
icmp 33.33.33.33:3208 192.168.1.2:3208 1.1.1.1:3208 1.1.1.1:3208
icmp 33.33.33.33:3464 192.168.1.2:3464 1.1.1.1:3464 1.1.1.1:3464
icmp 33.33.33.33:3720 192.168.1.2:3720 1.1.1.1:3720 1.1.1.1:3720
icmp 33.33.33.33:3976 192.168.1.2:3976 1.1.1.1:3976 1.1.1.1:3976
icmp 33.33.33.33:4232 192.168.1.2:4232 1.1.1.1:4232 1.1.1.1:4232
icmp 33.33.33.33:1024 192.168.2.1:63879 1.1.1.1:63879 1.1.1.1:1024
icmp 33.33.33.33:1025 192.168.2.1:64135 1.1.1.1:64135 1.1.1.1:1025
icmp 33.33.33.33:64391 192.168.2.1:64391 1.1.1.1:64391 1.1.1.1:64391
icmp 33.33.33.33:64647 192.168.2.1:64647 1.1.1.1:64647 1.1.1.1:64647
icmp 33.33.33.33:64903 192.168.2.1:64903 1.1.1.1:64903 1.1.1.1:64903
icmp 33.33.33.33:1160 192.168.2.2:1160 1.1.1.1:1160 1.1.1.1:1160
icmp 33.33.33.33:1416 192.168.2.2:1416 1.1.1.1:1416 1.1.1.1:1416
icmp 33.33.33.33:1672 192.168.2.2:1672 1.1.1.1:1672 1.1.1.1:1672
icmp 33.33.33.33:1928 192.168.2.2:1928 1.1.1.1:1928 1.1.1.1:1928
icmp 33.33.33.33:2184 192.168.2.2:2184 1.1.1.1:2184 1.1.1.1:2184
วิธีที่ 2 Config NAT โดยออก Internet ด้วย Public IP ที่อยู่ใน Pool IP
มีขั้นตอนดังนี้
1) กำหนด Private IP ด้วยการทำ ACL ดังตัวอย่างสร้าง 2 ACL
R1(config)#access-list 3 permit 192.168.1.0 0.0.0.255
R1(config)#access-list 4 permit 192.168.2.0 0.0.0.255
2) กำหนด Public IP โดยการสร้าง Pool IP ในตัวอย่างสร้าง 2 กลุ่ม IP
R1(config)#ip nat pool Network-A 55.55.55.41 55.55.55.42 netmask 255.255.255.248
R1(config)#ip nat pool Network-B 55.55.55.43 55.55.55.44 netmask 255.255.255.248
3) ประกาศ NAT
R1(config)#ip nat inside source list 3 pool Network-A overload
R1(config)#ip nat inside source list 4 pool Network-B overload
4) Enable NAT ที่ Interface ให้ถูกต้อง interface ขานอกใช้ nat outside , interface ขาในใช้ nat inside
R1(config)#interface f0/0
R1(config-if)#ip nat outside
R1(config-if)#exit
R1(config)#interface f0/1
R1(config-if)#ip nat inside
R1(config-if)#interface f1/0
R1(config-if)#ip nat inside
ทำการทดสอบและตรวจสอบการใช้งานด้วยการดูตาราง NAT ได้ผลตามด้านล่าง
R1#show ip nat translations
Pro Inside global Inside local Outside local Outside global
icmp 55.55.55.42:139 192.168.1.1:139 2.2.2.2:139 2.2.2.2:139
icmp 55.55.55.42:64650 192.168.1.1:64650 2.2.2.2:64650 2.2.2.2:64650
icmp 55.55.55.42:64906 192.168.1.1:64906 2.2.2.2:64906 2.2.2.2:64906
icmp 55.55.55.42:65162 192.168.1.1:65162 2.2.2.2:65162 2.2.2.2:65162
icmp 55.55.55.42:65418 192.168.1.1:65418 2.2.2.2:65418 2.2.2.2:65418
icmp 55.55.55.42:1675 192.168.1.2:1675 1.1.1.1:1675 1.1.1.1:1675
icmp 55.55.55.42:1931 192.168.1.2:1931 1.1.1.1:1931 1.1.1.1:1931
icmp 55.55.55.42:2187 192.168.1.2:2187 1.1.1.1:2187 1.1.1.1:2187
icmp 55.55.55.42:2443 192.168.1.2:2443 1.1.1.1:2443 1.1.1.1:2443
icmp 55.55.55.42:2699 192.168.1.2:2699 1.1.1.1:2699 1.1.1.1:2699
icmp 55.55.55.44:139 192.168.2.1:139 1.1.1.1:139 1.1.1.1:139
icmp 55.55.55.44:395 192.168.2.1:395 1.1.1.1:395 1.1.1.1:395
icmp 55.55.55.44:651 192.168.2.1:651 1.1.1.1:651 1.1.1.1:651
icmp 55.55.55.44:907 192.168.2.1:907 1.1.1.1:907 1.1.1.1:907
icmp 55.55.55.44:65418 192.168.2.1:65418 1.1.1.1:65418 1.1.1.1:65418
icmp 55.55.55.44:512 192.168.2.2:651 1.1.1.1:651 1.1.1.1:512
icmp 55.55.55.44:513 192.168.2.2:907 1.1.1.1:907 1.1.1.1:513
icmp 55.55.55.44:1163 192.168.2.2:1163 1.1.1.1:1163 1.1.1.1:1163
icmp 55.55.55.44:1419 192.168.2.2:1419 1.1.1.1:1419 1.1.1.1:1419
icmp 55.55.55.44:1675 192.168.2.2:1675 1.1.1.1:1675 1.1.1.1:1675
วีดีโอตัวอย่างการ Config Static NAT บน CISCO Router(ตอนที่ 2)
VIDEO
ดูวีดีโอเพิ่มเติมเกี่ยวกับ NAT ได้ที่ Playlist ด้านล่าง
https://www.youtube.com/watch?v=dEqjm_Ho66s&list=PLxTcKTJPFY7OBZlqmR72jutolTB9aFwFU&index=1
หวังว่าบทความนี้คงจะก่อให้เกิดประโยชน์ไม่มากก็น้อยสำหรับผู้ที่ทำงานอยู่ในแวดวงไอทีนะครับ
ขอบคุณครับ
-------------------------------------------------------------------------------------------------------
บทความ Network
บทความ Linux
บทความ Certificate