Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

로컬 PC에서 개발 중인 ASP.NET Core 웹 응용 프로그램을 다른 PC에서도 접근하는 방법

다음의 글에 자세한 방법이 소개되어 있습니다.

External Network Access to Kestrel and IIS Express in ASP.NET Core
; https://weblog.west-wind.com/posts/2016/sep/28/external-network-access-to-kestrel-and-iis-express-in-aspnet-core

ACCESSING AN ASP .NET CORE WEB APPLICATION REMOTELY
; https://gigi.nullneuron.net/gigilabs/accessing-an-asp-net-core-web-application-remotely/

정리해 보면 dotnet으로 웹 애플리케이션을 실행하면 다음과 같은 식의 메시지가 출력되는데,

$ dotnet /home/tusr/core3web/Core3Web.dll
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/tusr/core3web

저렇게 "localhost:5000"으로 메시지가 나오면 해당 웹 애플리케이션은 외부에서 접근할 수 없습니다. 이를 해제하기 위해서는 간단하게 다음과 같이 ListenAnyIP 메서드를 호출하면 됩니다.

Endpoint configuration
; https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#endpoint-configuration

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
                webBuilder.ConfigureKestrel(serverOptions =>
                {
                    serverOptions.ListenAnyIP(6000);
                });
            });
}

위와 같이 처리해 주면 이제 메시지가 다음과 같이 변경됩니다.

# dotnet /home/tusr/core3web/Core3Web.dll
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/home/tusr/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://[::]:6000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/tusr/core3web

혹은, netstat로 바인딩이 모든 IP로 된 것을 확인하는 것도 가능합니다.

$ netstat -ano | grep 6000
tcp6       0      0 :::6000                 :::*                    LISTEN      off (0.00/0/0)




이제 방화벽만 없다면 외부 PC에서 해당 포트로 접근하는 것이 가능합니다. 참고로, Centos 7의 경우,

RHEL/CentOS 7 에서 방화벽(firewalld) 설정하기
; https://www.lesstif.com/pages/viewpage.action?pageId=22053128

다음과 같이 활성화된 방화벽 영역을 확인할 수 있고,

# firewall-cmd --get-active-zone
public
  interfaces: eth0

# firewall-cmd --get-default-zone
public

해당 영역에 설정된 제약들을 이렇게 볼 수 있습니다.

# firewall-cmd --info-zone=public
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: ssh dhcpv6-client samba
  ports: 5000/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

보는 바와 같이 현재 "services" 관련해서 "ssh", "dhcpv6-client", "samba"와 연관된 서비스들이 외부로 노출되어 있으며, "ports" 설정을 통해 명시적으로 "5000/tcp"만을 접근이 가능합니다. 따라서, 이 글에서 예제로 들고 있는 6000번 포트의 웹 애플리케이션을 접근하도록 만들고 싶다면 다음과 같이 명령을 내리면 됩니다.

# firewall-cmd --permanent --zone=public --add-port=6000/tcp
# firewall-cmd --reload




아니... 그런데 이게 웬일입니까? 여전히 "http://...:6000"으로는 접근이 안 됩니다. 그렇긴 한데, Chome 웹 브라우저의 메시지에 좀 이상한 면이 있습니다.

Chrome, Edge
Hmmm… can't reach this page
It looks like the webpage at http://test_centos:6000/ might be having issues, or it may have moved permanently to a new web address.
ERR_UNSAFE_PORT

"ERR_UNSAFE_PORT"라고 나오는데, 사실 웹 사이트를 정상(?)적으로 접근을 못했다면 원래는 다음과 같은 식으로 나와야 했습니다.

test_centos took too long to respond
ERR_CONNECTION_TIMED_OUT

검색해 보면 ^^; Chrome은 보안을 위해 기본적으로 막아두는 포트가 있다고 합니다.

Which ports are considered unsafe by Chrome?
; https://superuser.com/questions/188058/which-ports-are-considered-unsafe-by-chrome

1,       // tcpmux
7,       // echo
9,       // discard
11,      // systat
13,      // daytime
15,      // netstat
17,      // qotd
19,      // chargen
20,      // ftp data
21,      // ftp access
22,      // ssh
23,      // telnet
25,      // smtp
37,      // time
42,      // name
43,      // nicname
53,      // domain
77,      // priv-rjs
79,      // finger
87,      // ttylink
95,      // supdup
101,     // hostriame
102,     // iso-tsap
103,     // gppitnp
104,     // acr-nema
109,     // pop2
110,     // pop3
111,     // sunrpc
113,     // auth
115,     // sftp
117,     // uucp-path
119,     // nntp
123,     // NTP
135,     // loc-srv /epmap
139,     // netbios
143,     // imap2
179,     // BGP
389,     // ldap
427,     // SLP (Also used by Apple Filing Protocol)
465,     // smtp+ssl
512,     // print / exec
513,     // login
514,     // shell
515,     // printer
526,     // tempo
530,     // courier
531,     // chat
532,     // netnews
540,     // uucp
548,     // AFP (Apple Filing Protocol)
556,     // remotefs
563,     // nntp+ssl
587,     // stmp?
601,     // ??
636,     // ldap+ssl
993,     // ldap+ssl
995,     // pop3+ssl
2049,    // nfs
3659,    // apple-sasl / PasswordServer
4045,    // lockd
6000,    // X11
6665,    // Alternate IRC [Apple addition]
6666,    // Alternate IRC [Apple addition]
6667,    // Standard IRC [Apple addition]
6668,    // Alternate IRC [Apple addition]
6669,    // Alternate IRC [Apple addition]
6697,    // IRC + TLS

재수(?) 좋게 제가 저 포트 목록에 있는 6000번을 ASP.NET Core 웹 애플리케이션에 사용했던 것입니다. 물론, chrome 브라우저에는 이 설정을 비활성화시키는 옵션이 있습니다.

Fix ERR_UNSAFE_PORT error on Google Chrome on Windows 10
; https://www.thewindowsclub.com/err_unsafe_port-error-on-google-chrome

이를 위해 일단 현재 실행 중인 "chrome.exe"의 전체 경로를 작업 관리자 등을 통해 알아내고,

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

실행 중인 모든 chrome 인스턴스를 종료한 다음 완전히 새롭게 명령행에서 다음과 같은 식으로 실행해 주면 됩니다.

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --explicitly-allowed-ports=6000

해보시면 알겠지만, 이는 매우 번거로운 작업이기 때문에 ^^ 차라리 그냥 포트 번호를 바꾸는 것이 더 속 편할 것입니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 3/9/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 



2020-06-15 04시15분
[감사해서 어쩔 줄 모르는 사람] 6시간 고민했던 해결책이 여기에 있었네요.

많은 도움되었습니다.
[guest]
2020-08-08 05시42분
[와] 몇 일 고민하던게 바로 풀렸네요 최곱니다
[guest]
2021-02-24 02시00분
ㅠㅠ너무 감사합니다.
어제 오늘 방화벽도 내렸다가, 포트포워딩도 했다가 별짓을 다 했는데.. 결국 되는군요. 너무 감사합니다.
용림이
2021-04-16 04시44분
[사용자] 프로젝트 속성-디버그에서 맨 밑에 있는 "앱 URL"에 실제 서버 IP를 적어줘도됩니다. https://localhost:5001;http://localhost:5000 -> https://192.168.0.5:5001;http://192.168.0.5:5000
[guest]
2021-04-16 09시47분
프로젝트 속성의 디버그를 이용한 설정은 비주얼 스튜디오에서 실행하는 경우에 한해 적용됩니다.

그와 같은 설정은 launchSettings.json에 저장되고 비주얼 스튜디오만 그 설정을 이용하므로 해당 응용 프로그램을 직접 실행하거나 다른 머신에 복사해 호스팅하는 경우라면 사용할 수 없는 방법입니다. (사실, 대부분의 경우 다른 PC에서 접근한다는 것은 비주얼 스튜디오로 실행하는 상황은 아닐 것입니다.)
정성태

... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...
NoWriterDateCnt.TitleFile(s)
12124정성태1/23/202010385VS.NET IDE: 140. IDE1006 - Naming rule violation: These words must begin with upper case characters: ...
12123정성태1/23/202011856웹: 39. Google Analytics - gtag 함수를 이용해 페이지 URL 수정 및 별도의 이벤트 생성 방법 [2]
12122정성태1/20/20208853.NET Framework: 879. C/C++의 UNREFERENCED_PARAMETER 매크로를 C#에서 우회하는 방법(IDE0060 - Remove unused parameter '...')파일 다운로드1
12121정성태1/20/20209405VS.NET IDE: 139. Visual Studio - Error List: "Could not find schema information for the ..."파일 다운로드1
12120정성태1/19/202010844.NET Framework: 878. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 네 번째 이야기(IL 코드로 직접 구현)파일 다운로드1
12119정성태1/17/202010888디버깅 기술: 160. Windbg 확장 DLL 만들기 (3) - C#으로 만드는 방법
12118정성태1/17/202011498개발 환경 구성: 466. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 세 번째 이야기 [1]
12117정성태1/15/202010528디버깅 기술: 159. C# - 디버깅 중인 프로세스를 강제로 다른 디버거에서 연결하는 방법파일 다운로드1
12116정성태1/15/202011022디버깅 기술: 158. Visual Studio로 디버깅 시 sos.dll 확장 명령어를 (비롯한 windbg의 다양한 기능을) 수행하는 방법
12115정성태1/14/202010777디버깅 기술: 157. C# - PEB.ProcessHeap을 이용해 디버깅 중인지 확인하는 방법파일 다운로드1
12114정성태1/13/202012630디버깅 기술: 156. C# - PDB 파일로부터 심벌(Symbol) 및 타입(Type) 정보 열거 [1]파일 다운로드3
12113정성태1/12/202013250오류 유형: 590. Visual C++ 빌드 오류 - fatal error LNK1104: cannot open file 'atls.lib' [1]
12112정성태1/12/20209850오류 유형: 589. PowerShell - 원격 Invoke-Command 실행 시 "WinRM cannot complete the operation" 오류 발생
12111정성태1/12/202013082디버깅 기술: 155. C# - KernelMemoryIO 드라이버를 이용해 실행 프로그램을 숨기는 방법(DKOM: Direct Kernel Object Modification) [16]파일 다운로드1
12110정성태1/11/202011661디버깅 기술: 154. Patch Guard로 인해 블루 스크린(BSOD)가 발생하는 사례 [5]파일 다운로드1
12109정성태1/10/20209586오류 유형: 588. Driver 프로젝트 빌드 오류 - Inf2Cat error -2: "Inf2Cat, signability test failed."
12108정성태1/10/20209625오류 유형: 587. Kernel Driver 시작 시 127(The specified procedure could not be found.) 오류 메시지 발생
12107정성태1/10/202010613.NET Framework: 877. C# - 프로세스의 모든 핸들을 열람 - 두 번째 이야기
12106정성태1/8/202011972VC++: 136. C++ - OSR Driver Loader와 같은 Legacy 커널 드라이버 설치 프로그램 제작 [1]
12105정성태1/8/202010641디버깅 기술: 153. C# - PEB를 조작해 로드된 DLL을 숨기는 방법
12104정성태1/7/202011358DDK: 9. 커널 메모리를 읽고 쓰는 NT Legacy driver와 C# 클라이언트 프로그램 [4]
12103정성태1/7/202014048DDK: 8. Visual Studio 2019 + WDK Legacy Driver 제작- Hello World 예제 [1]파일 다운로드2
12102정성태1/6/202011670디버깅 기술: 152. User 권한(Ring 3)의 프로그램에서 _ETHREAD 주소(및 커널 메모리를 읽을 수 있다면 _EPROCESS 주소) 구하는 방법
12101정성태1/5/202011043.NET Framework: 876. C# - PEB(Process Environment Block)를 통해 로드된 모듈 목록 열람
12100정성태1/3/20209092.NET Framework: 875. .NET 3.5 이하에서 IntPtr.Add 사용
12099정성태1/3/202011371디버깅 기술: 151. Windows 10 - Process Explorer로 확인한 Handle 정보를 windbg에서 조회 [1]
... 46  47  48  49  50  51  52  53  54  55  56  57  58  59  [60]  ...