一、配置主機地址:html
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 12.0.0.12 12.0.0.1 Checking for duplicate address... PC1 : 13.0.0.13 255.255.255.0 gateway 13.0.0.1
二、配置R1路由web
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
三、關閉sw路由功能vim
no ip routing
四、配置主機地址centos
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 12.0.0.12 12.0.0.1 Checking for duplicate address... PC1 : 12.0.0.12 255.255.255.0 gateway 12.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 12.0.0.12 13.0.0.13 icmp_seq=1 timeout 13.0.0.13 icmp_seq=2 timeout 84 bytes from 12.0.0.12 icmp_seq=3 ttl=62 time=62.485 ms 84 bytes from 12.0.0.12 icmp_seq=4 ttl=62 time=69.039 ms 84 bytes from 12.0.0.12 icmp_seq=5 ttl=62 time=69.046 ms
六、配置靜態NAT列表服務器
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.20 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
七、測試連通性tcp
PC1> ping 12.0.0.12 13.0.0.13 icmp_seq=1 timeout 13.0.0.13 icmp_seq=2 timeout 84 bytes from 12.0.0.12 icmp_seq=3 ttl=62 time=84.698 ms 84 bytes from 12.0.0.12 icmp_seq=4 ttl=62 time=85.265 ms 84 bytes from 12.0.0.12 icmp_seq=5 ttl=62 time=69.205 ms *Mar 1 00:23:50.619: NAT*: s=192.168.100.10 -> 12.0.0.10,d=12.0.0.12[5464] *Mar 1 00:23:51.831: NAT*: s=192.168.100.10->12.0.0.10, d=12.0.0.12 [5465] #將目標地址12.0.0.10轉換成192.168.100.10,這個就是靜態地址轉換的過程
一、實驗環境
Linux搭建的一臺Web服務器,局域網地址爲192.168.100.100,默認端口號80。局域網的網關192.168.100.1,映射地址:192.168.100.100:80—>12.0.0.100:8080。
別人只能看到公網IP地址,私網地址不能被直接訪問。
二、實驗目的
廣域網的客戶機沒法直接訪問100.100地址,若是想訪問的話就須要作端口映射。
三、實驗圖
四、在Linux中安裝httpd的服務軟件包,並開啓httpd服務,寫測試網頁等ide
[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
五、配置網關地址測試
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
六、經過centos中的瀏覽器可看到測試頁面(ping 192.168.100.100或127.0.0.1都行)this
七、給Linux綁定VMnet1網卡,給Host綁定VMnet2網卡,配置靜態地址
八、訪問對方192.168.100.100,此時是能夠訪問的,可是真實狀況下是沒法直接訪問對方私有地址的
九、靜態端口映射配置
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] # 端口和地址都進行了轉換
十、再次嘗試使用公網地址在win7進行訪問,此時能夠成功,實驗成功!