NAT的工做原理:網絡地址轉換html
NAT實現方式:web
靜態轉換vim
動態轉換安全
端口多路複用服務器
訪問外部服務器的過程:先查詢路由表再查看NAT表進行轉換網絡
數據包回來的過程:先查詢NAT表進行轉換再查詢路由表tcp
內部局部地址ide
外部局部地址測試
內部全局地址網站
外部全局地址
NAT的轉換條目
簡單轉換條目
擴輾轉換條目
NAT的優勢
節省公有合法IP地址
處理地址重疊
加強靈活性
安全性
NAT的缺點
延遲增大
配置和維護的複雜性
不支持某些應用,能夠經過靜態NAT映射來避免
NAT實現方法的工做過程
NAT的特徵
NAT配置步驟
一、接口IP地址配置
二、使用訪問控制列表定義那些主機能作NAT
三、決定採用什麼公有地址,靜態和地址池
Router(config)#ip nat pool pool-name star-ip end-ip {netmask netmask | prefix-length prefix-length} [type rotary]
四、指定地址轉換映射
Router(config)#ip nat inside source static local-ip global-ip [extendable]
Router(config)#ip nat inside source list access-list-number pool pool-name [overload]
五、在內部和外部端口上啓用NAT
將內網地址192.168.100.2 / 192.168.100.3靜態轉換爲合法的外部地址61.159.62.131 / 61.159.62.132,以便訪問外部網絡或被外部網絡訪問
設置外部端口的IP地址:
router(config)#interface FastEthernet 0/0
router(config-if)#ip address 61.159.62.130 255.255.255.248
router(config-if)#no shut
設置內部端口的IP地址:
router(config)#interface FastEthernet 1/0
router(config-if)#ip address 192.168.100.1 255.255.255.0
router(config-if)#no shut
創建靜態地址轉換:
router(config)#ip nat inside source static 192.168.100.2 61.159.62.130
router(config)#ip nat inside source static 192.168.100.3 61.159.62.131
在內部和外部端口上啓用NAT:
router(config)#inerface FastEthernet 0/0
router(config)#ip nat outside
router(config)#interface FastEthernet 1/0
router(config)#ip nat inside
配置默認路由:
router(config)#ip router 0.0.0.0 0.0.0.0 61.159.62.129
實驗拓撲圖
R2接口配置
輸入如下命令:
conf t
int f0/0
ip add 12.0.0.2 255.255.255.0
no shut
int f0/1
ip add 13.0.0.1 255.255.255.0
no shut
ex
ip route 0.0.0.0 0.0.0.0 12.0.0.1
sw接口配置
輸入如下命令:
conf t
no ip routing
int f1/2
speed 100
dup full
ex
R1接口配置
輸入如下命令:
conf t
int f0/0
ip add 192.168.100.1 255.255.255.0
no shut
int f0/1
ip add 12.0.0.1 255.255.255.0
no shut
ex
ip route 0.0.0.0 0.0.0.0 12.0.0.2
配置PC機地址
分別輸入如下命令:
PC1> ip 192.168.100.10 192.168.100.1
PC2> ip 192.168.100.20 192.168.100.1
PC3> ip 13.0.0.2 13.0.0.1
測試全網是否互通
輸入如下命令:
PC1> ping 192.168.100.20
PC1> ping 13.0.0.2
靜態NAT地址轉換配置
輸入如下命令:
ip nat inside source static 192.168.100.10 12.0.0.10
ip nat inside source static 192.168.100.10 12.0.0.20
int f0/0
ip nat inside
int f0/1
ip nat outside
end
debug ip nat
測試NAT地址轉換配置結果
實驗需求:
Linux搭建的一臺Web服務器,局域網地址爲192.168.100.100,默認端口爲80端口
局域網的網關192.168.100.1
廣域網的客戶機沒法直接訪問100.100地址,若是想訪問的話就須要作端口映射
映射地址:192.168.100.100:80—>12.0.0.100:8080
win7做爲廣域網的客戶端
CentOS 7作爲Web服務器
實驗拓撲圖
在CentOS7的終端作如下配置
yum install httpd -y
vim /var/www/html/index.html
<h1>this is inside web</h1>
systemctl start httpd
systemctl stop firewalld.service
setenforce 0
輸入本地地址,對網站進行自測
對CentOS7綁定VMnet1網卡,並配置固定ip192.168.100.100
vim /etc/sysconfig/network-scripts/ifcfg-ens33
將第4行的dhcp改成static
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
將win10綁定VMnet2網卡,並配置固定ip12.0.0.12
配置路由器網關地址
conf t
int f0/0
ip add 192.168.100.1 255.255.255.0
no shut
ex
int f0/1
ip add 12.0.0.1 255.255.255.0
no shut
ex
靜態NAT地址轉換配置
ip nat inside source static tcp 192.168.100.100 80 12.0.0.100 8080 extendable
int f0/0
ip nat inside
int f0/1
ip nat outsid
end
debug ip nat
再次嘗試使用公網地址在win10進行訪問,此時能夠成功,而且debug能夠抓取到地址轉換過程