进入全局模式,并为设备命名
<Huawei>system-view
[Huawei]sysname S1
创建vlan
[S1]vlan batch 3 9 1002
进入端口,将端口修改为access模式
[S1]interface GigabitEthernet 0/0/3
[S1-GigabitEthernet0/0/3]port link-type access
[S1-GigabitEthernet0/0/3]port default vlan 3
[S1-GigabitEthernet0/0/3]quit
进入端口,将端口修改为trunk模式,并只允许某些端口通过
[S1]interface GigabitEthernet 0/0/1
[S1-GigabitEthernet0/0/1]port link-type trunk
[S1-GigabitEthernet0/0/1]port trunk allow-pass vlan 3 9 1002
配置dhcp
[S3]dhcp enable
[S3]interface Vlanif 3
[S3-Vlanif3]ip address 172.16.3.1 24
[S3-Vlanif3]interface Vlanif 9
[S3-Vlanif9]ip address 172.16.9.1 24
[S3-Vlanif9]dhcp select global
[S3-Vlanif9]interface Vlanif 1002
[S3-Vlanif1002]ip address 192.168.2.1 24
[S3-Vlanif1002]quit
[S3]ip pool vlan9
[S3-ip-pool-vlan9]gateway-list 172.16.9.1
[S3-ip-pool-vlan9]network 172.16.9.0 mask 255.255.255.0
[S3-ip-pool-vlan9]lease day 3
[S3-ip-pool-vlan9]dns-list 8.8.8.8
配置ospf
[S3]ospf 1
[S3-ospf-1]area 0
[S3-ospf-1-area-0.0.0.0]network 192.168.2.0 0.0.0.255
[S3-ospf-1-area-0.0.0.0]network 172.16.3.0 0.0.0.255
[S3-ospf-1-area-0.0.0.0]network 172.16.9.0 0.0.0.255
[S3-ospf-1-area-0.0.0.0]quit
[S3-ospf-1]quit
配置静态路由
[R1]ip route-static 0.0.0.0 0 192.168.56.1
通过ospf1重分发静态路由
[R1]ospf 1
[R1-ospf-1]default-route-advertise always cost 200 type 1
为端口配合ip地址
[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ip address 192.168.2.2 24
[R1-GigabitEthernet0/0/1]quit
[S4]interface Vlanif 1004
[S4-Vlanif1004]ip address 192.168.4.1 24
[S4-Vlanif1004]quit
查看路由表
<R1>display ip routing-table