본문 바로가기

리눅스

우분투에서 systemd-resolved 서비스를 비활성화하는 방법

728x90

우분투에서 systemd-resolved 서비스를 비활성화하는 방법

테스트 환경

  • 운영체제 버전 정보
$ lsb_release -d
Description:    Ubuntu 22.04.2 LTS
  • systemd-resolved 서비스 상태 확인
systemctl status systemd-resolved
$ systemctl status systemd-resolved
● systemd-resolved.service - Network Name Resolution
     Loaded: loaded (/lib/systemd/system/systemd-resolved.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-05-19 16:52:02 KST; 15h ago
       Docs: man:systemd-resolved.service(8)
             man:org.freedesktop.resolve1(5)
             https://www.freedesktop.org/wiki/Software/systemd/writing-network-configuration-managers
             https://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients
   Main PID: 840 (systemd-resolve)
     Status: "Processing requests..."
      Tasks: 1 (limit: 4578)
     Memory: 8.6M
        CPU: 579ms
     CGroup: /system.slice/systemd-resolved.service
             └─840 /lib/systemd/systemd-resolved

May 19 16:52:01 uk-221 systemd[1]: Starting Network Name Resolution...
May 19 16:52:02 uk-221 systemd-resolved[840]: Positive Trust Anchors:
May 19 16:52:02 uk-221 systemd-resolved[840]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
May 19 16:52:02 uk-221 systemd-resolved[840]: Negative trust anchors: home.arpa 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa>
May 19 16:52:02 uk-221 systemd-resolved[840]: Using system hostname 'uk-221'.
May 19 16:52:02 uk-221 systemd[1]: Started Network Name Resolution.
  • systemd-resolved 서비스 LISTEN 포트 확인
netstat -nlp | grep systemd-resolve
$ netstat -nlp | grep systemd-resolve
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      866/systemd-resolve
udp        0      0 127.0.0.53:53           0.0.0.0:*                           866/systemd-resolve
unix  2      [ ACC ]     STREAM     LISTENING     29752    866/systemd-resolve  /run/systemd/resolve/io.systemd.Resolve
  • resolv.conf 심볼릭 링크 확인
$ ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Apr 21 10:00 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
  • resolv.conf 설정 파일 확인
$ cat /etc/resolv.conf
# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
options edns0 trust-ad
search .
728x90

systemd-resolved 서비스 비활성화 및 /etc/resolv.conf 파일 생성

1. systemd-resolved 서비스 비활성화

systemd-resolved 서비스를 시작 시에 자동으로 실행되지 않도록 비활성화합니다.

sudo systemctl disable systemd-resolved
$ sudo systemctl disable systemd-resolved
Removed /etc/systemd/system/dbus-org.freedesktop.resolve1.service.
Removed /etc/systemd/system/multi-user.target.wants/systemd-resolved.service.

2. systemd-resolved 서비스 중지

systemd-resolved 서비스를 중지합니다.

sudo systemctl stop systemd-resolved

3. 심볼릭 링크 삭제

rm /etc/resolv.conf

4. DNS 설정 변경

이제 DNS 설정을 변경하여 systemd-resolved 대신 원하는 DNS 서버를 사용하도록 구성해야 합니다. /etc/resolv.conf 파일을 편집하거나 Netplan을 사용하여 DNS 설정을 관리할 수 있습니다.

  • /etc/resolv.conf 파일 편집
    • /etc/resolv.conf 파일을 열고 원하는 DNS 서버 주소를 추가하거나 편집합니다.

예를 들어, Google Public DNS 서버(8.8.8.8)를 사용하려면 다음과 같이 편집합니다.

sudo vim /etc/resolv.conf

파일을 열고 다음과 같이 설정합니다.

nameserver 8.8.8.8

(또는) cat 명령어를 사용하여 resolv.conf 파일를 생성합니다.

cat <<EOF > /etc/resolv.conf
nameserver 168.126.63.1
nameserver 8.8.8.8
nameserver 1.1.1.1
EOF
  • Netplan 설정 변경
    • Netplan을 사용하여 네트워크 설정을 관리하는 경우, /etc/netplan/ 디렉토리에 있는 네트워크 구성 파일을 수정하여 원하는 DNS 서버를 지정합니다.

예를 들어, 다음과 같이 수정할 수 있습니다.

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      nameservers:
        addresses: [8.8.8.8]

5. systemd-resolved 서비스 마스크 및 스탑

systemd-resolved 서비스를 완전히 비활성화하기 위해 systemd에서 해당 서비스를 마스크하고 중지해야 합니다.

sudo systemctl mask systemd-resolved
sudo systemctl stop systemd-resolved

6. 시스템 다시 부팅

systemd-resolved 서비스를 비활성화하고 DNS 설정을 변경한 후에는 시스템을 재부팅합니다.

sudo reboot

 

systemd-resolved 서비스가 이제 비활성화되었으며 시스템 부팅 시 자동으로 시작되지 않습니다. 또한, 변경된 DNS 설정이 적용됩니다.

 

728x90