在 Linux 下将 TCP 流量重定向到 UNIX 域套接字 [英] Redirecting TCP-traffic to a UNIX domain socket under Linux
问题描述
假设一个传统的 Linux 应用程序正在侦听 UNIX 域套接字 /tmp/foo
.
Assume a legacy Linux application listening on a UNIX domain socket /tmp/foo
.
除了通过 UNIX 域套接字机制与这个遗留应用程序通信之外,我还希望能够通过端口(比如 1234)上的 TCP 连接连接到它.
In addition to communicating with this legacy application over the UNIX domain socket mechanism I want to be able to connect to it via a TCP-connection on port say 1234.
绑定到 TCP 端口 1234 然后将所有传入连接重定向到 UNIX 域套接字 /tmp/foo
的最简单方法是什么?
What is the easiest way to bind to TCP port 1234 and then redirect all incoming connections to the UNIX domain socket /tmp/foo
?
推荐答案
结果是 socat可用于实现此目的:
Turns out socat can be used to achieve this:
socat TCP-LISTEN:1234,reuseaddr,fork UNIX-CLIENT:/tmp/foo
并增加了一些安全性:
socat TCP-LISTEN:1234,bind=127.0.0.1,reuseaddr,fork,su=nobody,range=127.0.0.0/8 UNIX-CLIENT:/tmp/foo
这些示例已经过测试并按预期工作.
These examples have been tested and work as expected.
这篇关于在 Linux 下将 TCP 流量重定向到 UNIX 域套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!