I would like to forward an external port to a different port on a machine on a private network. However, I need to SNAT the traffic to appear to be from the gateway's internal IP, since the destination machine has a totally different outbound route. I'm combining two questions here, but I'm not sure if I can merge the results of asking them separately.
Gateway = 1.2.3.4/192.168.2.5, internal server = 192.168.2.10
I'm used to doing this, …
服务器A
服务器B
如何使用 iptables 将流量从 eth0 转发到 wg0 10.66.66.2?我想将以下 TCP 和 UDP 端口转发到ServerB
TCP: 2302、27015-27030、27036-27037 UDP: 2302、4380、27000-27031、27036
我已经尝试过转发所有短信,但无济于事。
sudo iptables -A FORWARD --in-interface eth0 -j ACCEPT
sudo iptables --table nat -A POSTROUTING --out-interface wg0 -j MASQUERADE
Run Code Online (Sandbox Code Playgroud)
编辑:
iptables -L我需要注意遗留 iptables 和“正常”iptables 之间的歧义吗?
[root@vmd40065 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere …Run Code Online (Sandbox Code Playgroud) 作为抵御蛮力攻击的第一道防线,我使用 TCP 包装器限制了 SSH 登录尝试(默认情况下拒绝访问,并在 中维护 IP 白名单/etc/hosts.allow)。
但是,有时我需要从不在白名单中的 IP 地址访问我的服务器(并且我的系统最终阻止了我自己的尝试)。
是否可以允许所有 IP 地址的 SSH 密钥登录,但禁止来自不在给定白名单中的 IP 的仅密码登录?我知道我可以将 SSH 配置为仅允许使用密钥登录,但我想保留在一系列 IP 地址上使用密码登录的能力。
我有一些 vps 空间,但根据我在 iftop 中看到的内容,我得到了很多扫描。我尝试了一些 iptables 的东西,但是将我在日志中看到的所有 ip 放在一起会很累而且毫无用处。我想知道最好的方法来确保我可以稳定连接到我的 vps,同时保持几乎所有功能关闭,直到我想通过 iptables 启用。/
目前我有 Debian,并在其上运行活动的 Vpn 和 Ssh。我想要最基本的东西+VPN+ssh 接受传入和传出连接,其余的可以留在我的前院之外。
基本上我正在寻找可以与 Debian 一起使用的命令列表。我根据我在网上看到的内容尝试了很多东西。有些东西引发了错误,有些让我感到困惑。无论如何,我能够将一些事情结合起来,比如接受 VPN 上的连接。我想我只需要一份清晰的清单。
我不需要定义负责连接的单个 ip,所以 ports 会为我做这件事。我可以稍后自己添加 IP 目的地。
谢谢
在我的 OpenWRT 实例中,我在 Input filter table 中添加了 iptables 规则,但问题是当我打开我的系统时我发现规则被删除了。我该怎么做才能使规则不会自动删除。
我的服务器上使用了一个简单的重定向,并带有 iptables 规则:
$ iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 13.37.42.1:80
$ iptables -t nat -A POSTROUTING -j MASQUERADE
我不明白第二行(化妆舞会)的用处。为什么/为什么它在这个例子中有用?
编辑:为什么 - 不是理论上的,而是现实中的 - 你会在这样的例子中使用它吗?
谢谢
我了解IPTables 中的作用prerouting和postrouting链的作用,但我无法理解作用output和input链的作用。
因此,在 NATing 中,我们使用DNATin更改目标 IP 或端口prerouting,或使用SNAT或MASQURADEin更改源 IP 以获取对正确接口的回复postrouting。
在这种情况下,我发现没有使用input和output链。有人可以快速向我解释它们(input和output)吗?
我的 ISP 屏蔽了很多东西,在每台设备上设置 DNSCrypt 是一件很痛苦的事情(在某些设备上,比如没有 root 的 Android 是不可能的)。
因此,我决定将路由器固件迁移到 DD-WRT,并尝试使用除该端口之外的其他端口强制将所有请求从 53 重定向到 DNS。我发现 OpenDNS 也在端口 443 上开放,但要解锁所有站点是不可能的,因为共享 IP 系统每 1-3 分钟更改一次(OpenDNS 需要知道您的公共 IP 地址才能应用自定义过滤器)。
我连续寻找了三天,却一无所获。你们中有人知道任何具有来自任何国家/地区的自定义端口(除 53 之外的端口)的 DNS 服务器吗?只要该服务器处于开启状态并 24/7 开放,或者可能有一种使 iptables 或 dnsmasq 使用端口 853 的方法?
注意:由于某种原因使用这些命令:
iptables -t nat -I PREROUTING -p tcp --dport 53 -j DNAT --to 54.255.130.140:443
iptables -t nat -I PREROUTING -p udp --dport 53 -j DNAT --to 54.255.130.140:443
Run Code Online (Sandbox Code Playgroud)
不适用于 853 端口。看起来它有不同的请求 DNS 的方法。
从今天起,每当我使用带有bridge网络接口的任何 docker 容器时,某些实用程序的 DNS 解析似乎都失败了。
例如,如果我运行:
sudo docker run --rm \
--cap-add=NET_ADMIN \
--log-driver json-file \
--log-opt max-size=10m \
--net=bridge --dns 9.9.9.9 \
alpine \
sh -c 'apk add curl bind-tools; printf "\nDATE:\n"; date; printf "\nRESOLV.conf\n"; cat /etc/resolv.conf; printf "\nDIG:\n"; dig api.nordvpn.com; printf "\nTRACE:\n"; dig +trace api.nordvpn.com; printf "\nHOST:\n"; host -va api.nordvpn.com; printf "\nNSLOOKUP:\n"; nslookup api.nordvpn.com; printf "\nCURL:\n"; curl api.nordvpn.com; printf "\nPING:\n"; ping -c 5 api.nordvpn.com; printf "\nWHOIS:\n"; whois api.nordvpn.com; printf "\nRESOLVE:\n"; systemd-resolve --status'
Run Code Online (Sandbox Code Playgroud)
我回来了:
DATE:
Sun Jul …Run Code Online (Sandbox Code Playgroud)