成都服務(wù)器托管,成都創(chuàng)新互聯(lián)提供包括服務(wù)器租用、成都多線機房、帶寬租用、云主機、機柜租用、主機租用托管、CDN網(wǎng)站加速、域名注冊等業(yè)務(wù)的一體化完整服務(wù)。電話咨詢:13518219792
Network Address Translation,網(wǎng)絡(luò)地址轉(zhuǎn)換
1.靜態(tài)轉(zhuǎn)換(Static Translation)
2.動態(tài)轉(zhuǎn)換(Dynamic Translation)
3.端口多路復(fù)用(Port Address Translation,PAT)
1.內(nèi)部局部地址:源IP=192.168.1.2
2.外部局部地址:目的IP=203.52.23.55
3.內(nèi)部全局地址:源IP=125.25.65.3
4.外部全局地址:目的IP=203.51.23.55
訪問外部服務(wù)器的過程:先查詢路由表再查看NAT表進行轉(zhuǎn)換
數(shù)據(jù)包回來的過程:先查詢NAT表進行轉(zhuǎn)換在查看路由表
1.簡單轉(zhuǎn)換條目:只轉(zhuǎn)換IP
2.擴展轉(zhuǎn)換條目:既轉(zhuǎn)換IP也轉(zhuǎn)換端口port
一個私網(wǎng)地址對一個公網(wǎng)i地址進行轉(zhuǎn)換
轉(zhuǎn)換的是同一IP,用端口加以區(qū)分
1.緩解IP地址資源匱乏
2.安全性:看不到來訪者的真正地址,因為會偽裝成公網(wǎng)地址
3.處理地址重疊
4.增強靈活性
1.延遲增大
2.配置和維護的復(fù)雜性
3.不支持某些應(yīng)用,可以通過靜態(tài)NAT映射來避免
虛擬專網(wǎng)要求兩端固定IP對聯(lián)IP不能變,此時會有穿越NAT設(shè)備配置
1.接口IP地址配置
2.使用訪問控制列表定義哪些內(nèi)部主機能做NAT
3.決定采用什么公有地址,靜態(tài)或地址池
router(config)#ip nat pool pool-name star-ip {netmask netmask | prefix-length prefix-length} [type rotary]
4.指定地址轉(zhuǎn)換映射
router(config)#ip nat inside source static local-ip global-ip [extendable]
router(config)#ip nat inside source static access-list-number pool pool-name[overload]
5.在內(nèi)部和外部端口上啟用NAT
router(config)#interface FastEthernet 0/0
router(config-if)#ip address 61.159.62.130 255.255.255.248
router(config-if)#no shut
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
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
sw#conf t
sw(config)#no ip routing
sw(config)#int f1/0
sw(config-if)#speed 100
sw(config-if)#dup full
sw(config-if)#ex
R2#conf t
R2(config)#int f0/0
R2(config-if)#ip add 12.0.0.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#int f
R2(config-if)#int f0/1
R2(config-if)#ip add 13.0.0.1 255.255.255.0
R2(config-if)#no shut
R2(config-if)#ex
R2(config)#ip route 0.0.0.0 0.0.0.0 12.0.0.1
R1#conf t
R1(config)#int f0/0
R1(config-if)#ip add 192.168.100.1 255.255.255.0
R1(config-if)#no shut
R1(config)#int f0/1
R1(config-if)#ip add 12.0.0.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#ex
R1(config)#ip route 0.0.0.0 0.0.0.0 12.0.0.2
PC1> ip 192.168.100.10 192.168.100.1
Checking for duplicate address...
PC1 : 192.168.100.10 255.255.255.0 gateway 192.168.100.1
PC2> ip 192.168.100.20 192.168.100.1
Checking for duplicate address...
PC1 : 192.168.100.20 255.255.255.0 gateway 192.168.100.1
PC3> ip 13.0.0.13 13.0.0.1
Checking for duplicate address...
PC1 : 13.0.0.13 255.255.255.0 gateway 13.0.0.1
PC1> ping 192.168.100.20
84 bytes from 192.168.100.20 icmp_seq=1 ttl=64 time=0.000 ms
84 bytes from 192.168.100.20 icmp_seq=2 ttl=64 time=0.000 ms
84 bytes from 192.168.100.20 icmp_seq=3 ttl=64 time=0.000 ms
84 bytes from 192.168.100.20 icmp_seq=4 ttl=64 time=0.000 ms
84 bytes from 192.168.100.20 icmp_seq=5 ttl=64 time=0.000 ms
PC1> ping 13.0.0.13
13.0.0.13 icmp_seq=1 timeout
13.0.0.13 icmp_seq=2 timeout
84 bytes from 13.0.0.13 icmp_seq=3 ttl=62 time=62.485 ms
84 bytes from 13.0.0.13 icmp_seq=4 ttl=62 time=69.039 ms
84 bytes from 13.0.0.13 icmp_seq=5 ttl=62 time=69.046 ms
R1(config)#ip nat inside source static 192.168.100.10 12.0.0.10
R1(config)#ip nat inside source static 192.168.100.10 12.0.0.20
R1(config)#int f0/0
R1(config-if)#ip nat inside
R1(config-if)#int f0/1
R1(config-if)#ip nat outside
R1(config-if)#end
R1#debug ip nat
IP NAT debugging is on
PC1> ping 13.0.0.13
13.0.0.13 icmp_seq=1 timeout
13.0.0.13 icmp_seq=2 timeout
84 bytes from 13.0.0.13 icmp_seq=3 ttl=62 time=84.698 ms
84 bytes from 13.0.0.13 icmp_seq=4 ttl=62 time=85.265 ms
84 bytes from 13.0.0.13 icmp_seq=5 ttl=62 time=69.205 ms
*Mar 1 00:23:50.619: NAT*: s=13.0.0.13, d=12.0.0.10->192.168.100.10 [5464]
*Mar 1 00:23:51.831: NAT*: s=13.0.0.13, d=12.0.0.10->192.168.100.10 [5465]
//將目標地址12.0.0.10轉(zhuǎn)換成192.168.100.10,這個就是靜態(tài)地址轉(zhuǎn)換的過程
Linux搭建的一臺Web服務(wù)器,局域網(wǎng)地址為192.168.100.100,默認端口為80端口
局域網(wǎng)的網(wǎng)關(guān)192.168.100.1
廣域網(wǎng)的客戶機無法直接訪問100.100地址,如果想訪問的話就需要做端口映射
映射地址:192.168.100.100:80--->12.0.0.100:8080
別人只能看到你的公網(wǎng)i地址,私網(wǎng)地址是不能直接訪問的
[root@localhost ~]# yum install httpd -y
[root@localhost ~]# vim /var/www/html/index.html //寫測試網(wǎng)頁
this is inside web
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
改dhcp為static
在末行按o在下行插入
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
wq保存退出
[root@localhost ~]# service network restart
Restarting network (via systemctl): [ 確定 ]
[root@localhost ~]# ifconfig
ens33: flags=4163 mtu 1500
inet 192.168.100.100 netmask 255.255.255.0 broadcast 192.168.100.255
R1#conf t
R1(config)#int f0/0
R1(config-if)#ip add 192.168.100.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#ex
R1(config)#int f0/1
R1(config-if)#ip add 12.0.0.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#ex
R1(config)#ip nat inside source static tcp 192.168.100.100 80 12.0.0.100 8080 extendable R1(config)#int f0/0
R1(config-if)#ip nat inside
R1(config-if)#int f0/1
R1(config-if)#ip nat outsid
R1(config-if)#end
R1#debug ip nat
IP NAT debugging is on
*Mar 1 00:36:59.327: NAT*: TCP s=49160, d=8080->80
*Mar 1 00:36:59.327: NAT*: s=12.0.0.12, d=12.0.0.100->192.168.100.100 [364]
//端口和地址都進行了轉(zhuǎn)換