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

Linux - 외부에서의 접속을 허용하기 위한 TCP 포트 여는 방법

예전에 Centos 7 환경에서 firewall-cmd 명령어를 이용해 방화벽 제어를 했었는데요, 그런데 방화벽 설정이 없는데도,

$ sudo firewall-cmd --permanent --zone=public --add-port=10240/tcp
FirewallD is not running

외부에서 "telnet ...ip... 10240"으로 접속 테스트가 안 됩니다. 음... 뭔가 또 다른 방화벽 시스템이 있는 듯한데요, 한참을 헤맨 끝에 iptables라는 것이 그 역할을 한다는 것을 알게 되었습니다. ^^;

How To List and Delete Iptables Firewall Rules
; https://www.digitalocean.com/community/tutorials/how-to-list-and-delete-iptables-firewall-rules

예를 들어, 아래와 같이 명령을 수행해 얻은 출력을 보면,

$ sudo iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
           tcp  --  anywhere             anywhere            
neutron-openvswi-INPUT  all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             multiport dports fs-agent /* 001 aodh-api incoming aodh_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 8777 /* 001 ceilometer-api incoming ceilometer_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 8776 /* 001 cinder-api incoming cinder_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports armtechdaemon /* 001 glance incoming glance_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 8041 /* 001 gnocchi-api incoming gnocchi_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports http /* 001 horizon 80 incoming */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports commplex-main /* 001 keystone incoming keystone */
ACCEPT     udp  --  anywhere             anywhere             multiport dports bootps /* 001 neutron dhcp in incoming neutron_dhcp_in_192.168.0.9 */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 9696 /* 001 neutron server incoming neutron_server_192.168.0.9 */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 8773,8774,8775,8778 /* 001 nova api incoming nova_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 6080 /* 001 novncproxy incoming */
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

"multiport dports 8777"라는 것에서 8777 포트에 대해 "telnet ...[ip]... 8777"로 연결하면 외부에서 접속이 됩니다. 그러니까, 위의 테이블에 포트를 등록하면 되는 것 같습니다. 이를 위해,

How to Open Ports in iptables
; https://www.ipserverone.info/knowledge-base/how-to-open-ports-in-iptables/

예를 들어 10240번 포트를 허용하고 싶다면 이렇게 명령어를 내릴 수 있습니다.

// 10240 포트로 들어오는 접속 허용
$ iptables -I INPUT -p tcp --dport 10240 -j ACCEPT

다시 iptables를 확인하면 해당 포트가 추가돼 있고,

$ sudo iptables -L INPUT
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:10240
           tcp  --  anywhere             anywhere            
neutron-openvswi-INPUT  all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             multiport dports fs-agent /* 001 aodh-api incoming aodh_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 8777 /* 001 ceilometer-api incoming ceilometer_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 8776 /* 001 cinder-api incoming cinder_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports armtechdaemon /* 001 glance incoming glance_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 8041 /* 001 gnocchi-api incoming gnocchi_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports http /* 001 horizon 80 incoming */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports commplex-main /* 001 keystone incoming keystone */
ACCEPT     udp  --  anywhere             anywhere             multiport dports bootps /* 001 neutron dhcp in incoming neutron_dhcp_in_192.168.0.9 */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 9696 /* 001 neutron server incoming neutron_server_192.168.0.9 */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 8773,8774,8775,8778 /* 001 nova api incoming nova_api */
ACCEPT     tcp  --  anywhere             anywhere             multiport dports 6080 /* 001 novncproxy incoming */
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

실제로 외부에서 10240 포트로의 접속이 가능해집니다.




참고로, 삭제는 위의 추가 명령어에서 옵션만 "I"가 아닌 "D"로 바꾸면 됩니다.

$ sudo iptables -D INPUT -p tcp --dport 10240 -j ACCEPT




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

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/27/2023]

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

비밀번호

댓글 작성자
 




... 16  17  [18]  19  20  21  22  23  24  25  26  27  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13182정성태12/4/20225395Windows: 217. Windows 환경에서의 Hello World x64 어셈블리 예제 (MASM 버전)
13181정성태12/3/20224792Linux: 54. 리눅스/WSL - hello world 어셈블리 코드 x86/x64 (nasm)
13180정성태12/2/20224992.NET Framework: 2074. C# - 스택 메모리에 대한 여유 공간 확인하는 방법파일 다운로드1
13179정성태12/2/20224414Windows: 216. Windows 11 - 22H2 업데이트 이후 Terminal 대신 cmd 창이 뜨는 경우
13178정성태12/1/20224894Windows: 215. Win32 API 금지된 함수 - IsBadXxxPtr 유의 함수들이 안전하지 않은 이유파일 다운로드1
13177정성태11/30/20225613오류 유형: 829. uwsgi 설치 시 fatal error: Python.h: No such file or directory
13176정성태11/29/20224534오류 유형: 828. gunicorn - ModuleNotFoundError: No module named 'flask'
13175정성태11/29/20226168오류 유형: 827. Python - ImportError: cannot import name 'html5lib' from 'pip._vendor'
13174정성태11/28/20224735.NET Framework: 2073. C# - VMMap처럼 스택 메모리의 reserve/guard/commit 상태 출력파일 다운로드1
13173정성태11/27/20225451.NET Framework: 2072. 닷넷 응용 프로그램의 스레드 스택 크기 변경
13172정성태11/25/20225244.NET Framework: 2071. 닷넷에서 ESP/RSP 레지스터 값을 구하는 방법파일 다운로드1
13171정성태11/25/20224845Windows: 214. 윈도우 - 스레드 스택의 "red zone"
13170정성태11/24/20225160Windows: 213. 윈도우 - 싱글 스레드는 컨텍스트 스위칭이 없을까요?
13169정성태11/23/20225726Windows: 212. 윈도우의 Protected Process (Light) 보안 [1]파일 다운로드2
13168정성태11/22/20225021제니퍼 .NET: 31. 제니퍼 닷넷 적용 사례 (9) - DB 서비스에 부하가 걸렸다?!
13167정성태11/21/20225063.NET Framework: 2070. .NET 7 - Console.ReadKey와 리눅스의 터미널 타입
13166정성태11/20/20224794개발 환경 구성: 651. Windows 사용자 경험으로 WSL 환경에 dotnet 런타임/SDK 설치 방법
13165정성태11/18/20224716개발 환경 구성: 650. Azure - "scm" 프로세스와 엮인 서비스 모음
13164정성태11/18/20225620개발 환경 구성: 649. Azure - 비주얼 스튜디오를 이용한 AppService 원격 디버그 방법
13163정성태11/17/20225537개발 환경 구성: 648. 비주얼 스튜디오에서 안드로이드 기기 인식하는 방법
13162정성태11/15/20226613.NET Framework: 2069. .NET 7 - AOT(ahead-of-time) 컴파일
13161정성태11/14/20225830.NET Framework: 2068. C# - PublishSingleFile로 배포한 이미지의 역어셈블 가능 여부 (난독화 필요성) [4]
13160정성태11/11/20225785.NET Framework: 2067. C# - PublishSingleFile 적용 시 native/managed 모듈 통합 옵션
13159정성태11/10/20229011.NET Framework: 2066. C# - PublishSingleFile과 관련된 옵션 [3]
13158정성태11/9/20225255오류 유형: 826. Workload definition 'wasm-tools' in manifest 'microsoft.net.workload.mono.toolchain' [...] conflicts with manifest 'microsoft.net.workload.mono.toolchain.net7'
13157정성태11/8/20225910.NET Framework: 2065. C# - Mutex의 비동기 버전파일 다운로드1
... 16  17  [18]  19  20  21  22  23  24  25  26  27  28  29  30  ...