【问题标题】:Blocking my vps from connecting to other vps/ip/port via sshd阻止我的 vps 通过 sshd 连接到其他 vps/ip/port
【发布时间】:2019-08-31 05:08:09
【问题描述】:

我想拒绝从我的 vps 到其他 vps/ip/port via sshd.(443) 的任何连接

我尝试使用 iptables 和防火墙规则,似乎仍然没有任何效果。

iptables -A INPUT -s 1.1.1.1 -j DROP ;
iptables -A FORWARD -s 1.1.1.1 -j DROP ;
iptables -A OUTPUT -s 1.1.1.1 -j DROP ;
iptables -A INPUT -p tcp -s 1.1.1.1 --dport 443 -j REJECT --reject-with tcp-reset ;
iptables -A OUTPUT -p tcp -s 1.1.1.1 --dport 443 -j REJECT --reject-with tcp-reset ;
iptables -A FORWARD -p tcp -s 1.1.1.1 --dport 443 -j REJECT --reject-with tcp-reset ;
iptables -I INPUT -s 1.1.1.1 -p tcp --dport 443 -j REJECT ; 
iptables -I OUTPUT -s 1.1.1.1 -p tcp --dport 443 -j REJECT ;
iptables -I FORWARD -s 1.1.1.1 -p tcp --dport 443 -j REJECT ;
firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -m tcp --source 1.1.1.1 -p tcp --dport 22 -j REJECT ;
firewall-cmd --direct --add-rule ipv4 filter OUTPUT 1 -m tcp --source 1.1.1.1 -p tcp --dport 22 -j REJECT ;
firewall-cmd --direct --add-rule ipv4 filter FORWARD 1 -m tcp --source 1.1.1.1 -p tcp --dport 22 -j REJECT ;

【问题讨论】:

    标签: block firewall iptables vps sshd


    【解决方案1】:

    如果您使用的是具有UFW 的发行版,例如 Ubuntu,则可以使用以下 3 个命令轻松阻止出站连接。更重要的是,这将在重启后继续存在,这与任何 iptables 命令不同,后者需要 iptables-save 或其他工具在重启后重新应用 iptables 设置。

    您没有提及其他出站连接。下面的命令会阻止所有出站连接(但对于从外部发起的连接,不会阻止出站流量)。

    sudo ufw enable
    sudo ufw default allow incoming # allow inbound connections
    sudo ufw default deny outgoing
    

    暂时允许出站连接,例如下载软件更新:

    sudo ufw default allow outgoing
    # run your update here
    sudo ufw default deny outgoing
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-17
      • 1970-01-01
      • 2020-03-31
      • 1970-01-01
      • 2019-11-12
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多