<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Iptables on Cylon&#39;s Collection</title>
    <link>https://www.161616.top/tags/iptables/</link>
    <description>Recent content in Iptables on Cylon&#39;s Collection</description>
    <generator>Hugo -- 0.125.7</generator>
    <language>zh</language>
    <lastBuildDate>Fri, 23 Aug 2024 23:00:36 +0800</lastBuildDate>
    <atom:link href="https://www.161616.top/tags/iptables/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Uranus installation</title>
      <link>https://www.161616.top/uranus-installation/</link>
      <pubDate>Fri, 23 Aug 2024 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/uranus-installation/</guid>
      <description>What is an Uranus? Uranus is a Linux firewalld central controller. In Greek mythology, Uranus king of gods. The firewall gateway is the Uranus for iptables.
Prerequisites Hardware requirements We recommend these hardware requirements for production systems or for development systems that are designed to demonstrate production use cases:
Item Description Minimum requirements Recommended Per instance You can install on one node but many features require at least one node. 1 instance &amp;gt; 1 instances RAM per instance Defining your RAM size must be part of the capacity planning for your Uranus usage.</description>
    </item>
    <item>
      <title>firewalld去除polkit验证</title>
      <link>https://www.161616.top/firewalld-without-polkit/</link>
      <pubDate>Wed, 19 Apr 2023 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/firewalld-without-polkit/</guid>
      <description>为什么去除polkit验证 在2021年询问过firewalld项目组，firewalld在dbus通讯时，会进行两部认证 policy kit 和 UID checking，正是因为这种情况，使得firewalld不能够通过TCP/IP连接，如果你需要连接，因为存在 UID checking ，这时会因为没有UID会报错。
firewalld needs to do some authorization on the dbus request. It currently tries two ways, in order of preference:
policy kit UID checking Neither of these are available over a TCP/IP dbus connection. [1]
如何去除polkit 首选需要确定你的firewalld版本，例如Centos7系列，那么你的 firewalld 版本为 0.6.3，那么你需要修改的包为 python-firewall-0.6.3, 在 debian11 上 firewalld版本默认为 0.9.3，那么需要关注的版本为：python3-firewall_0.9.3
在确定版本后直接从github仓库进行拉去修改就可以
bash 1 2 git fetch v0.9.3 git checkout v0.9.3 对于 python-firewall-0.6.3 来说。直接注释掉 slip.dbus.polkit.require_auth 就可以了</description>
    </item>
    <item>
      <title>ipset性能测试</title>
      <link>https://www.161616.top/ipset-preformance/</link>
      <pubDate>Fri, 04 Nov 2022 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/ipset-preformance/</guid>
      <description>测试方法 基于使用场景，最后⽣成的规则会是按照 ip 或者 ip:port 来进行过滤，测试时将使用10万条 iptables 规则来模拟对性能的压力；为了最大化测试压力情况，10万条 iptables 规则将都是==不会匹配==机房流量，通俗来讲，就是链式匹配会进行所有匹配并最后以无匹配告终。
网络负载的模拟将使用同机房 scp 来模拟，并按照下述条件进行匹配：
查看正常的拷贝速度，cpu负载等 我们建⽴10万条的普通 iptables 规则，查看规则建立速度，拷贝速度，CPU负载，CPU主要耗时操作等 我们建⽴10万的 ipset ，并把普通的 iptables 规则转为结合 ipset 的规则，查看规则建立速度，拷贝速度，CPU负载，CPU主要耗时等。 实验开始 步骤一：在同机房的⼀个机器构造⼀个大文件
同机房拷贝
观察网卡速度，CPU，系统主要耗时操作的等，此场景将在iptables 规则为空的情况下进行观察
使用 sar 观测网卡速度
使用 top 观察CPU负载
使用 perf top -G 观察CPU占用
步骤二：创建10万条iptables，观察⽹卡速度、cpu、系统主要耗时操作的等，会发现cpu利⽤率⼤部分被ipt占⽤，拷⻉速度下降到不到⼗分之⼀
bash 1 2 3 4 5 6 7 8 #!/bin/bash echo *filter for ((i=1;i&amp;lt;=$1;i++)) do echo -I INPUT -S $i -j ACCEPT done echo COMMIT 执行脚本
bash 1 $ time .</description>
    </item>
    <item>
      <title>使用firewalld dbus接口配置iptables</title>
      <link>https://www.161616.top/firewalld-dbus-interface/</link>
      <pubDate>Thu, 18 Nov 2021 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/firewalld-dbus-interface/</guid>
      <description>firewalld，一个基于动态区的iptables/nftables守护程序，自2009年左右开始开发，CentOS7基于 firewalld-0.6.3 ， 发布于2018年10月11日。主要的开发人员是托马斯·沃纳，他目前为红帽公司工作。这是因为为Federal 18 的默认防火墙机制， 随后在 Rhel7 和 Centos 7 中使用。
firewalld比旧的 iptable 机制有许多优势。值得注意的是，它解决了 iptable 要求每次更改时重新启动防火墙的问题，从而中断了任何状态连接。它还提供了丰富的 D-Bus 方法、信号和属性。
这里并不是从firewalld操作使用方式来介绍firewalld的改名，想反，是介绍firewalld D-Bus API来检索信息或更改设置。
firewalld被配置为系统 D-Bus 服务，注意看 systemd file中的&amp;quot; Type=dbus &amp;ldquo;参数。
text 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 $ cat /usr/lib/systemd/system/firewalld.service [Unit] Description=firewalld - dynamic firewall daemon Before=network-pre.target Wants=network-pre.target After=dbus.service After=polkit.service Conflicts=iptables.service ip6tables.service ebtables.service ipset.</description>
    </item>
    <item>
      <title>firewalld</title>
      <link>https://www.161616.top/firewalld/</link>
      <pubDate>Thu, 02 Mar 2017 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/firewalld/</guid>
      <description>1 firewalld的配置文件 以xml格式为主
bash 1 2 /etc/firewalld/ /usr/lib/firewalld/ 使用时的规则是这样的：当需要一个文件时firewalld会首先到第一个目录中查找，如果找到直接使用，否则会继续到第二个目录中查找。
1.1 配置文件结构 firewalld的配置文件主要有两个文件和三个目录
文件：firewalld.conf、lockdown-whitelist.xml
目录：zone services icmptypes
1.2 firewalld.conf firewalld的主配置文件，不过非常简单，只有五个配置项
defaultzone：默认使用的zone默认public
minimalmark：标记最小值
cleanUpOnExit：退出当前firewalld后是否清除防火墙规则，默认值为yes;
zones
保存zone配置文件
services
保存service配置文件
icmptypes
保存和icmp类型相关的配置文件
2 firewall操作 2.1 查看firewalld状态 bash 1 2 3 4 5 6 7 $ firewall-cmd --state not running $ systemctl start firewalld $ firewall-cmd --state running 2.2 不改变状态的条件下重新加载防火墙 bash 1 firewall-cmd --reload 获取支持的区域列表
bash 1 firewall-cmd --get-zone 获得所有支持的服务
bash 1 2 $ firewall-cmd --get-services RH-Satellite-6 amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxypmwebapi pmwebapis pop3s postgresql proxy-dhcp radius redis rpc-bind samba samba-client smtp ssh telnet tftp tftp-clienttransmission-client vnc-server wbem-https 获取所有支持的ICMP类型</description>
    </item>
    <item>
      <title>ch1 iptables介绍</title>
      <link>https://www.161616.top/ch1-iptables-introduction/</link>
      <pubDate>Sat, 22 Oct 2016 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/ch1-iptables-introduction/</guid>
      <description>1 防火墙实战 关闭两项功能：
selinux（生产中也是关闭的），ids入侵检测，MD5指纹将。系统所有核心文件全部做指纹识别，将指纹留下，将来出问题，一看就知道那个文件被改过。 iptables（生产中看情况，内网关闭，外网打开），大并发的情况，不能开iptables，影响性能。 使用防火墙就不如不使用防火墙，不使用防火墙的前提是不给外网ip，工作中要少给外网服务器ip，这样防火墙使用率较低，防火墙使用也很消耗资源 安全优化：
尽可能不给服务器配置外网IP。可以通过代理转发或者通过防火墙映射。 并发不是特别大情况再外网IP的环境，要开启iptables防火墙 http://edu.51cto.com/course/course_id-772.html
学好iptables基础：
OSI7层模型以及不同层对应那些协议？ TCP/IP三次握手，四次断开的过程，TCP HEADER。 常用的服务端口要了如指掌。 1.1 iptables防火墙简介 Netfilter/iptables(以下简称iptables)是unix/linux自带的一款优秀且开放源代码的完全自由的基于包过滤的防火墙工具，它的功能十分强大，使用非常灵活，可以对流入和流出的服务器数据包进行很精细的控制。特别是他可以在一台非常低的硬件配置下跑的非常好（赛扬500MHZ 64M内存的情况部署网关防火墙）提供400人的上网服务四号==不逊色企业级专业路由器防火墙==。iptables+zebra+squid
iptables是linux2.4及2.6内核中集成的服务。其功能与安全性比其老一辈ipwadin ipchains强大的多（长江水后浪推前浪），iptables主要工作在OSI七层的二、三、四层，如果重新编译内核，iptables也可以支持7层控制（squid代理+iptables）。
1.2 iptables名词和术语 容器：包含或者说属于关系
什么是容器？
​	在iptables里，就是用老描述这种包含或者说属于的关系
什么是Netfilter/iptables?
​	Netfilter是表（tables）的容器
什么是表（tables）？
​	表是链的容器，所有的链（chains）都属于其对应的表。
什么是链（chains）？
​	链（chains）是规则的容器
什么是规则（policy）
​	iptables一系列过滤信息的规范和具体方法条款
iptables抽象和实际比喻对比表| Netfilter | tables | chains | policy || --------- | ---------- | ------------ | -------------------- || 一栋楼 | 楼里的房子 | 房子里的柜子 | 柜子里衣服的摆放规则 |1.3 iptables工作流程 iptables是采用数据包过滤机制工作的，所以他会对请求的数据包包头数据进行分析，并根据我们预先设定的规则进行匹配来决定是否可以进入主机。</description>
    </item>
    <item>
      <title>ch2 iptables命令帮助信息</title>
      <link>https://www.161616.top/ch2-iptables-command/</link>
      <pubDate>Sat, 22 Oct 2016 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/ch2-iptables-command/</guid>
      <description>2 iptables命令帮助信息 有问题查帮助，下面是很全的帮助信息（必须拿下它）
bash 1 $ iptables -h bash 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 $ iptables -nL # INPUT链 ACCEPT默认允许决策 Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 REJECT all -- 0.0.0.0/0 0.</description>
    </item>
    <item>
      <title>ch3 iptables配置防火墙</title>
      <link>https://www.161616.top/ch3-iptables-configuration/</link>
      <pubDate>Sat, 22 Oct 2016 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/ch3-iptables-configuration/</guid>
      <description>生产环境配置主机防火墙有两种模式：
逛公园及看电影两种模式：
逛公园：默认随便出进，对非法的分子进行拒绝。企业应用：企业配置上网网关路由。
看电影：默认没有票进不去。花钱买票才能看电影。企业应用：服务器主机防火墙。
很显然：第二种更严格，更安全。
逛公园及看电影两种模式本事就是防火墙的默认规则是允许还是拒绝。
1.清理当前所有规则和计数器
bash 1 2 3 iptables -F iptables -Z iptables -X 2.配置允许SSH登陆端口进入
bash 1 2 iptables -A INPUT -p tcp --dport 52113 -j ACCEPT iptables -A INPUT -p tcp -s 192.168.1.0/30 -j ACCEPT 提示：此步骤是为了防止执行下面的步骤，把自己关在外面，除非你在本地处理，这部可以不做。
3.设置允许本机lo通讯规则
bash 1 2 iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT # output加不加都行，在工作环境上是加的 4.设置默认的防火墙禁止和允许规则
bash 1 2 3 iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT ACCEPT 一般情况下OUTPUT我们不要drop，像电影院一样，电影已经看完了，中间不想看就回家了，你不可能说不行不能走，所以一般出去没人管，进来才收票，OUTPUT一般不设置，但是不设置也有风险，企业流量暴涨，由于服务器中病毒外发流量。</description>
    </item>
    <item>
      <title>ch4 生产环境如何维护iptables</title>
      <link>https://www.161616.top/ch4-iptables-p/</link>
      <pubDate>Sat, 22 Oct 2016 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/ch4-iptables-p/</guid>
      <description>生产中，一般第一次添加规则命令行或者脚本加入然后一次性保存成文件，然后可以改配置文件管理：
bash 1 2 3 4 5 6 7 8 9 $ cat /etc/sysconfig/iptables # Generated by iptables-save v1.4.7 on Wed Nov 23 09:18:12 2016 *filter :INPUT DROP [0:0] :FORWARD DROP [0:0] :OUTPUT ACCEPT [115:13341] -A INPUT -p tcp -m tcp --dport 52113 -j ACCEPT COMMIT # Completed on Wed Nov 23 09:18:12 2016 生产维护：
⑴ 确定规则
sh 1 2 3 4 5 vim /etc/sysconfig/iptables # 加入想要的规则：例如： -A INPUT -p tcp -m tcp --dport 873 -j ACCEPT /etc/init.</description>
    </item>
    <item>
      <title>ch5 配置网关及服务器地址映射</title>
      <link>https://www.161616.top/ch5-iptables-nat/</link>
      <pubDate>Sat, 22 Oct 2016 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/ch5-iptables-nat/</guid>
      <description>1 办公室路由网关架构图 对应实际企业办公上网场景逻辑图
2.实验环境配置需求前期准备 2.1 服务器网关B需要准备如下条件 物理条件是具备上网卡，建议eth0外网地址（这里是192.168.1.5,gw 192.168.1.2），ech1内网地址（这里是172.168.1.10，内网卡不配GW。 确保服务器网关B要可以上网（B上网才能代理别的机器上网）。可以通过ping baidu.com或外网IP测试。 内核文件/etc/sysctl.conf里开启转发功能。在服务器网关B192.168.1.5机器上开启路由转发功能。编辑/etc/sysctl.conf修改内容为net.ipv4.ip_forward = 1，然后执行sysctl -p使修改生效 iptables的filter表的FORWARD链允许转发 不要filter防火墙功能，共享上网，因此最好暂停防火墙测试/etc/init.d/tables stop 2.2 加载iptables内核模块 配置网关需要iptables的nat表，PREROUTING，POSTROUTING。
(1)载入iptables内核模块，执行并放入rc.local
bash 1 2 3 4 5 6 7 modprobe ip_tables \ modprobe iptable_filter \ modprobe iptable_nat \ modprobe ip_conntrack \ modprobe ip_conntrack_ftp \ modprobe ip_nat_ftp \ modprobe ipt_state bash 1 2 3 $ lsmod|egrep ^ip iptable_nat 6051 0 iptable_filter 2793 0 2.3 局域网的机器： 局域网的机器有一块网卡即可，确保局域网的机器C，默认网关这只了网关服务器B的eth1内网卡IP（172.168l.1.10）。把主机C的gateway设置为B的内网卡192的网卡ip即172.168l.1.10。 检查手段： 分别ping网关服务器B的内外网卡IP，都应该是通的就对了. 出公网检查除了PING网站域名外，也要ping下外网ip，排除DNS故障。不通 ping 10.0.0.254网关也是不通的。 如上，请准备两台虚拟机B和C，其中B要有双网卡。B的内网卡的网段和C的网段一样。</description>
    </item>
    <item>
      <title>ch6 iptables生产应用场景</title>
      <link>https://www.161616.top/ch6-iptables-application/</link>
      <pubDate>Sat, 22 Oct 2016 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/ch6-iptables-application/</guid>
      <description>1、局域网共享上网（适合做企业内部局域网上网网关，以及IDC机房内网的上网网关 nat POSTROUTING）
2、服务器防火墙功能（适合IDC机房具有外网IP服务器，主要是filter INPUT的控制）
3、把外部IP及端口映射到局域网内部（可以一对一IP映射，也可针对某一个端口映射。）
也可能是IDC把网站的外网VIP级网站端口映射到负载均衡器上（硬件防火墙）（NAT PREROUTING）
4、办公路由器+网关功能（zebra路由+iptables过滤及NAT+squid正向透明代理80+ntop/iftop/iptaf流量查看+tc/cbq流量控制限速）。
5、邮件的网关。
问题2：的生产环境应用：用于没有外网地址的内网服务器，映射为公网IP后对外提供服务，也包括端口的映射
问题3：IP一对一映射 用于没有外网地址的内网服务器，映射为公网IP后对外提供服务，例如：ftp服务要一对一IP映射。
共享上网封IP的方法：
bash 1 2 /sbin/iptables -I FROWAED -s 10.0.0.26 -j　DROP /sbin/iptables ${deal} FROWARD -m mac --mac -source ${strIpMac} -j DROP 映射多个外网IP上网 bash 1 2 iptables -t nat -A POSTROUTING -s 10.0.1.0/255.255.240.0 -o eth0 -j SNAT --to-source 124.42.60.11-124.42.60.16 iptables -t nat -A POSTROUTING -s 172.168.1.0/255.255.255.0 -o eth0 -j SNAT --to=source 124.42.60.60-124.42.60.63 问题：公司内网主机多的时候，访问网站容易被封。</description>
    </item>
    <item>
      <title>ch7 关于iptables的内核参数</title>
      <link>https://www.161616.top/ch7-iptables-kernel-parameter/</link>
      <pubDate>Sat, 22 Oct 2016 00:00:00 +0000</pubDate>
      <guid>https://www.161616.top/ch7-iptables-kernel-parameter/</guid>
      <description>调整内核参数文件/etc/sysctl.conf，以下是我们生产环境的某个服务器的配置：
bash 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 # 表示如果套接字由本端要求关闭，这个檀树决定了他保持在FIN-WAIT-2状态的时间。 net.ipv4.tcp_fin_timeout = 2 # 表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接，默认为0，表示关闭。 net.ipv4.tcp_tw_reuse = 1 # 表示开启TCP连接中TIME-WAIT socket的快速收回，默认为0，表示关闭 net.ipv4.tcp_tw_recycle = 1 提示：以上两个参数为了防止生产环境下 time_wait过多设置的。 ############################################################ # 表示开启SYN Cookie。当出现SYN等带队列溢出时，启动cookie来处理，可防范少量SYN攻击，默认为0表示关闭 net.ipv4.tcp_syncookies = 1 # 表示当keepalive起用的时候，TCP发送keepalive消息的频度。缺省是两小时，改为20分钟 单位秒 net.ipv4.tcp_keepalive_time = 1200 # 表示对用向外连接的端口范围。缺省情况下很小。 net.ipv4.ip_local_port_range = 4000 65000 # 表示SYN队列的长度，默认为1024，加大队列长度为8192，可容纳更过等待连接的网络连接数。 net.</description>
    </item>
  </channel>
</rss>
