Настройка и разрешение DNS
Разберитесь, как работает DNS в Linux, настраивайте DNS-клиенты и устраняйте неполадки разрешения имён
«Настройка и разрешение 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 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
DNS: Name to Number
Welcome! Today we'll explore DNS (Domain Name System) in Linux. DNS is like the internet's phonebook, translating human-friendly domain names (like google.com) into machine-readable IP addresses (like 142.250.186.174).
Without DNS, you'd have to remember long numbers for every website or service you want to reach!
Your Linux DNS Client
In Linux, the primary configuration file for how your system resolves domain names is /etc/resolv.conf. This file tells your computer which DNS servers to ask when it needs to find an IP address for a hostname.
Think of it as your local DNS directory.
The `nameserver` Directive
The most important line in /etc/resolv.conf is nameserver. It specifies the IP address of a DNS server that your system should use.
- You can list multiple
nameserverentries. - Your system will try them in order until it gets a response.
- Common public DNS servers are Google's (
8.8.8.8,8.8.4.4) or Cloudflare's (1.1.1.1).
View Your Current DNS
Let's see what DNS servers your system is currently configured to use. We can do this by displaying the contents of the /etc/resolv.conf file.
Try running the command below:
cat /etc/resolv.confDomain & Search Directives
Besides nameserver, you might also see domain and search directives in /etc/resolv.conf:
domain example.com: Sets the default domain name for the local host.search example.com mycorp.local: Specifies a list of domains to try appending to hostnames that aren't fully qualified.
For example, if you ping webserver and search is mycorp.local, it will try webserver.mycorp.local.
Basic Lookups with `host`
The host command is a simple utility for performing DNS lookups. It's great for quickly finding the IP address of a domain or the domain name for an IP address.
It provides concise answers, making it perfect for quick checks.
`host` Command in Action
Let's use host to resolve a common domain. This command will query your configured DNS servers and return the associated IP address(es).
Run the example:
host coddykit.comDetailed Queries with `dig`
For more detailed DNS information, the dig (Domain Information Groper) command is your go-to tool. It provides a comprehensive output of DNS records, including authoritative nameservers, record types (A, MX, NS, etc.), and more.
It's invaluable for troubleshooting.
`dig`ging for Records
Execute dig to see a full DNS query in action. Notice the different sections of the output, like the ANSWER SECTION, which contains the IP address, and AUTHORITY SECTION, which lists the authoritative nameservers for the domain.
Try it out:
dig coddykit.comBasic DNS Troubleshooting
If you can't access a website by name but can by IP, it's likely a DNS issue. Here's a quick checklist:
- Check
/etc/resolv.conf: Are thenameserverIPs correct and reachable? - Test with
ping 8.8.8.8: Can you reach an external DNS server by IP? - Use
dig google.com @8.8.8.8: Explicitly query a working DNS server to see if resolution works that way. - Restart network service: Sometimes a network service restart can help apply changes.
DNS Client Configuration
You've learned about the key components of DNS client configuration in Linux.
Which of the following directives are commonly found in /etc/resolv.conf for configuring DNS client behavior?
Recap: DNS in Linux
Great job! You've learned how DNS works in Linux. You can now:
- Identify
/etc/resolv.confas the primary DNS client configuration file. - Understand the role of
nameserver,domain, andsearchdirectives. - Use
hostfor quick DNS lookups. - Use
digfor detailed DNS queries. - Perform basic troubleshooting for name resolution issues.
Mastering these tools is key to managing network services effectively!
Изучай Linux Networking & TCP/IP for Developers с ИИ-репетитором — бесплатно
Пиши и запускай код прямо в браузере, получай мгновенную помощь от ИИ-репетитора 24/7 и продолжи учиться на сайте или в приложении.
- Курсы
- 12
- Уроки
- 48
Часто задаваемые вопросы
Урок «Настройка и разрешение DNS» бесплатный?
Да — полный текст урока «Настройка и разрешение DNS» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Linux Networking & TCP/IP for Developers, подпишись на CoddyKit PRO. Курс Linux Networking & TCP/IP for Developers содержит 4 уроков всего.
Чему я научусь в уроке «Настройка и разрешение DNS»?
Разберитесь, как работает DNS в Linux, настраивайте DNS-клиенты и устраняйте неполадки разрешения имён Ты практикуешь Linux Networking & TCP/IP for Developers с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Linux Networking & TCP/IP for Developers?
Предыдущий опыт не требуется. Linux Networking & TCP/IP for Developers на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.
Сколько времени занимает урок «Настройка и разрешение DNS»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Linux Networking & TCP/IP for Developers?
Да. Каждый урок Linux Networking & TCP/IP for Developers включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Управление сетевыми интерфейсами
- Таблицы маршрутизации и шлюзы
- Настройка и разрешение DNS
- Настройка межсетевого экрана Linux с nftables