标签: iptables

docker-compose 只向外界暴露一个网络

我有一个通过 docker-compose 文件创建的新应用程序。该文件包含2个网络:

version: '2.1'

# ----------------------------------
# Services
# ----------------------------------
services:
  application:
    image: tianon/true
    volumes:
      - ${APPLICATION_PATH}:/var/www

  nginx:
    build:
      context: ./docker/nginx
    volumes_from: 
      - application
    volumes:
      - ${DOCKER_STORAGE}/nginx-logs:/var/log/nginx
      - ${NGINX_SITES_PATH}:/etc/nginx/sites-available
    ports:
      - "${NGINX_HTTP_PORT}:80"
      - "${NGINX_HTTPS_PORT}:443"
    networks:
      - frontend
      - backend

  redis:
    build:
      context: ./docker/redis
    volumes: 
      - ${DOCKER_STORAGE}/redis:/data
    ports:
      - "${REDIS_PORT}:6379"
    networks: 
      - backend

# ----------------------------------
# Networks
# ----------------------------------
networks:
  frontend:
    driver: "bridge"
  backend:
    driver: "bridge"

# ----------------------------------
# Volumes
# ----------------------------------
volumes:
  redis:
    driver: "local"
Run Code Online (Sandbox Code Playgroud)

您会注意到我这里有 2 个网络,frontend …

iptables docker docker-compose

2
推荐指数
1
解决办法
9337
查看次数

带有 hashlimit 和“--state NEW”的 iptables 阻止了太多新连接

我已经设置了速率限制来阻止对我的 ssh 服务器的暴力攻击。我使用以下 iptables 规则:

iptables -A INPUT -p tcp -m tcp --dport 22 -m hashlimit --hashlimit-upto 4/min
--hashlimit-burst 6 --hashlimit-mode srcip --hashlimit-name ssh
--hashlimit-htable-expire 60000 -m state --state NEW -j ACCEPT

iptables -A INPUT -m tcp -p tcp --dport 22 -m state --state NEW -j REJECT
Run Code Online (Sandbox Code Playgroud)

当我打开一个 SSH 连接(例如通过 PuTTY),然后一分钟后尝试打开另一个连接(例如,传输文件)时,第二个连接有时会被拒绝,服务器没有响应。如果我设法打开第二个 SSH 连接,然后尝试打开第三个连接,它会变得更加困难(很可能没有响应)。

我已经验证,当我禁用上述规则时,一切正常。增加--hashlimit-upto和/或--hashlimit-burst有帮助,但并不能完全解决问题——它只会降低问题发生的可能性。有时仍然会发生拒绝,但如果我禁用 iptables 规则,则永远不会发生。

到底是怎么回事?上述 iptables 规则规定,与新连接相关的 TCP 数据包应限制为每分钟 4 个。所以我应该能够轻松地每分钟打开最多 4 个连接。

iptables linux-networking

2
推荐指数
1
解决办法
4427
查看次数

如何通过wireguard覆盖网络转发/路由数据包?

我的问题与网络路由和 iptables 的基础知识有关,可能是因为我对如何设置它缺乏了解。

我使用wireguard 在主机之间建立了一个覆盖网络,其中一个位于路由器/NAT 后面。到目前为止,覆盖网络运行良好,每个主机都可以与其他主机通信。

现在,我想让主机 A 成为专用网络的网关,但遗憾的是我未能做到这一点。

你能帮我解开 iptables 转发之谜吗?

3 网络

VPN 的覆盖网络是169.254.0.0/24,路由器后面的专用网络是192.168.0.0/24

  • 互联网
  • 覆盖网络(169.254.0.0/24,在 Wireguard 上运行)
  • 专用网络 ( 192.168.0.0/24)

4 台主机

  • VPN服务器

    wg0: 169.254.0.1

  • 客户

    wg0: 169.254.0.2

  • 主机A

    wg0: 169.254.0.3
    eth0: 192.168.0.33

  • 主机B

    eth0: 192.168.0.53

为了说明真实的网络,下面是这张图: 真实网络

这是覆盖网络: 覆盖网络

此时,我的客户端无法通过主机 A 向主机 B 发送数据包。

linux routing iptables wireguard

2
推荐指数
1
解决办法
4155
查看次数

iptables 不喜欢争论

我正在设置一个 debian 10 服务器,这是我第一次使用 iptables,但 iptables 似乎不喜欢基本参数。我浏览了联机帮助页并尝试了https://phoenixnap.com/kb/iptables-tutorial-linux-firewall中的内容

\n
~# iptables \xe2\x80\x93A INPUT \xe2\x80\x93j DROP\nBad argument `\xe2\x80\x93A\'\nTry `iptables -h\' or \'iptables --help\' for more information.\n\n~# iptables \xe2\x80\x93A INPUT \xe2\x80\x93p tcp \xe2\x80\x93\xe2\x80\x93dport 80 \xe2\x80\x93j ACCEPT\nBad argument `\xe2\x80\x93A\'\nTry `iptables -h\' or \'iptables --help\' for more information.\n\n~# iptables \xe2\x80\x93A INPUT \xe2\x80\x93i lo \xe2\x80\x93j ACCEPT\nBad argument `\xe2\x80\x93A\'\nTry `iptables -h\' or \'iptables --help\' for more information.\n\n~# iptables --version\niptables v1.8.2 (legacy)\n
Run Code Online (Sandbox Code Playgroud)\n

这里发生了什么事?

\n

联机帮助页了解 -A :

\n
SYNOPSIS\n   iptables [-t table] {-A|-C|-D} chain rule-specification\n
Run Code Online (Sandbox Code Playgroud)\n …

debian iptables

2
推荐指数
1
解决办法
1497
查看次数

Fail2Ban iptables 条目拒绝 HTTPS 不会停止对 Amazon Linux 2 上的 Docker 容器的请求

我已经在 Amazon Linux 2 上设置了 Fail2Ban,使用nginx-http-auth以下覆盖配置启用内置监狱:

[nginx-http-auth]
enabled = true
action = iptables[name=HTTPS, port=https, protocol=tcp]
logpath = <snip>/logs/*error*.log
findtime = 15m
bantime = 15m
maxretry = 5
Run Code Online (Sandbox Code Playgroud)

该操作正在触发,我收到以下条目iptables -S

-A f2b-HTTPS -s 120.<snip>.122/32 -j REJECT --reject-with icmp-port-unreachable
Run Code Online (Sandbox Code Playgroud)

但是,我可以继续从被禁止的 IP 发出新的 HTTPS 请求,这些请求正在接收来自 Nginx 的 401 响应。我从两个 IP 地址进行复制 - 我的手机和另一个 EC2 主机。

以下是完整输出iptables -L:(注意:Nginx 在 Docker 内部运行,另外两个与本地网络隔离的容器也是如此)

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
f2b-HTTPS  tcp  --  anywhere             anywhere             tcp dpt:https

Chain …
Run Code Online (Sandbox Code Playgroud)

https iptables fail2ban docker amazon-linux-2

2
推荐指数
1
解决办法
2620
查看次数

如何设置 iptables 以阻止对服务器的传入请求,但仍然具有互联网连接

我的服务器上正在运行多个服务。但我不希望他们接触互联网。我的输入链规则看起来像这样

-P INPUT ACCEPT
-P FORWARD DROP
-P OUTPUT ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-port-unreachable
Run Code Online (Sandbox Code Playgroud)

但这会阻止与我的服务器的互联网连接,并 sudo apt update引发此错误

W:无法获取http://in.archive.ubuntu.com/ubuntu/dists/jammy/InRelease 解决“in.archive.ubuntu.com”的临时失败

ping www.google.com失败

ping: www.google.com : 名称解析暂时失败

这看起来是 DNS 的问题,但我相信规则 4 应该可以解决这个问题。对此的任何帮助将不胜感激。谢谢!

crdy@kronos:~$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd …
Run Code Online (Sandbox Code Playgroud)

networking firewall iptables

2
推荐指数
1
解决办法
278
查看次数

使用 iptables 和 dhcpd 进行端口转发

设置:我有一个 Linux(Gentoo,如果有区别的话)盒子,作为整个公寓的网关。这个盒子用 iptables 和 dhcpd 做它的 NAT-magic。

问题:我有一台计算机,我想将端口转发到(对于种子,如果再次存在差异)。

我有足够的 Linux 管理技能来阅读 howtos 并正确配置东西(最终),但我为我的案例找到的 howtos 太不清楚,似乎不必要地复杂。

对于我收集到的内容,我的问题是双重的:让 dhcpd 可靠地将某个静态 IP 分配给我想要的计算机,然后为端口转发配置 iptables。

有人可以给我一个明确的分步指南如何做到这一点吗?我敢肯定,我不是唯一一个想做这件事的人……


编辑:我的软件版本是:

# iptables --version
iptables v1.4.0

# dhcpd --version
isc-dhcpd-V3.1.1-Gentoo

dhcp linux iptables port-forwarding

1
推荐指数
1
解决办法
3419
查看次数

IP 表 - 更改不持久

我尝试使用以下方法打开服务器上的端口 8605(用于套接字连接):

iptables -I INPUT 2 -s 0/0 -p tcp --dport 8605 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)

然而,变化并没有持续,端口每天关闭一次(我假设正在定期重新加载某些东西)。

我怎样才能使我的更改持续存在?

编辑

尽管保存了它,但更改不会持续存在,每天都需要更正。

crontab好像没有什么明显的变化,服务器也没有重启。有任何想法吗?

编辑

我发现 iptables 在apf - 高级策略防火墙下运行,所以我需要更新那里的规则。

firewall iptables port

1
推荐指数
1
解决办法
351
查看次数

哈德森关于 debian lenny

前段时间我在一台服务器上安装了 Hudson deamon(在 debian lenny 测试中运行)。一切正常,直到我执行升级。目前无法在端口 8080(这是使用的默认端口)访问 Hudson。我一直在寻找 iptables 问题,但是端口 8080 在 INPUT 和 OUTPUT 中是打开的。/etc/default/hudson 里的配置文件好像没问题,我没碰过。如果我做一个 ps aux | grep hudson, hudson deamon 正在运行。

更新 1:对我来说真正奇怪的是在 /var/log/hudson/hudson.log 中我没有收到错误:

[Winstone 2010/02/10 17:10:04] - Control thread shutdown successfully
[Winstone 2010/02/10 17:10:04] - Winstone shutdown successfully
Running from: /usr/share/hudson/hudson.war
[Winstone 2010/02/10 17:10:43] - Beginning extraction from war file
hudson home directory: /var/lib/hudson
[Winstone 2010/02/10 17:10:44] - HTTP Listener started: port=8080
[Winstone 2010/02/10 17:10:44] - AJP13 Listener started: port=8009
[Winstone 2010/02/10 17:10:44] …
Run Code Online (Sandbox Code Playgroud)

debian iptables hudson

1
推荐指数
1
解决办法
951
查看次数

iptables 不写规则

我以 root 身份运行这两个规则,但是在执行 iptables -L 时它不显示任何规则,有人知道问题是什么吗?

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 --source 84.244.145.135 -j REDIRECT --to-port 1222
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 --source 243.134.97.194 -j REDIRECT --to-port 1222


duno@Virtual-Box:/home/glennwiz# iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
Run Code Online (Sandbox Code Playgroud)

linux ubuntu iptables port-forwarding rules

1
推荐指数
1
解决办法
134
查看次数