WSL 사용시 네트워크 관련 팁 - 3

알림
|
X

페이지 정보

작성자 no_profile platypus 202.♡.70.165
작성일 2024.08.23 19:15
분류 컴퓨터
1,074 조회
1 댓글
9 추천
글쓰기

본문

지난 번 글들의 링크입니다.


지난 번에 DNS설정 관련 내용을 빠뜨렸다는 걸 댓글 보고 알았습니다.


WSL2를 설치하면 기본적으로 WSL최초 실행시 자동으로 DNS서버를 다음과 유사하게 설정합니다.

  • /etc/resolv.conf 파일을 /mnt/wsl/resolv.conf 를 가리키는 symbolic link로 만듦.
  • 해당 파일은 nameserver 10.255.255.254와 같이 설정되어 있음.

그런데, WSL용 Virtual Switch Type을 바꿔주면 해당 설정으로 동작하지 않나 봅니다.


따라서, 원래 Ubuntu의 systemd-resolved를 사용하게 바꿔봅시다.

일단 WSL내의 Ubuntu에서 sudo 권한으로 작업합니다.


먼저 위의 symlink 만드는 것을 disable합니다. 현재의 /etc/resolve.conf 내용을 보면 아래와 같이 /etc/wsl.conf 파일에 generateResolvConf = false라고 설정하라고 나옵니다.

(이 내용은 [이 링크]에서 자세한 내용을 확인할 수 있습니다.)

$ ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 20 Aug 23 17:21 /etc/resolv.conf -> /mnt/wsl/resolv.conf
$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 10.255.255.254
$


vi 에디터 등으로 해당 내용을 바꿔줍니다. 아래는 바꾼 후의 예입니다.

$ cat /etc/wsl.conf
[boot]
systemd=true
[network]
generateResolvConf = false
$


그리고, systemd-resolved 설정을 바꿔줍니다. 설정 파일은 /etc/systemd/resolved.conf 입니다.

[Resolve] 섹션에 있는 DNS= 에 공유기 IP나 원하는 DNS서버 IP를 입력해 줍니다.

아래는 바꾼 후의 예입니다.

$ cat /etc/systemd/resolved.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file (or a copy of it placed in
# /etc/ if the original file is shipped in /usr/), or by creating "drop-ins" in
# the /etc/systemd/resolved.conf.d/ directory. The latter is generally
# recommended. Defaults can be restored by simply deleting the main
# configuration file and all drop-ins located in /etc/.
#
# Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config.
#
# See resolved.conf(5) for details.

[Resolve]
# Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
# Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
# Google: 8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
# Quad9: 9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
DNS=192.168.1.1
FallbackDNS=8.8.8.8
#Domains=
#DNSSEC=no
#DNSOverTLS=no
#MulticastDNS=no
#LLMNR=no
#Cache=no-negative
#CacheFromLocalhost=no
#DNSStubListener=yes
#DNSStubListenerExtra=
#ReadEtcHosts=yes
#ResolveUnicastSingleLabel=no
#StaleRetentionSec=0
$


위의 설정은 WSL을 완전히 종료 후 다시 시작해야 적용됩니다. (해당 창을 닫거나 exit로 나와도 WSL은 백그라운드에서 돌아갑니다.)

따라서 Windows Command Prompt나 PowerShell 창에서 아래의 예와 같이 WSL을 다시 시작합니다.

C:\>wsl --shutdown

C:\>wsl -l -v
NAME STATE VERSION
* Ubuntu-24.04 Stopped 2

C:\>

이제 WSL을 다시 실행하면 DNS 설정이 바뀐것을 확인할 수 있습니다.



여기까지가 지난 번 빠뜨렸던 DNS 설정 관련 내용입니다.

  • 게시물이 없습니다.
댓글 1 / 1 페이지

pinn님의 댓글

작성자 pinn (124.♡.157.15)
작성일 08.24 14:33
WSL
글쓰기
전체 검색