the*_*uke 2 linux iptables port
是否可以以一种方式配置 IPTables,即所有发往某个 IP 和端口的传出数据包都使用不同的端口进行更改,并对传入数据包执行相同操作?
我必须经常使用服务器,并且主机决定 SSH 访问只能在端口 222 而不是默认的 22。
这在 ssh、scp 或 rsyncing 时总是令人头疼。您必须始终记住添加端口参数。
我想用 IPTables 来规避这个。
非常感谢任何帮助。
是的,当然应该可以为 NAT 传出流量设置 iptable 规则。您真的应该只需要创建一个处理输出流量的规则。你不应该需要一个规则来对返回的数据包做任何事情。netfilter 的有状态特性会为您处理这个问题。
您可能需要使用其中一种规则。
# if you want to redirect requests from the local machine
iptables -t nat -A OUTPUT--destination remote.host.ip \
-p tcp --dport 22 -j DNAT --to-destination remote.host.ip:222
# if you want to redirect requests on a device inline
iptables -t nat -A PREROUTING --destination remote.host.ip \
-p tcp --dport 22 -j DNAT --to-destination remote.host.ip:222
Run Code Online (Sandbox Code Playgroud)
另一个简单的解决方案是简单地为服务器设置一个 SSH 配置文件并在您的配置中指定端口。
# list of all names, you might commonly use for this host.
Host foo foo.example.org foo.example
# real hostname
Hostname real.example.org
Port 222
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9416 次 |
最近记录: |