Службы DHCP и DNS
Изучите настройку и управление серверами DHCP для назначения IP-адресов и серверами DNS для разрешения имён
«Службы DHCP и DNS» — бесплатный урок Linux Networking & TCP/IP for Developers на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Linux Networking & TCP/IP for Developers, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Linux Networking & TCP/IP for Developers содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
Network's Dynamic Duo: DHCP & DNS
Welcome to understanding two foundational services in any Linux network: DHCP and DNS.
These protocols work behind the scenes to make network communication smooth and user-friendly. One assigns network details, the other translates names.
DHCP: Automatic IP Assignment
DHCP stands for Dynamic Host Configuration Protocol. Its main job is to automatically assign IP addresses and other network settings (like subnet mask, default gateway, and DNS server addresses) to devices on a network.
- Saves time: No need to manually configure each device.
- Prevents errors: Avoids duplicate IP addresses.
- Flexible: Easily manage IP address pools.
How DHCP Works: The DORA Process
When a device connects to a network, it uses a four-step process called DORA to get an IP address from a DHCP server:
- Discover: Client broadcasts a request for a DHCP server.
- Offer: DHCP server offers an available IP address.
- Request: Client accepts the offered IP.
- Acknowledge: Server confirms the lease and provides full configuration.
Setting Up a DHCP Server on Linux
On Linux, a common DHCP server is provided by the isc-dhcp-server package (or dhcpd). The primary configuration file is typically located at /etc/dhcp/dhcpd.conf.
This file defines subnets, IP ranges, default gateways, and DNS servers that clients will receive.
`dhcpd.conf` Example for a Subnet
Here's a simplified example of a dhcpd.conf entry for a local network. This tells the server what IPs to offer and what network details to provide.
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.150;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
option domain-name "example.com";
default-lease-time 600;
max-lease-time 7200;
}DNS: Translating Names to IPs
DNS, or the Domain Name System, is like the internet's phonebook. It translates human-readable domain names (e.g., google.com) into machine-readable IP addresses (e.g., 142.250.191.46).
Without DNS, you'd have to remember complex IP addresses for every website!
How DNS Resolution Works
When you type a domain name into your browser, a DNS query goes through several steps:
- Your computer checks its local cache.
- If not found, it asks a recursive DNS resolver (often provided by your ISP or a public one like 8.8.8.8).
- The resolver queries root servers, then TLD servers (.com, .org), and finally the authoritative name server for the specific domain.
- The authoritative server returns the IP address, which your computer then uses to connect.
Setting Up a DNS Server (BIND)
On Linux, BIND (Berkeley Internet Name Domain) is the most common DNS server software. It's also known as named.
BIND manages zones, which are files containing records that map domain names to IP addresses (and vice versa) for specific domains.
Zone files are typically configured in /etc/bind/.
Simple DNS Forward Zone File
This is an example of a forward zone file for example.com. It defines how specific names within that domain map to IP addresses.
@represents the domain itself.NSrecords specify name servers.Arecords map hostnames to IPv4 addresses.
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
2023010101 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ; Minimum TTL
)
@ IN NS ns1.example.com.
ns1 IN A 192.168.1.10
www IN A 192.168.1.10
mail IN A 192.168.1.20Troubleshooting DHCP and DNS
When things go wrong, these commands are your friends:
systemctl status dhcpd/named: Check service status.journalctl -u dhcpd/named: View service logs.ip a: Verify your device's IP address (from DHCP).dig example.com: Query DNS for a domain.nslookup example.com: Another tool to query DNS.
Quick Check: DHCP vs. DNS
You've learned about the distinct roles of DHCP and DNS. Let's test your understanding!
Recap: DHCP & DNS Essentials
In this lesson, you gained insight into DHCP and DNS:
- DHCP automates IP address assignment, saving time and preventing errors.
- DNS translates human-readable domain names into machine-readable IP addresses.
- Both are critical services for any functional network, ensuring devices get online and can find each other by name.
Keep exploring these services to master network configuration!
Изучай Linux Networking & TCP/IP for Developers с ИИ-репетитором — бесплатно
Пиши и запускай код прямо в браузере, получай мгновенную помощь от ИИ-репетитора 24/7 и продолжи учиться на сайте или в приложении.
- Курсы
- 12
- Уроки
- 48
Часто задаваемые вопросы
Урок «Службы DHCP и DNS» бесплатный?
Да — полный текст урока «Службы DHCP и DNS» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Linux Networking & TCP/IP for Developers, подпишись на CoddyKit PRO. Курс Linux Networking & TCP/IP for Developers содержит 4 уроков всего.
Чему я научусь в уроке «Службы DHCP и DNS»?
Изучите настройку и управление серверами DHCP для назначения IP-адресов и серверами DNS для разрешения имён Ты практикуешь Linux Networking & TCP/IP for Developers с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Linux Networking & TCP/IP for Developers?
Предыдущий опыт не требуется. Linux Networking & TCP/IP for Developers на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.
Сколько времени занимает урок «Службы DHCP и DNS»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Linux Networking & TCP/IP for Developers?
Да. Каждый урок Linux Networking & TCP/IP for Developers включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- SSH для безопасного удалённого доступа
- Веб-службы HTTP/HTTPS
- Службы DHCP и DNS
- NTP и службы синхронизации времени