• Stars
    star
    349
  • Rank 121,528 (Top 3 %)
  • Language
    C
  • License
    GNU General Publi...
  • Created over 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A TCP port redirector for UNIX

A TCP port redirector for UNIX

GitHub Status Coverity Status

This is a TCP port redirector for UNIX. It can be run under inetd or as a standalone daemon (in which case it handles multiple connections). It is 8-bit clean, not limited to line mode, yet small and lightweight. If you want access control, run it under xinetd or inetd with TCP wrappers.

redir listens for TCP connections on a given SRC:PORT. When clients connect to redir it initiates a connection to the server on DST:PORT to pass data between them. The SRC and DST are from the perspective of redir.

                      -------> SRC:PORT -----> DST:PORT

Request:       CLIENT -------> redir --------> SERVER


Response:      CLIENT <------- redir <-------- SERVER
                                     --bind=addr

Note: the --bind=ADDR argument is to limit redir on the server side reply, in case the box redir runs on have multiple addresses or interfaces on the server side.

redir finds most of its applications in traversing firewalls, but, of course, there are other use-cases. For a UDP port redirector, see uredir

Usage

Consult the man page for details.

Usage: redir [-hinspv] [-b IP]  [-f TYPE] [-I NAME] [-l LEVEL] [-t SEC]
                       [-x STR] [-m BPS] [-o FLAG] [-w MSEC] [-z BYTES]
                       [SRC]:PORT [DST]:PORT
Options:
  -b, --bind=IP            Listen only to IP on the server-side connection,
                           how DST connects to redir. Not applicable with -p
  -f, --ftp=TYPE           Redirect FTP connections.  Where type is
                           one of: 'port', 'pasv', or 'both'
  -h, --help               Show this help text
  -i, --inetd              Run from inetd, SRC:PORT comes from stdin
                           Usage: redir [OPTIONS] [DST]:PORT
  -I, --ident=NAME         Identity, tag syslog messages with NAME
                           Also used as service name for TCP wrappers
  -l, --loglevel=LEVEL     Set log level: none, err, notice*, info, debug
  -n, --foreground         Run in foreground, do not detach from terminal
  -p, --transproxy         Run in Linux's transparent proxy mode
  -s, --syslog             Log messages to syslog
  -t, --timeout=SEC        Set timeout to SEC seconds, default off (0)
  -v, --version            Show program version
  -x, --connect=STR        CONNECT string passed to proxy server

Traffic Shaping:
  -m, --max-bandwidth=BPS  Limit the bandwidth to BPS bits/second
  -o, --wait-in-out=FLAG   Wait for in(1), out(2), or in&out(3)
  -w, --random-wait=MSEC   Wait MSEC milliseconds before each packet
  -z, --bufsize=BYTES      Size of the traffic shaping buffer

SRC and DST are optional, redir will revert to use 0.0.0.0 (ANY)

Old Syntax

Command line options changed in v3.0. A limited subset of the old syntax is available with the --enable-compat configure option. This implicitly also enables -n by default.

The following subset of the old syntax are available:

  --lport=PORT             Local port (when not running from inetd)
  --laddr=ADDRESS          Local address (when not running from inetd)
  --cport=PORT             Remote port to redirect traffic to
  --caddr=ADDRESS          Remote address to redirect traffic to

Examples

To redirect port 80 to a webserver listening on loopback port 8080, remember to use sudo when using priviliged ports:

sudo redir :80 127.0.0.1:8080

This starts redir as a standard UNIX daemon in the background, with all log messages sent to the syslog. Use -n to foreground and see log messages on stderr.

To run redir from a process monitor like Finit or systemd, tell it to not background itself and to only use the syslog for log messages:

redir -n -s :80 127.0.0.1:8080

An /etc/inetd.conf line of the same looks very similar:

http  stream  tcp  nowait  root  /usr/sbin/tcpd /usr/bin/redir -n -s -i 127.0.0.1:8080

When running multiple redir instances it can be useful to change how they identify themselves:

redir -I nntp www:119 netgate:119
redir -I pop3 ftp:110 netgate:110

This starts an NNTP and a POP3 port redirector, named accordingly. Previously therere was a redir-wrapper script included in the distribution, but that is no longer maintained.

Building

Redir comes with a GNU configure script which you can use to adapt the build to your needs. If you would like to remove support for some extended options (for the sake of speed, code size, whatever), try the following options to configure:

--enable-compat    Enable limited v2.x command line syntax
--disable-shaper   Disable traffic shaping code
--disable-ftp      Disable FTP redirection support

The GNU Configure & Build system use /usr/local as the default install prefix. For most use-cases this is fine, but if you want to change this to /usr use the --prefix=/usr configure option:

./configure --prefix=/usr
make -j5
sudo make install-strip

Building from GIT sources require you have automake and autoconf installed. Use ./autogen.sh to create the configure script.

Origin & References

Redir was originally created by Nigel Metheringham and Sam Creasey. It is now maintained at GitHub by Joachim Wiberg. Use GitHub to file bug reports, clone, or send pull requests for bug fixes and extensions.

Redir is distributed under the terms of the GNU Public Licence, version 2 or later, distributed with this source archive in the file COPYING.

More Repositories

1

inadyn

In-a-Dyn is a dynamic DNS client with multiple SSL/TLS library support
C
782
star
2

finit

Fast init for Linux. Cookies included
C
576
star
3

mg

Micro (GNU) Emacs-like text editor ❤️ public-domain
C
293
star
4

editline

A small replacement for GNU readline() for UNIX
C
254
star
5

libuev

Lightweight event loop library for Linux epoll() family APIs
C
218
star
6

smcroute

Static multicast routing for UNIX
C
216
star
7

pimd

PIM-SM/SSM multicast routing for UNIX and Linux
C
194
star
8

watchdogd

Advanced system monitor & process supervisor for Linux
C
193
star
9

uftpd

FTP/TFTP server for Linux that just works™
C
162
star
10

mcjoin

Simple multicast testing application
C
130
star
11

merecat

Small and made-easy HTTP/HTTPS server based on Jef Poskanzer's thttpd
C
129
star
12

tetris

Micro Tetris™, based on the 1989 IOCCC Obfuscated Tetris by John Tromp
C
107
star
13

uredir

A UDP port redirector for UNIX
C
87
star
14

myLinux

myLinux is an embedded operating system based on Buildroot and Finit
Shell
73
star
15

sysklogd

BSD syslog daemon with syslog()/syslogp() API replacement for Linux, RFC3164 + RFC5424
C
71
star
16

mtools

Tools for multicast testing (msend and mreceive). I do however recommend you try out mcjoin(!) or mping instead.
C
69
star
17

mrouted

The original DVMRP (dynamic multicast routing) implementation for UNIX
C
65
star
18

mini-snmpd

A minimal SNMP agent implementation
C
63
star
19

netcalc

Simplified clone of sipcalc with ipcalc looks
C
60
star
20

xplugd

Monitor, keyboard, and mouse plug/unplug helper for X
C
59
star
21

libite

That missing frog DNA you've been looking for
C
58
star
22

ssdp-responder

SSDP responder for UNIX systems that gives you an InternetGatewayDevice icon in Windows :)
C
53
star
23

mdnsd

Jeremie Miller's original mdnsd
C
49
star
24

sntpd

sntpd is a fork of Larry Doolittle's ntpclient with added daemon, syslog, and IPv6 support
C
42
star
25

adventure

Classic Colossal Cave Adventure
C
42
star
26

omping

Open Multicast Ping (omping) is a tool for testing IPv4/IPv6 multicast connectivity on a LAN.
C
33
star
27

snake

Micro Snake, based on Simon Huggins snake game.
C
30
star
28

pok3r-layouts

Vortex POK3R keyboard layouts for Linux, Windows and OS X/macOS. Based on:
28
star
29

rfctl

Linux driver and control tool for 433 MHz communication on Raspberry Pi
C
25
star
30

sun

Simple library and application that shows sunset and sunrise based on your latitude,longitude
C
23
star
31

jush

just give me a unix shell
C
22
star
32

lipify

C API for http://ipify.org
C
19
star
33

pim6sd

PIM for IPv6 sparse mode daemon
C
19
star
34

tinyroot

Small busybox based embedded Linux root file system
Makefile
17
star
35

mping

A simple multicast ping program
C
17
star
36

pimd-dense

Continuation of the original pimd-dense from 1998-1999, gaps filled with frog DNA from pimd
C
14
star
37

pev

Portable Event Library
C
14
star
38

libicmp

Very simple library for sending and receiving ICMP datagrams.
C
13
star
39

backlight

Very simple program to control the backlight brightness of a laptop
C
13
star
40

getty

Minix getty
C
10
star
41

pacman

UNIX pacman game by Dave Nixon, AGS Computers Inc. (1981) with curses support by Mark Horton (1982)
C
10
star
42

uget

Really stupid get-file-over-http program/function
Shell
10
star
43

toolbox

Misc. home brewed code, free to use under GPL/MIT/ISC, see each snippet for license.
C
9
star
44

mrdisc

Stand alone UNIX implementation of RFC4286 Multicast Router Discovery Protocol
C
9
star
45

uemacs

MicroEMACS by Dave Conroy
C
8
star
46

aliens

UNIX aliens game by Jude Miller, Cambridge (1979) with curses support by Mark Horton (1981)
C
7
star
47

nlmon

Simple example of how to use libnl and libev to monitor kernel netlink events
C
7
star
48

quagga

Westermo Quagga. See security/0.99.17 branch for ported CVE fixes and westermo/0.99.17 for patches on top of that. For more information, see the Wiki.
C
7
star
49

keepalived

Health-checking for LVS and high availability
C
6
star
50

ttinfo

Display information about a process, group or tty
C
6
star
51

awesome-config

My awesome window manager configuration
Lua
5
star
52

finit-plugins

Plugin Repository for Finit
C
5
star
53

zoo

public domain zoo archive tool
C
5
star
54

logit

tiny log helper
C
5
star
55

MicroEMACS

MicroEMACS v3.6 by Dave Conroy and Daniel Lawrence from 1986. Free in the public domain.
C
5
star
56

cx

Small wrapper for basic lxc tasks
Shell
5
star
57

awesome-redshift

Ryan Young's small, simple lua library for interfacing the Awesome window manager with redshift
Lua
5
star
58

crobots

CROBOTS is a programming game, for (aspiring) programmers
C
5
star
59

gul

The one true GUL editor!
C
5
star
60

awesome-plain

Plain barebones AwesomeWM setup
Lua
4
star
61

usbctl

A user space tool to operate on USB devices.
C
4
star
62

mctools

Collection of (old) multicast tools
C
4
star
63

deb

Signing key(s) for .deb repository
3
star
64

booz

Zoo Extractor/Lister by Rahul Dhesi
C
3
star
65

sniffer

sniff packets from interface store in db for analysis
C
3
star
66

zroute

Very simple command line client for managing Zebra static routes from the command line. Useful if Zebra is your route manager and you want your DHCP client, or PPPoE client, to set default gateway dynamically via Zebra instead of as kernel routes.
C
3
star
67

libc-chaos

Emit random errors when calling libc functions to emulate an unstable underlying system
C
3
star
68

misc

Misc. helpers, in the public domain
Makefile
2
star
69

alpine-qemu-image

Create bootable Qemu images fro Alpine Linux ISO
Shell
2
star
70

ns

Example of how to use getaddrinfo()
C
2
star
71

awesome-light

Lua library for controlling screen and keyboard brightness from Awesome WM
Lua
2
star
72

plotty

Library for text terminal plotter
C
2
star
73

klish-plugin-sysrepo

Mirror of Serj Kalichev's klish plugins for sysrepo
C
2
star
74

faux

Mirror of Serj Kalichev's auxillary functions library
C
2
star
75

troglobit.github.io

Personal website and blog
CSS
2
star
76

demo

Collection of ASCII art demos
C
1
star
77

ubot

very small and stupid irc bot
C
1
star
78

awesome

My awesome-copycats adaptions
Lua
1
star
79

logrun

An event-based, regexp-triggered, job runner ...
Perl
1
star
80

klish

Mirror of Serj Kalichev's klish
C
1
star
81

br2-finit-demo

Demo of Finit (FastInit) in Buildroot
Makefile
1
star
82

zephyr-uart-test

Playground for the Zephyr UART
C
1
star
83

busybox-builder

busybox defconfig++ binaries
Shell
1
star
84

bridged

Linux bridge helper daemon
C
1
star
85

weatherd

Hackish weather data logger for my homemade Raspberry Pi based weather station
C
1
star