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] //端口和地址都进行了转换