DHCP (Dynamic Host Configuration Protocol) automatically assigns IP addresses and network parameters to client devices. On Cisco devices, a switch or router can be configured as a DHCP server or a DHCP relay to forward requests to a remote server.
Main Functions:
- DHCP Server — Assigns IP addresses to clients.
- DHCP Relay (ip helper-address) — Forwards DHCP requests from different subnets to a centralized DHCP server.
#DHCP
#DHCP servers use UDP 67 port
#DHCP clients use UDP 68 port
#Magic cookie?!
| --> DHCP Discover (I need IP addr) --> |
| broadcast request Src:68 Dst:67 |
| <--DHCP Offer (how about this IP addr? <-- |
DHCP | (Src:67, Dst:68) | DHCP
CLIENT | -->DHCP Request (I want to use the IP addr you offered) --> | SERVER
| (Src:68, Dst:67) |
| <--DHCP Ack (Okay, you may use it), Src:67, Dst:68)<-- |
| |
#Discover CLIENT-SERVER Broadcast
#Offer SERVER-CLIENT Broadcast or Unicast
#Request CLIENT-SERVER Broadcast
#Ack SERVER-CLIENT Broadcast or Unicast
#Release CLIENT-SERVER Unicast
#DHCP Relay on Cisco routers
#DHCP relay agent
#DHCP server
#DHCP client
#DHCP SERVER
ip dhcp excluded-address 192.168.1.1 192.168.1.10 #to specify a range of IP addresses that won`t be given to DHCP clients
ip dhcp pool <pool-name>
dns-server <IP address>
domain-name <domain-name>
default-router <GW IP address>
lease {<days hourse mitutes> | infinite}
show ip dhcp binding
#DHCP RELAY AGENT
#Choose the interface that the clients connected
interface <clients connected interface>
ip helper-address <DHCP Server IP address>
show ip interface <clients connected interface> #there is info about helper
#DHCP CLIENT CONFIGURATION
interface <interface>
ip address dhcp
#Make IP address "STAIC" by DHCP
ip dhcp pool <DHCP pool name> #for each entry you have to create a new DHCP pool
host <IP address mask>
client-identifier <01+MAC> # If MAC=0026.18d5.b5d7, then write 0100.2618.d5b5.d7
default-router <IP default gateway>
domain-name <domain name>
dns-server <dns server 1 dns server 2>
lease {<days hourse mitutes> | infinite}
#Client-identifier format in DHCP:
#01 — Client Hardware Type (Ethernet MAC)
#03 - Token Ring
#06 - IEEE 802 Networks
#Additional options:
option 42 ip 192.168.1.100 192.168.1.101 #NTP servers
option 66 ip 192.168.1.200 #TFTP IP address
option 121 hex 18C0A86400C0A80101 #<prefix length>+<network>+<gateway> each field must be hex format
#Example 1: Add the static route for the network 192.168.100.0/24 by the gateway 192.168.1.1
#Prefix length = 24, in hex =18
#Network = 192.168.100.0
# In decimal: 11000000.10101000.01100100.00000000
# First 24 bit (192.168.100) in hex = C0A864
#Gateway = 192.168.1.1
# In decimal: 11000000.10101000.00000001.00000001
# In hex = C0A80101
#The total value is 18C0A86400C0A80101
#Example 2: Add the static route for the network 10.1.2.0/23 by the gateway 192.168.1.254
#Prefix length = 23, in hex 17
#Network = 10.1.2.0: 10.1.2 -->0A0102
#Gateway = 192.168.1.254 -->C0A801FE
#How to count
#hex
# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
#Example 1:
# 24 in decimal ÷ 16 = 1 + 8, in hex = 18
#Example 1:
# In decimal 160 ÷ 16 =10 + 0, now we have to conver 10 again (because there in no 10 in hex). Decimal 10 in hex = A
# 160 in decimal = 0A in hex