V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
gzk329
V2EX  ›  程序员

[求助] 对指定的一组 IP 开放所有的端口,应该怎么写?

  •  
  •   gzk329 · Jun 16, 2023 · 1300 views
    This topic created in 1048 days ago, the information mentioned may be changed or developed.

    麒麟系统 用 iptables iptables -A INPUT -s IP_ADDRESS -j ACCEPT &&。 iptables -A OUTPUT -d IP_ADDRESS -j ACCEPT

    3 replies    2023-06-16 18:21:46 +08:00
    onetown
        1
    onetown  
       Jun 16, 2023
    用 ipset 啊

    '''
    ipset create whitelist hash:ip
    iptables -A INPUT -m set --match-set whitelist src -j ACCEPT
    iptables -A OUTPUT -m set --match-set whitelist dst -j ACCEPT
    '''

    然后用
    ipset add whitelist 1.1.1.1
    添加地址
    GeorgeWai
        2
    GeorgeWai  
       Jun 16, 2023
    如果 ip 不连续,写个 for 循环呗,源 ip 可以写在文件里
    #!/bin/bash
    for ip in `cat ip.list`
    do iptabale -A INPUT -s $ip -j ACCEPT
    done
    最后加一条缺省禁止访问的策略策略,一般 output 不加策略吧
    NessajCN
        3
    NessajCN  
       Jun 16, 2023 via Android
    ufw allow from [ip]
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5710 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 69ms · UTC 06:15 · PVG 14:15 · LAX 23:15 · JFK 02:15
    ♥ Do have faith in what you're doing.