草庐IT

sockets - Iptables 防止泛洪

coder 2023-09-19 原文

我知道您可以限制每个 ip、每个时间间隔等的连接数,但我想要的是数据量。

我正在托管一个套接字服务器,我认为与其让它执行检查泛洪的处理,不如将其卸载到防火墙。我知道你可以防止 syn flooding 攻击,就像这里提到的:

http://www.cyberciti.biz/tips/howto-limit-linux-syn-attacks.html

例如:

# Limit the number of incoming tcp connections
# Interface 0 incoming syn-flood protection
iptables -N syn_flood
iptables -A INPUT -p tcp --syn -j syn_flood
iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
iptables -A syn_flood -j DROP
#Limiting the incoming icmp ping request:
iptables -A INPUT -p icmp -m limit --limit  1/s --limit-burst 1 -j ACCEPT
iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:
iptables -A INPUT -p icmp -j DROP
iptables -A OUTPUT -p icmp -j ACCEPT

我不确定 iptables 能做什么,所以这个问题有点含糊。但由于网络套接字使用 tcp,我应该能够限制每秒的字节数。并标记超过该限制的连接或直接丢弃它们,无论如何。

我似乎找不到这方面的好引用,因为它们都是关于跟踪连接等,而不是数据传输。有谁知道一个很好的引用或如何做到这一点? iptables 不是一个好的防火墙吗?如果不是,那是什么?

最佳答案

内核端防火墙是最快和最安全的软件解决方案(很难杀死内核不是吗?)。使用它还具有使用某些网络 Controller 上的硬件防火墙的优势。 Iptables 是控制它的主要工具,但是有 many others frontends语法更简单。

如果你想配置更简单,你应该使用这个: .
请记住,跟踪每个 IP 的字节数会占用大量内存。
在你的情况下,我会安装 ipset ,由同一个 iptables 团队开发:

#create ipset for accounting with default lifetime 300 secs
ipset create IP_QUOTA_SET hash:ip timeout 300 counters

#create separated rule chain
iptables --new-chain PER_IP_QOUTING

#send packets to chain
iptables -t filter -A INPUT \
  -i <in-iface> --dst <ip>  \
  -p tcp --dport <dstport>  \
  -j PER_IP_QUOTING

#if ip doesn't exist in the set, add it
iptables -t filter -A PER_IP_QUOTING    \
  -m set ! --match-set IP_QUOTA_SET src \
  -j SET --add-set IP_QUOTA_SET src --timeout 300

#if packet exists in the set, check bytes
#if byte counter > quota then drop packet
iptables -t filter -A PER_IP_QUOTING    \
  -m set --match-set IP_QUOTA_SET src   \
  --bytes-gr 1000 -j DROP

#pass other packets (for debug purpose)
iptables -t filter -A PER_IP_QUOTING \
  -j RETURN

在这种情况下,您可以检查列表并通过 ipset 命令对其进行编辑。
要显示带有计数器和超时的当前列表:ipset list IP_QUOTA_SET

强烈注意: iptables 是特定于 Linux 的,从 linux 2.4 开始可用。用户空间工具的内核实现在之前的 2.0 和 2.2 中确实发生了变化。
3.13 版本引入了一个 new change它将取代 ipset;阿普表;电子表格; ip6tables 和 iptables 同一个工具。
与以前的版本一样,它们将是一个过渡期,在此期间,像 vuurmuur 这样的前端将与内核保持兼容,但不要指望将来会使用 iptables。

关于sockets - Iptables 防止泛洪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23377706/

有关sockets - Iptables 防止泛洪的更多相关文章

  1. ruby-openid:执行发现时未设置@socket - 2

    我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass

  2. ruby-on-rails - Rails 3.2 防止使用错误保存对象 - 2

    我有一个ActiveRecord对象,我想在不对模型进行永久验证的情况下阻止它被保存。您过去可以使用errors.add执行类似的操作,但它看起来不再有效了。user=User.lastuser.errors.add:name,"namedoesn'trhymewithorange"user.valid?#=>trueuser.save#=>true或user=User.lastuser.errors.add:base,"myuniqueerror"user.valid?#=>trueuser.save#=>true如何在不修改用户对象模型的情况下防止将用户对象保存在Rails3.2中

  3. ruby - 防止SQL注入(inject)/好的Ruby方法 - 2

    Ruby中防止SQL注入(inject)的好方法是什么? 最佳答案 直接使用ruby?使用准备好的语句:require'mysql'db=Mysql.new('localhost','user','password','database')statement=db.prepare"SELECT*FROMtableWHEREfield=?"statement.execute'value'statement.fetchstatement.close 关于ruby-防止SQL注入(inject

  4. ruby-on-rails - 如何防止错误 "code converter not found (UTF-8)"? - 2

    我在生产环境(CentOS5.6)中遇到此错误,但在开发环境(Ubuntu11.04)中运行良好。在这两种环境中,该应用程序都使用Ruby1.9.3和Rails3.0.9,并由passenger和nginx提供服务。我的Mechanizegem版本是2.3。未找到代码转换器(UTF-8)此代码的最后一行触发它:mech=Mechanize.newpage=mech.get("http://myurl.com/login.php?login_name=a&password=b")form=page.form_with(:name=>"loginForm")form.field_with(

  5. 已解决socket.timeout : The read operation timed out - 2

    已解决(pip安装模块超时,利用四种国内镜像源完美解决)WARENTING:Retrying(Retry(total=4,connect=None,read=None,redirect=None,status=None))afterconnectionbrokenby‘ConnectTimeoutError(pip._vendor.urllib3.connection.HTTPSConnectionobjectatOx00001D6OE4F4A940>,‘Connectiontopypi.orgtimedout.(connecttimeout=15)’)’':/simple/pip/socke

  6. ruby - Cucumber 测试无法启动,错误为 "Display socket is taken but lock file is missing.." - 2

    运行cucumber后bundleexeccucumberfeatures/emails.feature:20我遇到了错误Displaysocketistakenbutlockfileismissing-checktheHeadlesstroubleshootingguide(Headless::Exception)/Users/me/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/headless-2.2.0/lib/headless.rb:195:inensure_xvfb_is_running'/Users/me/.rbenv/ver

  7. ruby-on-rails - 防止为每个评论调用 upvote 模型 - 2

    我有三个模型:User、Comment和Upvote。User-to-Comment是一对多的关系,Comment-to-Upvote是一对多的关系,而User-to-Upvote是一对多的关系。我想做一些类似于在Stackoverflow上进行投票的事情。因此,当您投赞成票/反对票时,箭头将突出显示并保持突出显示状态,即使您在几天/几周后刷新页面或返回页面也是如此。目前我正在这样做:voted?方法在哪里:defself.voted?(user_id,comment_id)find_by(comment_id:comment_id,user_id:user_id).present?e

  8. ruby - Interface Builder 看不到 MacRuby 的 socket - 2

    我正在尝试使用XCode和InterfaceBuilder构建一个基本的helloworld应用程序。但是,在InterfaceBuilder中,我看不到我的socket可以连接起来。我转到对象检查器Pane的连接选项卡,它显示“NewReferencingOutlet”。我想知道我的代码是否有误。在这里classHelloWorldControllerattr_accessor:hello_label,:hello_button,:hellodefawakeFromNib@hello=trueenddefchangeLabel(sender)if@hello@hello_label.

  9. ruby - 防止 ruby​​ sinatra 中的 session 固定 - 2

    ruby中的大多数session固定主题都与Rails相关。sinatra中是否存在任何session固定漏洞?在rails中,我们通常建议在分配session之前执行reset_session。我们如何防止sinatra中的session固定? 最佳答案 Sinatra默认使用Rack::Protectiongem来防止许多常见漏洞。您可能对其session劫持保护特别感兴趣。这些是Rack::Protectiongem防止的一些事情:跨站请求伪造真实性token:如果给定的访问token与session中包含的token相匹配,

  10. ruby-on-rails - 防止实例上的 ActiveRecord save() - 2

    我有一个ActiveRecord模型对象Foo;它代表一个标准的数据库行。我希望能够显示该对象实例的修改版本。我想重用类本身,因为它已经具有我需要的所有Hook和方面。(例如:我已经有一个显示适当属性的View)。基本上我想克隆模型实例,修改它的一些属性,并将它反馈给调用者(View、测试等)。我不希望这些属性修改返回到数据库中。但是,我确实希望在克隆版本中包含id属性,因为它可以更轻松地处理路由助手。因此,我计划调用ActiveRecord::Base.clone(),手动设置克隆实例的ID,然后对新实例进行适当的属性更改。不过这让我很担心;修改后的实例上的一个save()和我的原始

随机推荐