iptables将所有请求重定向到本地主机 [英] iptables redirect all requests to localhost

查看:269
本文介绍了iptables将所有请求重定向到本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有请求重定向到本地主机(127.0.0.1)。我需要它,因为我有一个服务器的本地副本,想要测试一些东西

I want to redirect all requests made to a particular ip to localhost (127.0.0.1). I need it because I have a local replica of a server and want to test some things

我如何写一个iptables规则呢?

How can I write a iptables rule to do that?

谢谢

推荐答案

我知道这是一个很老的线程...但是还没有回答。所需的主要更改将是附加OUTPUT规则而不是PREROUTING规则。

I know this is a pretty old thread... But still without an answer. The main change required will be to append an OUTPUT rule rather than PREROUTING rule.

从手册页:

nat:
    This table is consulted when a packet that creates a new connection is encountered.  It consists of three built-ins: PREROUTING (for altering packets as soon as they come in), OUTPUT (for altering locally-generated packets  before  routing),  and  POSTROUTING  (for altering packets as they are about to go out).

所以,这可能是所需的命令:

So, this might be the command required:

iptables -t nat -A OUTPUT -p tcp --src <SOURCE PORT TO BE REDIRECTED> --dst 127.0.0.1 --dport 9090 -j REDIRECT --to-ports 9090

这篇关于iptables将所有请求重定向到本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆