V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
617450941
V2EX  ›  Linux

iptables 怎么限制一个端口只能一个 ip 连接 求解

  •  
  •   617450941 · 2015-10-20 22:50:53 +08:00 · 3934 次点击
    这是一个创建于 3112 天前的主题,其中的信息可能已经有所发展或是发生改变。
    iptables 怎么限制一个端口只能一个 ip 连接 求解 网上找了很多都是限制连接数的 不是限制 ip 的 想一个端口就只能一个 ip 连接
    6 条回复    2018-04-12 20:27:42 +08:00
    kimw
        1
    kimw  
       2015-10-21 01:29:18 +08:00
    iptables -I INPUT -s IP_ADDRESS -j ACCEPT
    iptables -A INPUT -j DROP --reject-with icmp-port-unreachable
    kimw
        2
    kimw  
       2015-10-21 01:30:58 +08:00
    上面一个不算不算。重来。

    iptables -I INPUT -s IP_ADDRESS -p all --dport PORT -j ACCEPT # please fill up the IP_ADDRESS and PORT
    iptables -A INPUT -j DROP --reject-with icmp-port-unreachable
    617450941
        3
    617450941  
    OP
       2015-10-21 09:19:55 +08:00
    @kimw 怎么限制一段端口比如 20000-30000 的端口只能一个 ip 连接
    kimw
        4
    kimw  
       2015-10-22 17:13:55 +08:00
    > @kimw 怎么限制一段端口比如 20000-30000 的端口只能一个 ip 连接

    iptables -I INPUT -s IP_ADDRESS -p all --dport PORT1:PORT2 -j ACCEPT # please fill up the IP_ADDRESS, PORT1 and PORT2
    iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable

    PORT1-PORT2 就是范围。

    另, 1L 、 2L 的最后一行的 -j DROP 应该是 -j REJECT 。之前有笔误。
    ycyppq123
        5
    ycyppq123  
       2015-10-26 21:52:23 +08:00
    @kimw 弄了个 ss ,分享给朋友用,想限制一个端口只能一个 IP 连接怎么设置呢?
    dayslife
        6
    dayslife  
       2018-04-12 20:27:42 +08:00
    @ycyppq123 我和你有相同的需求,也有这想法,你实现了吗,加我一下 qq ? 2329330680
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   910 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:01 · PVG 04:01 · LAX 13:01 · JFK 16:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.