Skip to content

Instantly share code, notes, and snippets.

@sigridjineth
Created December 29, 2023 01:38
Show Gist options
  • Save sigridjineth/783a84c019e042e02e14a555be047c7e to your computer and use it in GitHub Desktop.
Save sigridjineth/783a84c019e042e02e14a555be047c7e to your computer and use it in GitHub Desktop.
resolv.conf

다음과 같은 PDO Exception 에러가 있다고 생각해보자.

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

RDS Host 이름을 찾을 수 없기 때문에 발생하는 문제이다.

가장 쉽게 해결하는 방법은 /etc/hosts에 아이피와 해당 호스트를 직접 입력하면 해결이 되지만, 이거는 특정 도메인을 못 찾는 문제가 아니라 DNS 조회를 못하는 것이다.

우리의 컴퓨터는 다음 방법을 통해 도메인을 조회한다.

  1. 로컬 캐시 조회
  2. /etc/hosts 조회
  3. DNS 조회

우분투에서는 /etc/resolv.conf 파일 안에 정보가 있다.

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN

nameserver 172.31.0.2
search ap-northeast-2.compute.internal

172.31.0.2 가 네임 서버라는 것은 내부 DNS 서버가 존재한다는 뜻이다. 8.8.8.8 을 이용한다는 것은 Google DNS 서버를 upstream으로 이용한다는 것이다. 특히 dnsmasq쿠버네티스에서 내부 DNS 설정을 이용할 경우 유용하다.

내부 DNS 서버의 정상 동작 여부는 다음과 같이 확인해볼 수 있다.

nslookup myrds.abcdefghijkl.ap-northeast-2.rds.amazonaws.com 172.31.0.2

nslookup myrds.abcdefghijkl.ap-northeast-2.rds.amazonaws.com 8.8.8.8

DNS 설정 바꾸기

참고 : resolv.conf - ArchWiki

nameserver 172.31.0.2
search ap-northeast-2.compute.internal

# Google IPv4 nameservers
nameserver 8.8.8.8
nameserver 8.8.4.4

# Google IPv6 nameservers
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

man resolv.conf을 참고하도록 한다.

서버가 재부팅될 때 resolv.conf가 초기화되지 않도록 조치를 취할 수 있다.

  • 다음을 열어본다. /etc/resolvconf/update.d/libc
  • 다음도 열어본다. vi /etc/resolvconf/resolv.conf.d/tail
  • tail 에 아래 내용을 추가한다.
# Google IPv4 nameservers
nameserver 8.8.8.8
nameserver 8.8.4.4

# Google IPv6 nameservers
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

$ sudo service resolvconf restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment