Skip to main content

How to configure DHCP Server on a switch for different VLANs?

 

DHCP (Dynamic Host Configuration Protocol) servers provide all the basic information the client wants to operate on the network, including DNS address, Default Gateway, IP addresses, subnet masks, and many more in detail.

In this lab, we have one switch and 16 PCs. Our task is to assign all the PCs to their VLANs and configure the DHCP server for all VLANs. Ultimately, ensure all the PCs get their IP addresses from the DHCP server. 



  • configure the topology as per the diagram
  • configure VLAN 10,20,30, and 40
  • assign ports to their VLANs 
  • configure IP addresses for VLANs 
  • VLAN 10 192.168.1.1/24
  • VLAN 20 192.168.2.1/24
  • VLAN 30 192.168.3.1/24
  • VLAN 40 192.168.4.1/24
  • configure DHCP server for all VLANs
  • ensure that all PCs get IPs
  • verify with show commands
  • configure IP routing command 


SW-dhcp-(config)#vlan 10
SW-dhcp-(config-vlan)#name vlan10
SW-dhcp-(config-vlan)#exit

SW-dhcp-(config)#vlan 20
SW-dhcp-(config-vlan)#name vlan20
SW-dhcp-(config-vlan)#exit

SW-dhcp-(config)#vlan 30
SW-dhcp-(config-vlan)#name vlan30
SW-dhcp-(config-vlan)#exit

SW-dhcp-(config)#vlan 40
SW-dhcp-(config-vlan)#name vlan40
SW-dhcp-(config-vlan)#exit

SW-dhcp-(config)#interface range ethernet 0/0-3
SW-dhcp-(config-if-range)#switchport
SW-dhcp-(config-if-range)#switchport mode access
SW-dhcp-(config-if-range)#switchport access vlan 10
SW-dhcp-(config-if-range)#exit

SW-dhcp-(config)#interface range ethernet 1/0-3
SW-dhcp-(config-if-range)#switchport
SW-dhcp-(config-if-range)#switchport mode access
SW-dhcp-(config-if-range)#switchport access vlan 20
SW-dhcp-(config-if-range)#exit

SW-dhcp-(config)#interface range ethernet 2/0-3
SW-dhcp-(config-if-range)#switchport
SW-dhcp-(config-if-range)#switchport mode access
SW-dhcp-(config-if-range)#switchport access vlan 30
SW-dhcp-(config-if-range)#exit

SW-dhcp-(config)#interface range ethernet 3/0-3
SW-dhcp-(config-if-range)#switchport
SW-dhcp-(config-if-range)#switchport mode access
SW-dhcp-(config-if-range)#switchport access vlan 40
SW-dhcp-(config-if-range)#exit

SW-dhcp-#show vlan
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active
10   vlan10                           active    Et0/0, Et0/1, Et0/2, Et0/3
20   vlan20                           active    Et1/0, Et1/1, Et1/2, Et1/3
30   vlan30                           active    Et2/0, Et2/1, Et2/2, Et2/3
40   vlan40                           active    Et3/0, Et3/1, Et3/2, Et3/3



SW-dhcp-(config)#interface vlan 10
SW-dhcp-(config-if)#ip address 192.168.1.1 255.255.255.0
SW-dhcp-(config-if)#no shutdown
SW-dhcp-(config-if)#exit

SW-dhcp-(config)#interface vlan 20
SW-dhcp-(config-if)#ip address 192.168.2.1 255.255.255.0
SW-dhcp-(config-if)#no shutdown
SW-dhcp-(config-if)#exit

SW-dhcp-(config)#interface vlan 30
SW-dhcp-(config-if)#ip address 192.168.3.1 255.255.255.0
SW-dhcp-(config-if)#no shutdown
SW-dhcp-(config-if)#exit


SW-dhcp-(config)#interface vlan 40
SW-dhcp-(config-if)#ip address 192.168.4.1 255.255.255.0
SW-dhcp-(config-if)#no shutdown
SW-dhcp-(config-if)#exit
SW-dhcp-(config)#end

SW-dhcp-#show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol

Vlan10                 192.168.1.1     YES manual up                    up
Vlan20                 192.168.2.1     YES manual up                    up
Vlan30                 192.168.3.1     YES manual up                    up
Vlan40                 192.168.4.1     YES manual up                    up


SW-dhcp-(config)#service dhcp
SW-dhcp-(config)#ip dhcp pool vlan10
SW-dhcp-(dhcp-config)#network 192.168.1.2 255.255.255.0
SW-dhcp-(dhcp-config)#default-router 192.168.1.1
SW-dhcp-(dhcp-config)#dns-server 8.8.8.8
SW-dhcp-(dhcp-config)#exit

SW-dhcp-(config)#service dhcp
SW-dhcp-(config)#ip dhcp pool vlan20
SW-dhcp-(dhcp-config)#network 192.168.2.2 255.255.255.0
SW-dhcp-(dhcp-config)#default-router 192.168.2.1
SW-dhcp-(dhcp-config)#dns-server 8.8.8.8
SW-dhcp-(dhcp-config)#exit

SW-dhcp-(config)#service dhcp
SW-dhcp-(config)#ip dhcp pool vlan30
SW-dhcp-(dhcp-config)#network 192.168.3.2 255.255.255.0
SW-dhcp-(dhcp-config)#default-router 192.168.3.1
SW-dhcp-(dhcp-config)#dns-server 8.8.8.8
SW-dhcp-(dhcp-config)#exit

SW-dhcp-(config)#service dhcp
SW-dhcp-(config)#ip dhcp pool vlan40
SW-dhcp-(dhcp-config)#network 192.168.4.2 255.255.255.0
SW-dhcp-(dhcp-config)#default-router 192.168.4.1
SW-dhcp-(dhcp-config)#dns-server 8.8.8.8
SW-dhcp-(dhcp-config)#exit

SW-dhcp-(config)#ip routing
SW-dhcp-(config)#exit


SW-dhcp-#show ip dhcp binding
Bindings from all pools not associated with VRF:
IP address      Client-ID/              Lease expiration        Type       State      Interface
                Hardware address/
                User name
192.168.1.2     0100.5079.6668.00       Dec 15 2024 11:16 AM    Automatic  Active     Vlan10
192.168.1.3     0100.5079.6668.01       Dec 15 2024 11:16 AM    Automatic  Active     Vlan10
192.168.1.4     0100.5079.6668.02       Dec 15 2024 11:16 AM    Automatic  Active     Vlan10
192.168.1.5     0100.5079.6668.03       Dec 15 2024 11:16 AM    Automatic  Active     Vlan10
192.168.2.2     0100.5079.6668.04       Dec 15 2024 11:17 AM    Automatic  Active     Vlan20
192.168.2.3     0100.5079.6668.05       Dec 15 2024 11:17 AM    Automatic  Active     Vlan20
192.168.2.4     0100.5079.6668.06       Dec 15 2024 11:17 AM    Automatic  Active     Vlan20
192.168.2.5     0100.5079.6668.07       Dec 15 2024 11:17 AM    Automatic  Active     Vlan20
192.168.3.2     0100.5079.6668.0d       Dec 15 2024 11:17 AM    Automatic  Active     Vlan30
192.168.3.3     0100.5079.6668.0c       Dec 15 2024 11:17 AM    Automatic  Active     Vlan30
192.168.3.4     0100.5079.6668.0b       Dec 15 2024 11:17 AM    Automatic  Active     Vlan30
192.168.3.5     0100.5079.6668.0a       Dec 15 2024 11:18 AM    Automatic  Active     Vlan30
192.168.4.2     0100.5079.6668.14       Dec 15 2024 11:16 AM    Automatic  Active     Vlan40
192.168.4.3     0100.5079.6668.15       Dec 15 2024 11:16 AM    Automatic  Active     Vlan40
192.168.4.4     0100.5079.6668.16       Dec 15 2024 11:17 AM    Automatic  Active     Vlan40
192.168.4.5     0100.5079.6668.17       Dec 15 2024 11:17 AM    Automatic  Active     Vlan40



PC1> ip dhcp
DDORA IP 192.168.1.2/24 GW 192.168.1.1

PC1> show ip

NAME        : PC1[1]
IP/MASK     : 192.168.1.2/24
GATEWAY     : 192.168.1.1
DNS         : 8.8.8.8
DHCP SERVER : 192.168.1.1
DHCP LEASE  : 84926, 86400/43200/75600
MAC         : 00:50:79:66:68:00
LPORT       : 10018
RHOST:PORT  : 127.0.0.1:10019
MTU:        : 1500









Comments

Popular posts from this blog

What is Classification and marking? What is IP Precedence and DSCP Values? What is AF and EF?

  Classification and Marking Classification and marking are the processes of identifying the priority of each packet. This is the first step of QOS control and should be done near the source hosts. Classification is the process of identifying and categorising traffic into classes, typically based upon incoming interface IP precedence, DSCP Source or Destination address. Application classification is the most fundamental QOS building block. Without classification, all packets are treated the same.   The table lists the criteria of classification                                  Marking  Marking is the QOS feature component that colours a packet so it can be identified and distinguished from other packets in QOS treatment. Commonly used markers: link-layer: COS (ISL, 802.1q), MPLS EXP bits,...

OSPF default routing

  OSPF Default Route Configuring OSPF Default route is not a big problem. We have couple of options when we want to OSPF default route. Here is an example R1(config)#router ospf 1  R1(config-router)#default-information originate ?   always       Always advertise default route   metric       OSPF default metric   metric-type  OSPF metric type for default routes   route-map    Route-map reference   <cr> We can change numbers of things for example metric or metric type but most of the people forget about the most important thing is the always keyword.  If we add the always command this feature advertises the default route even if we do not have in our routing table. It will look like that route is installed in routing table.   When we use the default information originate we can advertise a default route in OSPF. But OSPF won’t...

BGP Local preference configuration

BGP Local preference (Local_Pref) Path attribute gives the router inside a single autonomous system a value that they can set per-route and advertise to all iBGP routers inside the autonomous system, so that all routers in the autonomous system agree about which routers is the best exit point for packet destined for that prefix. Local preference (Local_Pref) is the second BGP attribute. We can use the local preference to choose the outbound external BGP path. Local preference is sent to all internal BGP (iBGP) routers in our autonomous system. Local preference (Local_Pref) is not exchanged between external BGP routers. It’s a well-known and discretionary BGP attribute. Default value is 100. The path with the highest local preference is desirable  Topology:- TASK: To reach 50.1.1.1, 15.0.0.1 network router 2 and router 3 using 3.1.1.2 path ( AS 65144) because it has less numbers of au...