本机为 PC 机,系统为 Windows 10,模拟器为 GNS3 2.2.3
192.168.0.108
)192.168.0.104
)路由器接口 f0/0
连接 Cloud 节点关联的以太网卡
为接口 f0/0
配置 DHCP,动态获取 IP 地址
R1# conf t
R1(config)# int f0/0
R1(config-if)# ip address dhcp
R1(config-if)# no shutdown
R1(config-if)# end
可能需要等待一段时间,得到地址:192.168.0.103
R1#
*Feb 25 10:21:06.959: %DHCP-6-ADDRESS_ASSIGN: Interface FastEthernet0/0 assigned DHCP address 192.168.0.103, mask 255.255.255.0, hostname R1
为路由器配置 DNS,用于解析域名
R1# conf t
R1(config)# ip domain-lookup
R1(config)# ip name-server 8.8.8.8
R1(config)# end
测试路由器是否连接互联网,成功
R1# ping www.baidu.com
Translating "www.baidu.com"...domain server (192.168.1.1) [OK]
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 14.215.177.39, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/27/32 ms
内部网络包含两台在同一网段的虚拟机,IP 地址分别为:192.168.1.108
、192.168.1.109
用一台交换机将它们和路由器接口 f0/1
连接。
在 VMware 中创建两台虚拟机,分别为 Ubuntu 16.04 和 CentOS 7
在 GNS3 中导入两台虚拟机,注意勾选:Allow GNS3 to override non custom VMware adapter
在 VMware 中点击 “编辑 - 虚拟网络编辑器”,添加供 GNS3 使用的网卡,注意选择仅主机模式并禁用DHCP。或者在 GNS3 中点击 “Preference - VMware - Advanced local settings - Configure” 选项,调用 gns3vmnet
自动完成。
(由 GNS3 启动虚拟机后,会为虚拟机自动配置网卡)
GNS3 will randomly select an available Host-only VMnet to bridge the VMware virtual machine into the GNS3 topology. VMnet 0 (bridged), VMnet 1 (host-only), and VMnet 8 (NAT) are available in VMware by default, but will not be used by GNS3 for this purpose!
It is important that any new Host-Only VMnet created for GNS3 to use have the default DHCP for it disabled!
192.168.1.108
(192.168.1.109
)255.255.255.0
192.168.1.1
8.8.8.8
两台虚拟机的网关就是路由器接口 f0/1
,为其配置 IP 地址:
R1# conf t
R1(config)# int f0/1
R1(config-if)# ip address 192.168.1.1 255.255.255.0
R1(config-if)# no shutdown
R1(config-if)# end
$ ping 192.168.0.103
PING 192.168.0.103 (192.168.0.103) 56(84) bytes of data.
64 bytes from 192.168.0.103: icmp_seq=1 ttl=255 time=2.64 ms
64 bytes from 192.168.0.103: icmp_seq=2 ttl=255 time=3.80 ms
$ ping 192.168.0.108
PING 192.168.0.108 (192.168.0.108) 56(84) bytes of data.
^C
--- 192.168.0.108 ping statistics ---
12 packets transmitted, 0 received, 100% packet loss, time 11272ms
能 ping
通路由器另一端,但 ping
不通与路由器在同一网段的无线网卡,不能连接互联网,需要配置 NAT。
R1# conf t
R1(config)# int f0/0
R1(config-if)# ip nat outside
R1(config-if)# int f0/1
R1(config-if)# ip nat inside
R1(config-if)# exit
可以选择:静态 NAT 配置、端口复用、动态 NAT 配置。
1. 静态 NAT 配置:ip nat inside source static 内部私有IP地址 公网地址
R1(config)# ip nat inside source static 192.168.1.108 192.168.0.118
R1(config)# ip nat inside source static 192.168.1.109 192.168.0.119
2. 端口复用
// 建立允许内网IP网段进行NAT转换的ACL
access-list ACL编号 permit 内网IP网段 通配符掩码
// 建立端口复用NAT
ip nat inside source list ACL编号 interface 外网接口 overload
R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255
R1(config)#ip nat inside source list 1 interface f0/0 overload
3. 动态 NAT 配置
// 建立允许内网IP网段进行NAT转换的ACL
access-list ACL编号 permit 内网IP网段 通配符掩码
// 建立公网IP地址池
ip nat pool 地址池名称 起始公网地址 结束公网地址 netmask 子网掩码
// 建立动态NAT
ip nat inside source list ACL编号 pool 公网地址池名称
R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255
R1(config)#ip nat pool gen 192.168.0.120 192.168.0.130 netmask 255.255.255.0
R1(config)#ip nat inside source list 1 pool gen
在虚拟机上测试互联网连接,成功
$ ping www.baidu.com
PING www.wshifen.com (104.193.88.123) 56(84) bytes of data.
64 bytes from 104.193.88.123 (104.193.88.123): icmp_seq=1 ttl=50 time=214 ms
64 bytes from 104.193.88.123 (104.193.88.123): icmp_seq=3 ttl=50 time=208 ms
R1# write memory