Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host R1
R1(config)#int f0/0
R1(config-if)#ip add 172.16.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R1(config-if)#ip dhcp pool test
R1(dhcp-config)#network 172.16.1.0 255.255.255.0
R1(dhcp-config)#default-router 172.16.1.1
R1(dhcp-config)#dns-server 192.168.1.254
R1(dhcp-config)#ip dhcp excluded-address 172.16.1.1 172.16.1.20
R1(config)#ip dhcp excluded-address 172.16.1.254
R1(config)#do show ip dhcp binding
IP address Client-ID/ Lease expiration Type
Hardware address
172.168.1.21 0090.2B95.DE6E -- Automatic
172.168.1.22 0090.2B19.CC33 -- Automatic
注意:如果单臂感觉做不好 可以自己给pc地址 ping通了再做dhcp
路由器:
Router(config)#host R2
R2(config)#interface f0/0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#interface f0/0.2
R2(config-subif)#encapsulation dot1Q 2
R2(config-subif)#ip address 192.168.2.254 255.255.255.0
R2(config-subif)#exit
R2(config)#interface f0/0.3
R2(config-subif)#encapsulation dot1Q 3
R2(config-subif)#ip address 192.168.3.254 255.255.255.0
R2(config-subif)#exit
R2(config)#interface f0/0.4
R2(config-subif)#encapsulation dot1Q 4
R2(config-subif)#ip address 192.168.4.254 255.255.255.0
R2(config-subif)#exit
R2(config)#do show ip int brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset up up
FastEthernet0/0.2 192.168.2.254 YES manual up up
FastEthernet0/0.3 192.168.3.254 YES manual up up
FastEthernet0/0.4 192.168.4.254 YES manual up up
FastEthernet0/1 unassigned YES unset administratively down down
Vlan1 unassigned YES unset administratively down down
R2(config)#do show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.2.0/24 is directly connected, FastEthernet0/0.2
C 192.168.3.0/24 is directly connected, FastEthernet0/0.3
C 192.168.4.0/24 is directly connected, FastEthernet0/0.4
R2(config)#service dhcp
R2(config)#ip dhcp excluded-address 192.168.2.1
R2(config)#ip dhcp excluded-address 192.168.3.1
R2(config)#ip dhcp excluded-address 192.168.4.1
R2(config)#ip dhcp excluded-address 192.168.2.254
R2(config)#ip dhcp excluded-address 192.168.3.254
R2(config)#ip dhcp excluded-address 192.168.4.254
R2(config)#ip dhcp pool vlan2
R2(dhcp-config)#network 192.168.2.0 255.255.255.0
R2(dhcp-config)#dns-server 192.168.2.1
R2(dhcp-config)#default-router 192.168.2.254
R2(dhcp-config)#exit
R2(config)#ip dhcp pool vlan3
R2(dhcp-config)#network 192.168.3.0 255.255.255.0
R2(dhcp-config)#dns-server 192.168.3.1
R2(dhcp-config)#default-router 192.168.3.254
R2(dhcp-config)#exit
R2(config)#ip dhcp pool vlan4
R2(dhcp-config)#network 192.168.4.0 255.255.255.0
R2(dhcp-config)#dns-server 192.168.4.1
R2(dhcp-config)#default-router 192.168.4.254
R2(dhcp-config)#exit
执行:
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host R2
R2(config)#int f0/0
R2(config-if)#no shut
R2(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R2(config-if)#exit
R2(config)#int f0/0.2
R2(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.2, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.2, changed state to up
R2(config-subif)#enc do 2
R2(config-subif)#ip add 192.168.2.254 255.255.255.0
R2(config-subif)#exit
R2(config)#int f0/0.3
R2(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.3, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.3, changed state to up
R2(config-subif)#enc do 3
R2(config-subif)#ip add 192.168.3.254 255.255.255.0
R2(config-subif)#exit
R2(config)#int f0/0.4
R2(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.4, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.4, changed state to up
R2(config-subif)#enc do 4
R2(config-subif)#ip add 192.168.4.254 255.255.255.0
R2(config-subif)#end
R2#
%SYS-5-CONFIG_I: Configured from console by console
R2#show ip int bri
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset up up
FastEthernet0/0.2 192.168.2.254 YES manual up up
FastEthernet0/0.3 192.168.3.254 YES manual up up
FastEthernet0/0.4 192.168.4.254 YES manual up up
FastEthernet0/1 unassigned YES unset administratively down down
Vlan1 unassigned YES unset administratively down down
R2#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.2.0/24 is directly connected, FastEthernet0/0.2
C 192.168.3.0/24 is directly connected, FastEthernet0/0.3
C 192.168.4.0/24 is directly connected, FastEthernet0/0.4
R2#ser dhcp
^
% Invalid input detected at '^' marker.
R2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#ser dhcp
R2(config)#ip dhcp ex
R2(config)#ip dhcp excluded-address 192.168.2.1
R2(config)#ip dhcp excluded-address 192.168.3.1
R2(config)#ip dhcp excluded-address 192.168.4.1
R2(config)#ip dhcp excluded-address 192.168.2.254
R2(config)#ip dhcp excluded-address 192.168.3.254
R2(config)#ip dhcp excluded-address 192.168.4.254
R2(config)#ip dhcp pool vlan2
R2(dhcp-config)#network 192.168.2.0 255.255.255.0
R2(dhcp-config)#dns-server 192.168.2.1
R2(dhcp-config)#default-router 192.168.2.254
R2(dhcp-config)#exit
R2(config)#ip dhcp pool vlan3
R2(dhcp-config)#network 192.168.3.0 255.255.255.0
R2(dhcp-config)#dns-server 192.168.3.1
R2(dhcp-config)#default-router 192.168.3.254
R2(dhcp-config)#exit
R2(config)#ip dhcp pool vlan4
R2(dhcp-config)#network 192.168.4.0 255.255.255.0
R2(dhcp-config)#dns-server 192.168.4.1
R2(dhcp-config)#default-router 192.168.4.254
R2(dhcp-config)#exit
交换机
S3>en
Switch#conf t
S3(config)#host S3
S3(config)#vlan 2
S3(config-vlan)#vlan 3
S3(config-vlan)#vlan 4
S3(config-vlan)#exit
S3(config)#interface f0/2
S3(config-if)#switchport mode access
S3(config-if)#switchport access vlan 2
S3(config-if)#exit
S3(config)#interface f0/3
S3(config-if)#switchport mode access
S3(config-if)#switchport access vlan 3
S3(config-if)#exit
S3(config)#interface f0/4
S3(config-if)#switchport mode access
S3(config-if)#switchport access vlan 4
S3(config-if)#exit
S3(config)#interface f0/24
S3(config-if)#switchport mode trunk
S3(config-if)#switchport trunk allowed vlan 2,3,4
S3(config-if)#end
S3#show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, Fa0/5, Fa0/6, Fa0/7
Fa0/8, Fa0/9, Fa0/10, Fa0/11
Fa0/12, Fa0/13, Fa0/14, Fa0/15
Fa0/16, Fa0/17, Fa0/18, Fa0/19
Fa0/20, Fa0/21, Fa0/22, Fa0/23
Fa0/24, Gig0/1, Gig0/2
2 VLAN0002 active Fa0/2
3 VLAN0003 active Fa0/3
4 VLAN0004 active Fa0/4
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active
执行:
Switch>en
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#host S3
S3(config)#vlan 2
S3(config-vlan)#vlan 3
S3(config-vlan)#vlan 4
S3(config-vlan)#exit
S3(config)#int f0/2
S3(config-if)#swi mode access
S3(config-if)#swi access vlan 2
S3(config-if)#exit
S3(config)#int f0/3
S3(config-if)#swi mode access
S3(config-if)#swi access vlan 3
S3(config-if)#exit
S3(config)#int f0/4
S3(config-if)#swi mode access
S3(config-if)#swi access vlan 4
S3(config-if)#exit
S3(config)#int f0/24
S3(config-if)#swi mode trunk
S3(config-if)#end
S3#
%SYS-5-CONFIG_I: Configured from console by console
S3#show int trunk
S3#show vlan bri
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, Fa0/5, Fa0/6, Fa0/7
Fa0/8, Fa0/9, Fa0/10, Fa0/11
Fa0/12, Fa0/13, Fa0/14, Fa0/15
Fa0/16, Fa0/17, Fa0/18, Fa0/19
Fa0/20, Fa0/21, Fa0/22, Fa0/23
Fa0/24, Gig0/1, Gig0/2
2 VLAN0002 active Fa0/2
3 VLAN0003 active Fa0/3
4 VLAN0004 active Fa0/4
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active
S3#
%LINK-5-CHANGED: Interface FastEthernet0/24, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to up
pc:
测试:
dhcp配置路由器R2的f0/0端口与交换机S3的f0/24端口相连,交换机S3的f0/2端口与vlan 2下的pc2相连,交换机S3的f0/3端口与vlan 3下的pc3相连,交换机S3的f0/2端口与vlan 4下的pc4相连,交换机S3的f0/23端口连接一台Server-PTA注意
f0/0.2:192.168.2.254/24
f0/0.3:192.168.3.254/24
f0/0.4:192.168.4.254/24
f0/0.100:192.168.100.254/24
每个子网池从第10个主机地址开始分配。
DNS:192.168.*.1
Router>en
Router#conf t
Router(config)#int f0/0
Router(config-if)#no shut
Router(config-if)#int f0/0.2
Router(config-subif)#enc do 2
Router(config-subif)#ip add 192.168.2.254 255.255.255.0
Router(config-subif)#ip helper-address 192.168.100.2
Router(config-subif)#exit
Router(config)#int f0/0.3
Router(config-subif)#enc do 3
Router(config-subif)#ip add 192.168.3.254 255.255.255.0
Router(config-subif)#ip helper-address 192.168.100.2
Router(config-subif)#exit
Router(config)#int f0/0.4
Router(config-subif)#enc do 4
Router(config-subif)#ip add 192.168.4.254 255.255.255.0
Router(config-subif)#ip helper-address 192.168.100.2
Router(config-subif)#exit
Router(config)#int f0/0.100
Router(config-subif)#enc do 100
Router(config-subif)#ip add 192.168.100.254 255.255.255.0
Router(config-subif)#exit
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#host s3
s3(config)#vlan 2
s3(config-vlan)#vlan 3
s3(config-vlan)#vlan 4
s3(config-vlan)#vlan100
s3(config-vlan)#interface f0/2
s3(config-if)#switchport mode access
s3(config-if)#switchport access vlan 2
s3(config-if)#exit
s3(config)#interface f0/3
s3(config-if)#switchport mode access
s3(config-if)#switchport access vlan 3
s3(config-if)#exit
s3(config)#interface f0/4
s3(config-if)#switchport mode access
s3(config-if)#switchport access vlan 4
s3(config-if)#exit
S3(config)#int f0/23
S3(config-if)#swi mode access
S3(config-if)#swi access vlan 100
s3(config)#interface f0/24
s3(config-if)#switchport mode trunk
s3(config-if)#exit
s3(config-if)#do show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, Fa0/5, Fa0/6, Fa0/7
Fa0/8, Fa0/9, Fa0/10, Fa0/11
Fa0/12, Fa0/13, Fa0/14, Fa0/15
Fa0/16, Fa0/17, Fa0/18, Fa0/19
Fa0/20, Fa0/21, Fa0/22, Fa0/23
Fa0/24, Gig0/1, Gig0/2
2 VLAN0002 active Fa0/2
3 VLAN0003 active Fa0/3
4 VLAN0004 active Fa0/4
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active