
我sshd: Listen 2222
在伺服器上有,我想做的是:
ssh -p 2222 userA@ip
,伺服器找到userA
,然後將此連接重定向到6122
該伺服器的端口,但我不想在本地電腦上修改,因為有數百個用戶,所有這些用戶都有自己的docker容器,例如,對於用戶userA
,我sshd
在其容器上運行,並將22
連接埠暴露給6122
主機連接埠。所以我想用iptables
或其他方式轉發Host:2222
到Container:6122
。
我嘗試過如下命令:
iptables -t nat -A userA_rules -p tcp --dport 2222 -j REDIRECT --to-port 6122
iptables -A OUTPUT -m owner --uid-owner userA -j userA_rules
但這不起作用。我是新手iptables
,所以我不確定哪裡錯了。我也嘗試修改/etc/ssh/sshd_config
為使用Match User userA
區塊,但我也失敗了。任何建議,將不勝感激。
答案1
iptables 擁有者模組僅適用於在產生資料包的電腦上本機產生的資料包,而不是在遠端伺服器上產生的資料包。
https://manpages.ubuntu.com/manpages/focal/en/man8/iptables-extensions.8.html
owner
This module attempts to match various characteristics of the packet creator, for locally
generated packets. This match is only valid in the OUTPUT and POSTROUTING chains.
Forwarded packets do not have any socket associated with them. Packets from kernel threads
do have a socket, but usually no owner.
但該 UID/GID 在伺服器外部不可用。
Iptables 工作於 TCP/IP 網路封包。封包具有目標 IP 目標端口、來源 IP 和來源端口,但沒有屬性表明:它們是由freshzy
來源電腦上的使用者或 UID #123 產生的。因此,遠端伺服器上的 iptables 根本沒有資訊來執行您希望它執行的操作;從遠端電腦為一個使用者建立規則。