如何只允许通过隧道连接到端口?

| 我想让git-daemon通过永久的ssh隧道。我完成了这项任务。如何阻止与GIT_DAEMON端口(在我的情况下为9418)的任何远程未隧道连接? 我已经在iptables中尝试了简单的规则(阻止除localhost外的所有内容):
$ iptables -A INPUT -p tcp -d ! localhost --destination-port 9418 -j DROP
但是,它也阻止了一条隧道(因为它保存了源IP地址)。如果我还有一个用于防火墙的主机,可以通过阻止与此端口的任何远程连接来简单地完成,但是我需要该主机来完成此工作。 通过以下两种方式之一创建隧道: 对于Windows:
plink.exe -N -i <key> -L 127.0.0.1:9418:192.168.1.69:9418 tunnel@192.168.1.69
对于Linux:
ssh -N -i <key> -L 127.0.0.1:9418:192.168.1.69:9418 tunnel@192.168.1.69
    
已邀请:
        您可以尝试以下操作(未经测试):
# accept localhost
iptables -A INPUT -p tcp -d localhost --destination-port 9418 -j ACCEPT

# send everyone else packing
iptables -A INPUT -p tcp --destination-port 9418 -j DROP
使用that4ѭ表示:
ACCEPT     tcp  --  anywhere             localhost.localdomain tcp dpt:git
DROP       tcp  --  anywhere             anywhere            tcp dpt:git
编辑 这(可能)是如何设置隧道的:
ssh -N -i <key> -L 127.0.0.1:9418:127.0.0.1:9418 tunnel@192.168.1.69
重要的是,下半部分是
127.0.0.1
,而不是普通IP     
        实际上,只需将ѭ8绑定到回送接口,就可以完全不使用iptables来实现此目的。
git daemon --listen=127.0.0.1
这样就可以使其仅可从localhost连接,并且不需要root权限来设置。     

要回复问题请先登录注册