Network Address Translation,網絡地址轉換html
1.靜態轉換(Static Translation)web
2.動態轉換(Dynamic Translation)shell
3.端口多路複用(Port Address Translation,PAT)vim
1.內部局部地址:源IP=192.168.1.2瀏覽器
2.外部局部地址:目的IP=203.52.23.55安全
3.內部全局地址:源IP=125.25.65.3服務器
4.外部全局地址:目的IP=203.51.23.55網絡
訪問外部服務器的過程:先查詢路由表再查看NAT表進行轉換tcp
數據包回來的過程:先查詢NAT表進行轉換在查看路由表ide
1.簡單轉換條目:只轉換IP
2.擴輾轉換條目:既轉換IP也轉換端口port
一個私網地址對一個公網i地址進行轉換
轉換的是同一IP,用端口加以區分
1.緩解IP地址資源匱乏
2.安全性:看不到來訪者的真正地址,由於會假裝成公網地址
3.處理地址重疊
4.加強靈活性
1.延遲增大
2.配置和維護的複雜性
3.不支持某些應用,能夠經過靜態NAT映射來避免
虛擬專網要求兩端固定IP對聯IP不能變,此時會有穿越NAT設備配置
1.接口IP地址配置
2.使用訪問控制列表定義哪些內部主機能作NAT
3.決定採用什麼公有地址,靜態或地址池
router(config)#ip nat pool pool-name star-ip {netmask netmask | prefix-length prefix-length} [type rotary]
4.指定地址轉換映射
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.在內部和外部端口上啓用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轉換成192.168.100.10,這個就是靜態地址轉換的過程
Linux搭建的一臺Web服務器,局域網地址爲192.168.100.100,默認端口爲80端口
局域網的網關192.168.100.1
廣域網的客戶機沒法直接訪問100.100地址,若是想訪問的話就須要作端口映射
映射地址:192.168.100.100:80--->12.0.0.100:8080
別人只能看到你的公網i地址,私網地址是不能直接訪問的
[root@localhost ~]# yum install httpd -y [root@localhost ~]# vim /var/www/html/index.html //寫測試網頁 <h1>this is inside web</h1> [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<UP,BROADCAST,RUNNING,MULTICAST> 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] //端口和地址都進行了轉換