bigg01/tcpproxy
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
A simple TCP proxy service. It listens on an address (host and port combination)
and forwards all TCP traffic to a remote address.
Installation:
```bash
$ GO111MODULE=on go mod tidy && CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -o tcpproxy .
```
Usage:
```bash
$ tcpproxy -l 0.0.0.0:29418 -r origin.server:29418
$ docker build -t tcpproxy:latest .
# image is arround 4MB :-)
$ docker images |grep -i tcpproxy
tcpproxy latest 50938d4749ec About a minute ago 3.48MB
$ docker run -it tcpproxy:latest
flag needs an argument: -l
Usage of ./tcpproxy:
-l string
local address to listen on
-logconn
log connections
-r string
remote address to dial
$ docker run --rm -it -p 8023:8023 -p 8080:8080 tcpproxy:latest tcpproxy -l 0.0.0.0:8023 -r 10.0.0.208:3000 -logconn true
INFO[0003] connected: 172.17.0.1:57728
$ curl -v telnet://127.0.0.1:8023
* Rebuilt URL to: telnet://127.0.0.1:8023/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8023 (#0)
# Prom
$ curl http://localhost:8080/metrics |grep -i proxy_tcp_connection
# HELP proxy_tcp_connection Current number of established Connection
# TYPE proxy_tcp_connection gauge
proxy_tcp_connection 1
$ docker pull quay.io/bigg01/tcpproxy
### Run TCP Server
$
$ oc run -it gotest1 --rm=true --restart='Never' --image=rhel7/rhel-tools:latest -- /bin/sh
If you don't see a command prompt, try pressing enter.
sh-4.2$ curl -v telnet://tcpproxy.tcpproxy.svc:8023
* About to connect() to tcpproxy.tcpproxy.svc port 8023 (#0)
* Trying 172.30.214.132...
* Connected to tcpproxy.tcpproxy.svc (172.30.214.132) port 8023 (#0)
* Closing connection 0
Message received.sh-4.2$
$ echo -n "test out the server" | nc tcpproxy.tcpproxy.svc 8023
Message received.sh-4.2$
$ go run tcpserver.go
Listening on 0.0.0.0:3333