拓扑
在三层交换机SW1下的局域网中有vlan10、vlan20、vlan30,网关分别为192.168.10.1/24、192.168.20.1/24和192.168.218.10/24,都配置在三层交换机的vlanif上;
PC1和PC2的IP地址分别为192.168.10.10/24、192.168.20.20/24
web服务器地址为192.168.218.19;
三层交换机的vlan40用来和路由器R3连接,地址段为11.0.0.0/24;
R3和R4之间的地址段为12.0.0.0/24,模拟公网;
R4g0/0/1口下是网段为172.16.0.0/24的局域网,用于访问192.168.218.0/24网段的web服务器;
最后实现vlan间通信,并向外提供web服务。
配置
配置IP地址
R3
sys
sysname R3
in g0/0/0
un sh
ip add 11.0.0.1 24
q
in g0/0/1
un sh
ip add 12.0.0.1 24
q
R4
sys
sysname R4
in g0/0/0
un sh
ip add 12.0.0.2 24
q
in g0/0/1
un sh
ip add 172.16.0.1 24
q
配置三层交换机、vlan
sys
sysname SW1
vlan bat 10 20 30
int g0/0/1
port link-type access
port default vlan 10
q
int g0/0/2
port link-type access
port default vlan 20
q
int g0/0/3
port link-type access
port default vlan 30
q
int g0/0/4
port link-type access
port default vlan 40
q
int Vlanif 10
ip add 192.168.10.1 24
q
int Vlanif 20
ip add 192.168.20.1 24
q
int Vlanif 30
ip add 192.168.218.10 24
q
int Vlanif 40
ip add 11.0.0.2 24
q
ip route-static 0.0.0.0 0.0.0.0 11.0.0.1
PC1 ping PC2
R3 ping SW1
配置路由
R3
ip route-static 0.0.0.0 0.0.0.0 12.0.0.2
ip route-static 192.168.218.0 255.255.255.0 11.0.0.2
ip route-static 192.168.20.0 255.255.255.0 11.0.0.2
ip route-static 192.168.10.0 255.255.255.0 11.0.0.2
R4
ip route-static 0.0.0.0 0.0.0.0 12.0.0.2
R3 ping PC1、PC2、web server
R4 ping R3
配置NAT
R3
把公网接口的8080端口映射到web server的80端口
acl 3000
rule permit ip source 192.168.10.0 0.0.0.255
rule permit ip source 192.168.20.0 0.0.0.255
q
in g0/0/1
nat server protocol tcp global current-interface 8080 inside 192.168.218.19 80
nat outbound 3000
R4
acl 3000
rule permit ip source 172.16.0.0 0.0.0.255
q
int g0/0/0
nat outbound 3000
配置web服务器
安装nginx
[root@localhost ~]# tar -xf nginx-1.16.1.tar.gz
[root@localhost ~]# cd nginx-1.16.1/
[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx
[root@localhost nginx-1.16.1]# make && make install
开启nginx服务
[root@localhost nginx-1.16.1]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ./nginx
可以使用命令ln -s /usr/local/nginx/sbin/* /usr/local/sbin/创建命令的软链接
验证
使用cloud3中的172.16.0.100测试机访问web server