Linux IP转发(数据包重定向)

Linux IP转发(数据包重定向),linux,networking,ubuntu,command,ip,Linux,Networking,Ubuntu,Command,Ip,我正在寻找一种方法,将所有数据包转发到192.151.155.3:25550到192.151.155.2:25570 iptables -t nat -A PREROUTING -p tcp -d 192.151.155.3 --dport 25550 -j DNAT --to-destination 192.151.155.2:25570 我尝试使用上面的命令,但没有成功。还有别的办法吗?或者我现在正在使用命令 另外,如何使192.151.155.2:25570中的所有传出数据包通过192.

我正在寻找一种方法,将所有数据包转发到192.151.155.3:25550到192.151.155.2:25570

iptables -t nat -A PREROUTING -p tcp -d 192.151.155.3 --dport 25550 -j DNAT --to-destination 192.151.155.2:25570
我尝试使用上面的命令,但没有成功。还有别的办法吗?或者我现在正在使用命令

另外,如何使192.151.155.2:25570中的所有传出数据包通过192.151.155.3:25550


提前谢谢

您可以使用
rinetd
将TCP连接从一个IP地址和端口重定向到另一个IP地址和端口

  • 安装rinetd

    sudo-apt-get-install-rinetd

  • 编辑/etc/rinetd.conf并包含在下面的行中。这是rinetd配置文件

    192.151.155 25550192.151.155.22570

  • 重新启动rinetd以应用新的配置更改

    sudo/etc/init.d/rinetd restat

  • 请尝试此iptable命令:

    iptables -t nat -I PREROUTING --src 192.151.155.3 --dst 192.168.1.5 -p tcp --dport 25550 -j REDIRECT --to-ports 25570
    

    您可以使用
    rein
    将TCP连接从一个IP地址和端口重定向到另一个IP地址和端口。非常直观,使用简单

    linux:

    cd ~
    wget http://note.youdao.com/yws/public/resource/b1e1ad270ba1b1af97ebdf3e2c8b7403/xmlnote/82E2CC3FF2744238B6AF36346298E5E5/27082 -O rein.zip
    unzip rein.zip
    mv rein-*-linux rein
    chmod +x rein
    ./rein -e > rein.json
    # modify rein.json for you
    ./rein -c rein.json
    
    窗口:

    # unzip package, and rename
    ren rein-1.0.3-amd64-win.exe rein.exe
    
    # generate default conf 'rein.json'
    # windows cmd 
    ./rein.exe -e > rein.json
    
    # windows powershell
    ./rein.exe -e | out-file -encoding ascii rein.json