firewalld 配置 internal 到 public 区域的流量转发
firewalld 支持通过 Policy 对象实现跨区域流量转发。本文介绍如何配置策略,允许 internal 区域的流量转发到 public 区域,使内网主机可以通过防火墙访问外部网络。
前提条件
- firewalld 已安装并运行(
systemctl status firewalld) - 有 root 或 sudo 权限
- 了解 firewalld 的 Zone 和 Policy 概念
firewalld 支持通过 Policy 对象实现跨区域流量转发。本文介绍如何配置策略,允许 internal 区域的流量转发到 public 区域,使内网主机可以通过防火墙访问外部网络。
systemctl status firewalld)VyOS 是一个开源的路由器操作系统,ZeroTier 则是一个易于使用的 SD-WAN 方案。将两者结合,可以用 VyOS 作为各站点的网关设备,通过 ZeroTier 组建虚拟网络,实现站点间的安全通信。
相比传统的 IPsec VPN 或 BGP over WireGuard 方案,ZeroTier 的优势在于:无需公网 IP、无需手动配置隧道对端、通过 Central 控制台统一管理路由。适合中小规模的多站点部署。
本文介绍如何在 Alpine Linux 系统上部署 SmokePing 网络延迟监控工具,使用 Caddy 作为 Web 服务器,FCGIWrap 处理 CGI 脚本。
# 更新软件包索引
apk update
# 安装 SmokePing 及相关组件
apk add fcgiwrap fcgiwrap-openrc caddy smokeping smokeping-openrc
# 创建 fcgiwrap 服务用户
useradd -r fcgiwrap-openrc
# 创建 SmokePing 数据目录
mkdir -p /var/lib/smokeping/Ping
mkdir -p /var/lib/smokeping/DNS
# 设置权限
chown smokeping:smokeping /var/lib/smokeping/Ping
chown smokeping:smokeping /var/lib/smokeping/DNS
chmod 777 /var/lib/smokeping/images/Ping
chmod 777 /var/lib/smokeping/images/DNS
创建 Caddy 配置文件 /etc/caddy/Caddyfile:
{
log {
output file /var/log/caddy/access.log {
roll_size 100MB # 单个日志文件最大 100MB
roll_keep 10 # 保留最近 10 个日志文件
roll_keep_for 720h # 保留 30 天(720 小时)
}
format console # 易读的格式,也可改用 json 格式(format json)
}
}
http://192.168.1.100 {
# 处理静态资源
handle /js/* {
root * /usr/share/webapps/smokeping/
file_server
}
handle /css/* {
root * /usr/share/webapps/smokeping/
file_server
}
handle /imgcache/* {
root * /usr/share/webapps/smokeping/
file_server
}
handle_path /images/* {
root * /var/lib/smokeping/images
file_server browse
}
# 处理 CGI 请求
handle {
root * /usr/share/webapps/smokeping/
reverse_proxy unix//run/fcgiwrap/fcgiwrap.sock {
transport fastcgi {
env SCRIPT_FILENAME /usr/share/webapps/smokeping/smokeping.cgi
split ""
}
}
}
}
Gitea 是一个轻量级的自托管 Git 服务,采用 Go 语言编写,是 GitHub 和 GitLab 的轻量替代方案。它提供了完整的代码托管功能,包括 Issues、Pull Requests、Wiki、CI/CD 等,同时保持了极低的资源占用。
| 特性 | Gitea | GitLab | GitHub |
|---|---|---|---|
| 资源占用 | 极低(100MB RAM) | 高(2GB+ RAM) | SaaS |
| 部署复杂度 | 简单 | 复杂 | 无需部署 |
| 数据控制 | 完全自控 | 完全自控 | 依赖第三方 |
| 国内访问 | 可部署内网 | 可部署内网 | 需代理 |
Route-Map 是 FRR (FRRouting) 的路由策略工具,用于控制 OSPF 路由的发布和接收。通过 Route-Map,可以实现:
Route-Map 由一条或多条 sequence 组成,每个 sequence 有:
permit(允许)或 deny(拒绝)Route-Map 按序列号从小到大依次执行:
| 匹配类型 | 说明 | 示例 |
|---|---|---|
ip address |
匹配 IP 地址/前缀 | match ip address prefix-list LIST |
interface |
匹配出接口 | match interface eth0 |
metric |
匹配路由开销 | match metric 100 |
protocol |
匹配路由协议类型 | match protocol ospf |
next-hop |
匹配下一跳地址 | match ip next-hop A.B.C.D |
tag |
匹配路由标签 | match tag 100 |
as-path |
匹配 AS 路径(BGP) | match as-path 100 |
ospf - OSPF 路由static - 静态路由connected - 直连路由kernel - 内核路由rip - RIP 路由bgp - BGP 路由isis - IS-IS 路由pim - PIM 路由本文记录了将 Netbox 从旧环境迁移到 k3s 集群的过程。
使用 pg_dump 导出 Netbox 数据库,排除变更日志表以减小备份体积:
pg_dump --username netbox --password --host localhost --exclude-table-data=extras_objectchange netbox > netbox.sql
为了避免 Pod 竞争和锁定问题,先删除现有的 Netbox Pod:
kubectl delete po netbox-68cbd8b854-2hvgp
# 进入 PostgreSQL Pod
kubectl exec -it netbox-postgresql-0 -- sed -ibak 's/^\([^#]*\)md5/\1trust/g' /opt/bitnami/postgresql/conf/pg_hba.conf
# 重新加载配置
kubectl exec -it netbox-postgresql-0 -- pg_ctl reload
kubectl exec -it netbox-postgresql-0 -- psql -U postgres
DROP DATABASE netbox;
CREATE DATABASE netbox;
ALTER USER netbox WITH PASSWORD 'balabalabala';
ALTER DATABASE netbox OWNER TO netbox;
-- PostgreSQL 15 及以上版本需要
\connect netbox;
GRANT CREATE ON SCHEMA public TO netbox;
kubectl exec -it netbox-postgresql-0 -- sed -i 's/^\([^#]*\)trust/\1md5/g' /opt/bitnami/postgresql/conf/pg_hba.conf
kubectl exec -it netbox-postgresql-0 -- pg_ctl reload
kubectl exec -it netbox-postgresql-0 -- sh -c "PGPASSWORD=balabalabala psql -U netbox -d netbox < /tmp/netbox.sql"
wget可以通过--content-disposition参数使用HTTP响应头中的Content-Disposition字段来设置下载文件的文件名。
wget [--no-check-certificate] --content-disposition 'url'
Content-Disposition是HTTP响应头中的一个字段,用于指示如何处理响应内容。当服务器希望浏览器下载文件而不是显示时,会使用这个字段。
常见的格式:
Content-Disposition: attachment; filename="example.pdf"
Content-Disposition: attachment; filename*=UTF-8''%E4%BE%8B%E5%AD%90.pdf
--content-disposition: 启用对Content-Disposition头的支持--no-check-certificate: 跳过SSL证书验证(可选,用于自签名证书)当下载链接指向动态生成的文件时,服务器会通过Content-Disposition指定正确的文件名:
wget --content-disposition "https://example.com/download.php?id=123"
对于包含中文字符的文件名,Content-Disposition可能会使用URL编码:
wget --content-disposition "https://example.com/中文文件.pdf"
wget会自动处理URL编码的文件名。
结合其他参数使用:
# 后台下载,使用Content-Disposition文件名
wget -b --content-disposition "https://example.com/file.zip"
# 限制下载速度,使用Content-Disposition文件名
wget --limit-rate=100k --content-disposition "https://example.com/large-file.iso"
pip-audit 是 PyPA(Python Packaging Authority)维护的依赖安全扫描工具,用于检查 Python 环境和依赖文件中是否存在已知漏洞。数据来源是 Python Packaging Advisory Database,通过 PyPI JSON API 或 OSV 查询。
和 npm audit 类似,但 pip 本身没有内置 audit 功能,pip-audit 填补了这个空缺。
pip install pip-audit
需要 Python 3.10+。也支持 conda 安装:
conda install -c conda-forge pip-audit
扫描当前环境
pip-audit
直接扫描当前虚拟环境中安装的所有包,输出有漏洞的包及 CVE 编号。
扫描 requirements 文件
pip-audit -r requirements.txt
扫描项目路径
pip-audit /path/to/project
会自动识别项目中的依赖文件(requirements.txt、pyproject.toml、setup.cfg 等)。
扫描 lock 文件
pip-audit --locked /path/to/project
Netmiko 是一个基于 Paramiko 的 Python 库,专门用于简化网络设备的 SSH 管理。它支持 Cisco、Juniper、Arista、HP、华为、Fortinet 等 100+ 平台,提供统一的 API 接口,让网络工程师可以用一套代码管理不同厂商的设备。
pip install netmiko
from netmiko import ConnectHandler
device = {
'device_type': 'cisco_xe',
'host': '192.168.1.1',
'username': 'admin',
'password': 'password',
}
net_connect = ConnectHandler(**device)
print(net_connect.find_prompt()) # 输出: cisco5#
device_type 指定设备厂商和型号,常见值包括:
| device_type | 厂商/平台 |
|---|---|
| cisco_ios | Cisco IOS |
| cisco_xe | Cisco IOS XE |
| cisco_nxos | Cisco NX-OS |
| juniper_junos | Juniper JunOS |
| arista_eos | Arista EOS |
| huawei | 华为 |
| hp_comware | H3C Comware |
| fortinet | Fortinet |
output = net_connect.send_command('show ip arp')
print(output)
Netmiko 会自动处理输出分页(terminal length 0),并去除命令回显和提示符,只返回纯净的命令输出。
对于耗时较长的命令,可以指定超时时间:
output = net_connect.send_command('show tech-support', delay_factor=5, max_loops=500)
config_commands = [
'interface GigabitEthernet0/1',
'description Uplink-to-Core',
'ip address 10.0.0.1 255.255.255.0',
'no shutdown',
]
output = net_connect.send_config_set(config_commands)
print(output)
# 保存配置
net_connect.save_config()
send_config_set() 会自动进入配置模式、逐条执行命令、退出配置模式。
from netmiko import ConnectHandler
devices = [
{'device_type': 'cisco_xe', 'host': '192.168.1.1', 'username': 'admin', 'password': 'pass1'},
{'device_type': 'cisco_xe', 'host': '192.168.1.2', 'username': 'admin', 'password': 'pass2'},
{'device_type': 'cisco_xe', 'host': '192.168.1.3', 'username': 'admin', 'password': 'pass3'},
]
for device in devices:
try:
conn = ConnectHandler(**device)
output = conn.send_command('show version')
print(f'{device["host"]}: {output[:100]}...')
conn.disconnect()
except Exception as e:
print(f'{device["host"]}: 连接失败 - {e}')
Netbox升级到4.4版本后,打开Racks视图,发现页面空白。打开页面控制台发现报错oobErrorNoTarget.查询资料发现,问题在于新引入的"HTMX Navigation"功能。临时方案为:打开用户设置,“HTMX Navigation"选项选择"Disabled”
sed 's/[[:blank:]]\{2,\}/\t/g' config
以下是几个常用的在线文件共享服务,可用于快速分享文件给他人: