[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

 

 

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
23 [C/C++ 인공지능] Artificial Neural Network C++ Class : 인공신경망 C++ 클래스 file 졸리운_곰 2023.11.25 308
22 [C/C++ 인공지능] Visual Studio 2019에서 LibTorch 사용하기 file 졸리운_곰 2023.11.20 392
21 [C/C++ 인공지능] A Simple and Complete Explanation of Neural Networks : 신경망에 대한 간단하고 완전한 설명 file 졸리운_곰 2023.10.22 279
20 [C/C++ 인공지능] Deep Learning from Scratch in C++: Tensor Programming file 졸리운_곰 2023.09.06 340
19 [C/C++ 인공지능] Getting Started with mlpack 졸리운_곰 2023.01.28 310
18 [C/C++][인공지능] Most Useful C/C++ ML Libraries Every Data Scientist Should Know file 졸리운_곰 2022.10.01 423
17 [인공지능] 추론 기법 file 졸리운_곰 2022.05.05 509
16 [C++ 인공지능] C ++을 이용한 단순 MLP 역 전파 인공 신경망 (단계 별) file 졸리운_곰 2022.04.11 370
15 [C/C++인공지능] An Introduction to Machine Learning Libraries for C++ file 졸리운_곰 2021.12.06 360
14 [C/C++][tensorflow 1.x] windows C lib : [Tensorflow] How to Install Tensorflow for C API file 졸리운_곰 2021.11.19 396
13 [C/C++][tensorflow] tensorflovw 1.x version 텐서플로우 C 예제 file 졸리운_곰 2021.11.19 544
12 [C/C++ 인공지능][linux][cuda] flashlight file 졸리운_곰 2021.11.09 506
11 [C/C++] (고전 기호 처리 인공지능) 전문가 시스템 file 졸리운_곰 2020.06.13 330
10 [유전알고리즘] 자동 그림생성 프로그램 - Evolving Image file 졸리운_곰 2018.03.04 910
9 대화 프로그램 - ELIZA 졸리운_곰 2018.03.04 359
8 Caffe 설치하기 ๑•‿•๑ (2) file 졸리운_곰 2018.02.21 337
7 Caffe 설치하기 ๑•‿•๑ (1) file 졸리운_곰 2018.02.21 427
6 Windows 에 Caffe 설치하기 (๑•‿•๑) 졸리운_곰 2018.02.21 306
5 Windows에서 Caffe 예제 돌리기 : MNIST(1) (๑•‿•๑) file 졸리운_곰 2018.02.21 356
4 Caffe 구성 요소들 알아보기: blobs, nets, layer, solver, prototxt ๑•‿•๑ file 졸리운_곰 2018.02.21 569
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED