안녕하세요? 서버 개발을 진행하면서 포트 및 방화벽에 대해서 설정할 일이 많아 정리를 해보았습니다. A. 포트 상태 확인 1. 열려있는 모든 포트 표시 -n: host명으로 표시 안함 2. LISTEN중인 포트 표시 3. 확인하려는 포트번호 상태확인 4. 특정 호스트 포트 상태 확인 4.1 특정 포트 상태 확인 Sample Result) Connection to www.google.com 80 port [tcp/http] succeeded! 4.2 특정 호스트의 포트 범위를 지정하여 열린 포트 확인 Sample Result) Connection to
10.20.30.40 21 port [tcp/ftp] succeeded! B. 포트 열기 ※ 방화벽 설정 정보
확인하기 1. 특정포트 외부에서 접속할 수 있도록 열기 (외부에서 접속할 수 있도록 포트 OPEN) 1.1 TCP PORT일 경우 1.2 UDP PORT일
경우 -I: 새로운 규칙을 추가한다. ※ 내부에서 외부로 나갈 수 있도록 포트 열기 # iptables -I OUTPUT 1 -p tcp --dport 9002 -j ACCEPT 2. 추가한 설정 조회 3. 추가한 설정 삭제 a) 규칙번호로 삭제 b) 추가한 규칙으로 삭제 4. 변경사항 저장 C. 방화벽 활성화&비활성화 1. 켜기 2. 끄기 ------------------------------------------------------------------------------------------ 리눅스서버에서 리모트서버로 포트가 오픈되어 있는지 확인하는 2가지 방법에 대해 알아보겠습니다. 1) nc (넷캣, Netcat) 추천!!! 실습으로 리모트 서버 10.0.0.1, 8883 포트로 확인해보겠습니다. [포트 오픈된 경우] $ nc -vz 10.0.0.1 8883 [결과] Connection to 10.0.0.1 8883 port [tcp/*] succeeded! [포트 미오픈된 경우] (리모트 서버에서 서비스를 하고 있는지 또는 방화벽 설정을 확인하세요) $ nc -vz 10.0.0.1 8884 [결과] connect to 10.0.0.1 port 8884 (tcp) failed: Connection refused 또는 connection to 10.0.0.1 failed: Connection timed out. 실습으로 리모트 서버 10.0.0.1, 8883 포트로 확인해보겠습니다. [포트 오픈된 경우] $ telnet 10.0.0.1 8883 Trying 10.0.0.1... Connected to 127.0.0.1. [포트 미오픈된 경우] (리모트 서버에서 서비스를 하고 있는지 또는 방화벽 설정을 확인하세요) $ telnet 10.0.0.1 8884 Trying 10.0.0.1... telnet: Unable to connect to remote host: Connection refused 끝. nc 명령어 도움말입니다. 참고하세요. usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port] * Port numbers can be individual or ranges: lo-hi [inclusive] Command Summary: -4 Use IPv4 -6 Use IPv6 -b Allow broadcast -C Send CRLF as line-ending -D Enable the debug socket option -d Detach from stdin -F Pass socket fd -h This help text -I length TCP receive buffer length -i interval Delay interval for lines sent, ports scanned -k Keep inbound sockets open for multiple connects -l Listen mode, for inbound connects -M ttl Outgoing TTL / Hop Limit -m minttl Minimum incoming TTL / Hop Limit -N Shutdown the network socket after EOF on stdin -n Suppress name/port resolutions -O length TCP send buffer length -P proxyuser Username for proxy authentication -p port Specify local port for remote connects -q secs quit after EOF on stdin and delay of secs -r Randomize remote ports -S Enable the TCP MD5 signature option -s source Local source address -T keyword TOS value -t Answer TELNET negotiation -U Use UNIX domain socket -u UDP mode -V rtable Specify alternate routing table -v Verbose -W recvlimit Terminate after receiving a number of packets -w timeout Timeout for connects and final net reads -X proto Proxy protocol: "4", "5" (SOCKS) or "connect" -x addr[:port] Specify proxy address and port -Z DCCP mode -z Zero-I/O mode [used for scanning] |