在Linux下将TCP流量重定向到UNIX域套接字 [英] Redirecting TCP-traffic to a UNIX domain socket under Linux
本文介绍了在Linux下将TCP流量重定向到UNIX域套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假定一个旧版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屋!
查看全文