交换部分——Vlan、DHCP、STP

描述:

每台电脑代表一个部门,其中pc1、pc2、pc3、pc4则依次为vlan10、vlan20、vlan30、vlan40。

两台接入交换机LSW2、LSW3分别连接vlan10vlan20,vlan30vlan40

上行汇聚交换机LSW1开启DHCP服务,DNS设置为3.0.0.1

二层交换机直接互连,因此需开启STP,并将三层交换机设置为根。

下面命令,第一次都全拼且有注释,后续全为缩写

二层交换LSW2配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
system-view  //进入系统视图
sysname sw2 //修改交换机名字

vlan batch 10 20 30 40 //批量增设vlan10 vlan20 vlan30 vlan40

interface Ethernet0/0/1 //进入1接口的视图
port link-type access //配置为access模式
port default vlan 10 //配置接口的VLAN

int e0/0/2
p l a
p d v 20

interface Ethernet0/0/3
port link-type trunk //配置为trunk模式
port trunk allow-pass vlan 10 20 30 40 //配置接口放行的VLAN

int e0/0/4
p l t
p t a v 10 20 30 40

二层交换LSW3配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sys
sys sw3

vlan batch 10 20 30 40
interface Ethernet0/0/3
port link-type access
port default vlan 30
int e0/0/4
p l a
p d v 40
interface Ethernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20 30 40
int e0/0/2
p l t
p t a v 10 20 30 40

三层交换机LSW1配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
sys
sys sw1

dhcp enable // 开启DHCP功能
vlan batch 10 20 30 40
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 10 20 30 40
int g0/0/3
p l t
p t a v 10 20 30 40

interface Vlanif10 //虚拟一个vlan10接口(需已创建vlan10)
ip address 192.168.10.254 255.255.255.0 //为该虚拟接口配置ip地址
dhcp select interface //在该接口上开启DHCP
dhcp server dns-list 3.0.0.1 //在该接口DHCP上设定DNS服务地址
int vlanif20
ip add 192.168.20.254 24
dhcp sel int
dhcp server dns 3.0.0.1
int vlanif30
ip add 192.168.30.254 24
dhcp sel int
dhcp server dns 3.0.0.1
int vlanif40
ip add 192.168.40.254 24
dhcp sel int
dhcp server dns 3.0.0.1

stp root primary //设置该交换机为STP的根服务器(由于华为交换机默认开启STP,所以都没有输入开启命令)

注:下游电脑获取到DHCP授权的ip地址的前提是交换机开起了DHCP功能,并在接口上启用DHCP,同时设置了VlanIf的ip地址,并且链路是放行了vlan。

基础命令 说明与用例
vlan * 创建vlan
vlan batch * * 同时创建多个vlan
用例:vlan batch 20 40 || vlan bath 20 to 40 (配置vlan20到vlan40)
interface Ethernet 进入接口模式(百兆口)
port link-type access 接口类型配置为access
port default vlan * 为接口配置vlan
用例:port default vlan 10
interface GigabitEthernet 进入接口模式(千兆口)
port link-type trunk 接口类型配置为trunk
port trunk pvid vlan * 接口配置pvid ——打上的vlan标签
port trunk allow-pass vlan * 接口放行对应的vlan通过
用例:port trunk allow-pass vlan 10 20
interface Vlanif * 对已创建的vlan,创建一个vlanif接口,作为改vlan的网关
用例:int vlan 10
ip address * 为vlanif接口添加ip地址——其下vlan设备的网关地址
用例:ip address 192.168.1.254 24

路由部分——动态路由ospf、静态路由、NAT

在上文的拓扑基础上,增加一个出口路由器

首先需要配置LSW1,增加到AR1的链路信息与配置ospf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
vlan 12
interface GigabitEthernet0/0/2
port link-type access
port default vlan 12
interface Vlanif12
ip address 192.168.12.2 255.255.255.0


// 开启ospf,并设定router-id为2.2.2.2
// 开启area0
// 宣告设备所连接的网段信息
ospf 1 router-id 2.2.2.2
area 0.0.0.0
network 192.168.12.2 0.0.0.0
network 192.168.10.254 0.0.0.0
network 192.168.20.254 0.0.0.0
network 192.168.30.254 0.0.0.0
network 192.168.40.254 0.0.0.0

配置AR1路由器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
sys
sys r1
int s4/0/0
ip add 192.168.12.1 24


ospf 1 router-id 1.1.1.1
area 0
network 192.168.12.1 0.0.0.0

//设置静态缺省路由,让未配置的网段路由统一走下一跳到12.0.0.2(假定该ip地址为AR1路由器所连接的公网路由器ip)
ip route-static 0.0.0.0 0.0.0.0 12.0.0.2
//将该静态缺省路由通过ospf宣告给ospf下的其他三层设备
ospf 1
default-route-advertise

假设在AR1路由器的右侧连接了运营商的公网路由器,其ip地址为12.0.0.2,运营商分配的公网ip为12.0.0.1

设置NAT出口策略

1
2
3
4
5
6
//创建一条acl策略,规则为全放行
acl 2000
rule 1 permit
进入连接了公网路由器的1口,配置nat出口策略(使用2000号的acl规则)
int g0/0/1
nat outbound 2000

再增设3个路由器与2台服务器,对应公网的情况。

AR2通过串口线与AR1连接,也就是12.0.0.2ip的公网路由器。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sys
sys R2
int s4/0/0
ip add 12.0.0.2 24
int g0/0/0
ip add 23.0.0.2 24
int g0/0/1
ip add 24.0.0.2 24

ospf 1 router-id 2.2.2.2
area 0
network 12.0.0.2 0.0.0.0
network 23.0.0.2 0.0.0.0
network 24.0.0.2 0.0.0.0

AR3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sys
sys R3
int g0/0/0
ip add 23.0.0.3 24
int g0/0/1
ip add 34.0.0.3 24
int g0/0/2
ip add 3.0.0.254 24

ospf 1 router-id 3.3.3.3
a 0
net 23.0.0.3 0.0.0.0
net 34.0.0.3 0.0.0.0
net 3.0.0.254 0.0.0.0

AR4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sys
sys R4
int g0/0/0
ip add 24.0.0.4 24
int g0/0/1
ip add 34.0.0.4 24
int g0/0/2
ip add 4.0.0.254 24

ospf 1 router-id 4.4.4.4
a 0
net 24.0.0.4 0.0.0.0
net 34.0.0.3 0.0.0.0
net 4.0.0.254 0.0.0.0

为dns服务器配置3.0.0.1地址,http服务器配置4.0.0.1地址

则私网的pc都可以连通到公网的这两个服务

注意:配置记得保存,以及模拟器会定期休眠。时间太久可能某一台路由器宕机了导致链路不通。

点对点协议认证

以上图为例,在右侧的AR2配置认证模式与账号密码

1
2
3
4
5
6
7
8
9
//配置认证模式为chap
interface Serial4/0/0
ppp authentication-mode chap
q

//创建用户,并将用户用于ppp协议
aaa
local-user magiku password cipher magiku030
local-user magiku service-type ppp

注:点对点协议是基于串口线连接的设备之间。