Hack My Planet
Day 15: DHCP & DNS
Write out what the code specifically does line-by-line
For example:
Line 1: Define a function isPalindrome() that takes in a parameter named string
Line 2: blah blah blah
1 def isPalindrome(string):
2 left_pos = 0
3 right_pos = len(string) - 1
4
5 while right_pos >= left_pos:
6 if string[left_pos] != string[right_pos]:
7 return False
8 left_pos += 1
9 right_pos -= 1
10 return True
Dynamic Host Configuration Protocol (DHCP)
- DHCP servers allocate IP addresses on the network and remembers who owns that address, and leases it to them for a limited time
- Dynamic: constantly changing
- Host: computer
- Configuration: configuring your networking settings
- Protocol: set of rules that define how to do things
- This can be advantageous compared to distributing static IP addresses because that can be time-consuming and inefficient
DHCP Server Setup
- One student's Pi will be the server
- Having multiple on one network can cause complications
- Everyone gather around the server Pi during setup
sudo apt-get update
sudo apt-get install dnsmasq
- Disconnect the bridge from school connection and plug in the Ethernet cable to the server Pi
- Need to configure the DHCP server software
cd /etc
sudo mv dnsmasq.conf dnsmasq.default
sudo nano dnsmasq.conf
DHCP Server Setup
interface=eth0
dhcp-range=10.4.4.100,10.4.4.254,255.255.255.0,12h
- The first line tells dnsmasq to listen for DHCP requests on the Ethernet port of the Pi
- The second line specifies the range of IP addresses the server can give out. The 12h at the end specifies the lease time
- Press 'Ctrl+X' to quit out of nano (Press 'y' to confirm saving, then 'Enter' to leave the filename as the default)
- Enter the following command to restart the dnsmasq service:
sudo service dnsmasq restart
- Server is now active and listening for requests from client hosts
DHCP Client Setup
- Configure your network interface file to get an IP address from a DHCP server
- sudo nano /etc/network/interfaces
- change 'iface eth0 inet manual' to 'iface eth0 inet dhcp'
sudo service networking restart
ifconfig
Domain Name System
- DNS looks up the server IP addresses for the websites you want to connect to
- Translates domain or host names (i.e. google.com) into IP addresses and vice versa
- DNS query
- When you type a website address into your browser, your computer contacts a DNS server to obtain the corresponding IP address
- The client then directly communicates with the server using the returned IP address
DNS Server Setup
- Edit the dnsmasq configuration file: sudo nano /etc/dnsmasq.conf
- DNS doesn't have a broadcasting location system like DHCP so the clients need to be told the IP, and the hosts file for the lookup database for DNS queries must be specified.
dhcp-option=6,IP_ADDRESS
no-hosts
addn-hosts=/etc/hosts.dnsmasq
DNS Server Setup
- Create the lookup table for host names:
sudo nano /etc/hosts.dnsmasq
- The line you will be adding must follow a specific format: IP<tab>hostname
- Unplug all other Ethernet connections. Restart the dnsmasq service: sudo service dnsmasq restart
- To make the DHCP server work with its own DNS server:
sudo nano /etc/resolv.conf
The file should have the following one line only:
nameserver 127.0.0.1
sudo service networking restart
DNS Client Setup
- ifconfig to check if the IP address is obtained from the DHCP server
- ping serverpi to get a response from the IP address
Hack My Planet Day 15 DHCP & DNS
By jtheadland
Hack My Planet Day 15 DHCP & DNS
- 643