DHCP And Switch
Consider this following topology
Components:
- Switch1: L2 Ethernet switch
- Switch2: L2 Ethernet switch
- R1: Cisco 3660
[!important]
We pause interconnection between Switch 1 and Switch 2
First the PC1 and 2 will not have IP. First think we need to do is to assign an IP.
In order to do this, R1 need to setup DHCP server and also interconnect Switch 1 and Switch 2 and assign its subnet.
R1:
- Get a list of possible interface
show ip int
- Plug in switch 1 to (FastEthernet 0/0) fe0/0
- Plug in switch 2 to fe0/1
- Go to configure terminal
config t
- Select interface
fe0/0
:int FastEthernet 0/0
- Assign IP address and netmask for switch 1
ip address 9.9.9.1 255.255.255.0
- Enable the interface (bring state to up, by default it's down)
no shutdown
- Exit out of configuration for
fe0/0
:exit
- Assign IP address and netmask for switch 1
- Select interface
fe0/1
:int FastEthernet 0/1
- Assign ip address
ip address 9.9.8.1 255.255.255.0
- Enable interface
no shutdown
- Exit out of configuration:
exit
- Assign ip address
- Save all config to switch for the next run:
write memory
- Confirm all setting up correctly:
show ip interface brief
As the result, we have assigned ip for the two interface port. Next we want to setup DHCP server
R1:
- Go to config term:
config t
- List out current dhcp pool (expect empty result)
show ip dhcp
- Create new pool
default
:ip dhcp pool default
- Setup default router:
default-router 9.9.9.1
.- Note, this will automatically matches with the subnet created above. As a result, this will assign
Switch 1
as default router - End the configuration:
end
- Note, this will automatically matches with the subnet created above. As a result, this will assign
- Confirm again with
show ip dhcp pool
Now technically we can do ip dhcp
on each machine to obtain an IP address
PC1:
ip dhcp
(this will assign9.9.9.2
) since the default dhcp is9.9.9.1
PC2:
ip dhcp
(this will assign9.9.9.3
) since the default dhcp is9.9.9.1
Why would PC2 has 9.9.9.3
whereas it's in the 9.9.8.1/24
subnet?
- Since we dont setup a broadcast domain, PC2 will send a DHCP discover request to the network. This is typically a broadcast.
- The broadcast will then transfer to Switch 2 and subsequently R1.
- R1 will broadcast again to
fe0/0
which is the default DHCP - This is where the ip was assigned
To fix this, release DHCP from PC2: ip dhcp -x
Setup another DHCP pool for fe0/1
:
R1:
- Go to config term:
config t
- List out current dhcp pool (expect empty result)
show ip dhcp
- Create new pool
default
:ip dhcp pool default-b
- Setup default router:
default-router 9.9.8.1
.- Note, this will automatically matches with the subnet created above. As a result, this will assign
Switch 2
as default router - End the configuration:
end
- Note, this will automatically matches with the subnet created above. As a result, this will assign
- Confirm again with
show ip dhcp pool
Redo DHCP on PC2: ip dhcp
Now PC2 will be assigend 9.9.8.2
Test ping from PC1 to PC2 and vice versa should be success.
Note: the arp table for some reasons was stored in the router not the PC. This might be the behavior of VPC (Virtual Computer from GNS3)