这是一款简洁好用的 TCP 端口转发程序。
其官方 rinetd 仓库,其作者官方博客,如下是官方的描述:
A TCP port-forwarding utility that does not require root access.
原作者已经放弃项目,由新维护者进行维护,仓库地址:rinetd
安装
在部分发行版的官方仓库中存在,但是 RHEL 系列的发行版并未存在。这部分发行版需要自行编译安装。
下载源码
git clone https://github.com/boutell/rinetd.git编译
make不出意外的话会见到如下提示:
cc -DLINUX -g   -c -o rinetd.o rinetd.c
rinetd.c:176:6: warning: conflicting types for built-in function ‘log’ [enabled by default]
 void log(int i, int coSe, int result);
      ^
cc -DLINUX -g   -c -o match.o match.c
cc rinetd.o match.o -o rinetd修改 Makefile 中的编译参数
- 将 CFLAGS=-DLINUX -g后添加参数-fno-builtin-log
然后重新编译即可,记得删除已经编译的 rinetd 二进制文件。
make
cc rinetd.o match.o -o rinetd编译后安装即可
make install配置
其程序默认的配置文件为 /etc/rinetd.conf 
配置格式为:源IP 源端口 转发IP 转发端口,配置支持使用 ? 和 * 规则。
小贴士:比如将本机的 80 端口转发至某地址的 51002 端口。
logfile /var/log/rinetd.log
0.0.0.0 80 192.168.99.99 51002脚本
启停脚本可使用如下
#! /bin/sh
### BEGIN INIT INFO
# Provides:          rinetd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/rinetd
CONFFILE=/etc/rinetd.conf
PIDFILE=/var/run/rinetd.pid
NAME=rinetd
DESC="internet redirection server"
test -f $DAEMON || exit 0
test -f $CONFFILE || exit 0
set -e
. /lib/lsb/init-functions
case "$1" in
  start)
    echo -n "Starting $DESC:"
    start-stop-daemon --start --quiet --exec $DAEMON && echo -n " $NAME"
    echo "."
    ;;
  stop)
    echo -n "Stopping $DESC:"
    start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON && echo -n " $NAME"
    echo "."
    ;;
  reload|force-reload)
    echo -n "Reloading configuration of $DESC:"
    start-stop-daemon --stop --quiet --pidfile $PIDFILE --signal 1 --exec $DAEMON && echo -n " $NAME"
    echo "."
    ;;
  restart)
    echo -n "Stopping $DESC:"
    start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON && echo -n " $NAME"
    echo "."
    sleep 1
    echo -n "Starting $DESC:"
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON && echo -n " $NAME"
    echo "."
    ;;
  status)
    status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload}"
    exit 1
    ;;
esac
exit 0其他
配置说明
# this is the configuration file for rinetd, the internet redirection server
#
# you may specify global allow and deny rules here
# only ip addresses are matched, hostnames cannot be specified here
# the wildcards you may use are * and ?
#
# allow 192.168.2.*
# deny 192.168.2.1?
#
# forwarding rules come here
#
# you may specify allow and deny rules after a specific forwarding rule
# to apply to only that forwarding rule
#
# bindadress    bindport  connectaddress  connectport
# logging information
logfile /var/log/rinetd.log
# uncomment the following line if you want web-server style logfile format
# logcommon附录
参考链接
            本文由 柒 创作,采用 知识共享署名4.0
            国际许可协议进行许可。
转载本站文章前请注明出处,文章作者保留所有权限。
最后编辑时间: 2023-08-31  00:05 AM        
 
                    
这个挺好用的哈。请问UDP的用什么转发?