[linux master][리눅스 마스터][국가기술자격] [리눅스] socat 명령어(proxy)

socat 명령어(proxy)

socat 명령어

  • 양방향 데이터 전송을 위한 다목적 릴레이

socat 패키지 설치

  • CentOS
sudo yum install -y socat
  • Ubuntu
sudo apt-get update
sudo apt-get install -y socat

socat version 정보

socat -V | grep "socat version"
$ socat -V | grep "socat version"
socat version 1.7.4.1 on Mar 25 2022 09:51:32

socat 명령어의 기본 구문

  • <address>는 소스와 대상 각각에 해당하는 주소 및 포트
socat [options] <address> <address>

TCP 서버에서 들어오는 연결을 다른 TCP 서버로 전달하는 경우

socat TCP-LISTEN:<source-port>,reuseaddr,fork TCP:<destination-host>:<destination-port>
  • TCP-LISTEN:<source-port>:<source-port> 포트에서 들어오는 TCP 연결을 수신합니다.
  • reuseaddr: 포트 재사용을 허용합니다.
  • fork: 각 연결을 새로운 프로세스로 분기하여 병렬 처리를 지원합니다.
  • TCP:<destination-host>:<destination-port>: <destination-host>:<destination-port>로 데이터를 전달합니다.

socat의 주요 옵션은 다음과 같습니다.

 

  • -h, --help: 도움말 표시
  • -V, --version: 버전 정보 표시
  • -d, --debug: 디버그 모드 활성화
  • -t, --timeout: 타임아웃 설정
  • -T, --time: 각 연결의 지속 시간 제한 설정
  • -b, --backlog: 대기열 크기 설정
  • -x, --hexdump: 16진수 형식으로 데이터 출력
  • -v, --verbose: 상세한 출력 모드 활성화
  • -q, --quiet: 출력을 최소화
  • -t, --tcp: TCP를 사용하여 데이터 전송
  • -u, --udp: UDP를 사용하여 데이터 전송
  • -s, --syslog: syslog를 통해 메시지 출력
  • -n, --nodelete: 중간 소켓 삭제 비활성화

사용 예시

TCP 서버에서 들어오는 연결을 로그 파일에 기록하는 방법

socat TCP-LISTEN:8080,reuseaddr,fork OPEN:/var/log/tcp.log,creat,append

로컬 포트에서 들어오는 TCP 연결을 원격 서버로 포워딩하는 방법

socat TCP-LISTEN:8080,fork TCP:remotehost:80

로컬 포트에서 들어오는 연결을 다른 포트로 리다이렉트하는 방법

socat TCP-LISTEN:8080,fork TCP:localhost:8888

 

socat을 이용한 릴레이

구성 : (gateway -----------> relay -----------> db)

 

socat_proxy

 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

  • relay(socat)
socat tcp-listen:3306,reuseaddr,fork tcp:10.10.20.76:3306 &
root@relay:~$ socat tcp-listen:3306,reuseaddr,fork tcp:10.10.20.76:3306 &
[1] 2881
netstat -tnlp | grep socat
root@relay:~$ netstat -tnlp | grep socat
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      2881/socat
  • geteway(client)
telnet xxx.xxx.xxx.180 3306
root@gateway:~$ telnet xxx.xxx.xxx.180 3306
Trying xxx.xxx.xxx.180...
Connected to ec2-xxx-xxx-xxx-180.ap-northeast-1.compute.amazonaws.com.
Escape character is '^]'.
N
5.7.23-log'
S%%q{71 !]z]Rte\@mysql_native_password^]
telnet> quit
Connection closed.

 

socat의 기능은 다양하며 여러 가지 용도로 사용될 수 있습니다.

 

 

[출처] https://scbyun.com/entry/linux-socat-%EB%AA%85%EB%A0%B9%EC%96%B4proxy

 

 

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
28 [Linux programming][turbo c] The libXbgi Library file 졸리운_곰 2023.02.05 248
27 [unix][linux][compiler] Yacc와 Lex 시작하기 file 졸리운_곰 2021.09.08 261
26 [Visual Studio 2019] Visual Studio로 Linux 원격 개발하기(Ubuntu 설치부터 SSH 서버접속까지) file 졸리운_곰 2021.08.29 235
25 [unix][emacs] 이맥스와 함께하는 개발환경 . emacs 튜토리얼 file 졸리운_곰 2021.08.18 319
24 [Linux][C/C++] cmake 사용법과 활용 file 졸리운_곰 2020.11.08 552
23 [CMake] Linux C/C++ cmake 시작하기 졸리운_곰 2020.11.08 398
22 [C++] CMake Build System file 졸리운_곰 2020.11.08 328
21 Windows 10에 한국어 입출력이 가능한 리눅스 데스크톱 설치하기 file 졸리운_곰 2020.06.29 289
20 wxwidgets 과 codeblock 설치(리눅스) 졸리운_곰 2019.12.25 228
19 ubuntu 18.04.2 LTS 개발환경 세팅 졸리운_곰 2019.12.25 223
18 Ubuntu 16.04 개발환경 세팅하기! 졸리운_곰 2017.03.21 356
17 tcl/tk 자료 secret 졸리운_곰 2017.02.23 0
16 CentOS xrdp 설정 (원격데스크탑) 졸리운_곰 2017.02.01 453
15 Five lightweight Linux desktop worlds for extreme open-sourcers file 졸리운_곰 2016.05.12 1022
14 Logging every shell command 졸리운_곰 2016.05.11 581
13 How to keep a detailed audit trail of what’s being done on your Linux systems file 졸리운_곰 2016.05.11 467
12 Docker의 소개와 간단한 사용법 file 졸리운_곰 2015.11.24 804
11 Make Self-Extracting Archives with makeself.sh 졸리운_곰 2015.11.07 363
10 리눅스 간단 배포 Linux simple deploy 제작 : make self file 졸리운_곰 2015.11.07 352
9 Joinc: Linux 커널에서의 디바이스 드라이버 작성 졸리운_곰 2015.06.16 833
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED