Step 1:安装和配置防火墙
- 安装防火墙:确保你的操作系统(Windows 1/11/12,MacOS 12,Linux)已经安装了防火墙工具(如Nginx、OpenVPN等)。
- 打开防火墙:在Python shell或命令提示符中,运行以下命令:
python -c "import nft; nft.set_context('default')"这会启用默认的防火墙设置。
Step 2:设置翻墙策略
-
启用翻墙策略:
- 在Python中,设置防火墙策略为“默认”:
python -c "import nft; nft.set_context('default')" - 在命令提示符中,运行:
nft configure --default-port-eth 8 --default-port-dport 443
这表示设置ethPort为8,dPort为443,即使用HTTP和HTTPS协议。
- 在Python中,设置防火墙策略为“默认”:
-
启用防火墙翻墙策略:
- 在Python中,启用翻墙策略为“默认”:
python -c "import nft; nft.set_context('default')" - 在命令提示符中,运行:
nft configure --default-port-eth 8 --default-port-dport 443 nft configure --default-port-eth 443 --default-port-dport 8
- 在Python中,启用翻墙策略为“默认”:
-
启用日志监控:
- 在Python中,启用日志监控:
python -c "import nft; nft.configure(['default'], ['default'], ['default log'])"
- 在命令提示符中,运行:
nft configure --default-port-eth 8 --default-port-dport 443 nft configure --default-port-eth 443 --default-port-dport 8 nft configure --default-port-eth 8 --default-port-dport 443 nft configure --default-port-eth 443 --default-port-dport 8 nft configure --default-port-eth 8 --default-port-dport 443
这会添加日志记录。
- 在Python中,启用日志监控:
Step 3:设置防火墙端口
- 设置特定端口:
- 使用以下命令设置ethPort端口为8:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'eth', 8])"
- 在命令提示符中,运行:
nft configure --default-port-eth 8
- 使用以下命令设置ethPort端口为8:
- 设置dPort端口:
- 如果需要,设置dPort端口为443:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'dport', 443])"
- 在命令提示符中,运行:
nft configure --default-port-dport 443
- 如果需要,设置dPort端口为443:
- 设置IP地址:
- 如果需要,设置默认IP地址:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'eth', 8], ['default', 'dport', 443], ['default ip', 'eth', 8])"
- 在命令提示符中,运行:
nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8
- 如果需要,设置默认IP地址:
Step 4:配置防火墙规则
-
启用防火墙翻墙策略:
- 在Python中,启用翻墙策略为“默认”:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'eth', 8], ['default', 'dport', 443], ['default ip', 'eth', 8])"
- 在命令提示符中,运行:
nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8
- 在Python中,启用翻墙策略为“默认”:
-
设置防火墙翻墙规则:
- 如果需要,设置特定IP地址的防火墙翻墙规则:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'eth', 8], ['default', 'dport', 443], ['default ip', 'eth', 8])"
- 在命令提示符中,运行:
nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8
- 如果需要,设置特定IP地址的防火墙翻墙规则:
Step 5:设置防火墙的权限
-
启用权限:
- 在Python中,启用权限为“默认”:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'eth', 8])"
- 在命令提示符中,运行:
nft configure --default-port-eth 8
- 在Python中,启用权限为“默认”:
-
设置特定IP地址的权限:
- 如果需要,设置ethPort IP地址的权限为“firewall”:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'eth', 8])"
- 在命令提示符中,运行:
nft configure --default-port-eth 8
- 如果需要,设置ethPort IP地址的权限为“firewall”:
Step 6:配置防火墙的日志
-
启用日志监控:
- 在Python中,启用日志监控为“默认”:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'eth', 8], ['default', 'dport', 443], ['default ip', 'eth', 8], ['default log'])"
- 在命令提示符中,运行:
nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8
- 在Python中,启用日志监控为“默认”:
-
设置日志的记录类型:
- 如果需要,设置日志的记录类型为“admin”:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'eth', 8], ['default', 'dport', 443], ['default ip', 'eth', 8], ['default log'], ['default log admin'])"
- 在命令提示符中,运行:
nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8 nft configure --default-port-dport 443 nft configure --default-port-eth 8
- 如果需要,设置日志的记录类型为“admin”:
Step 7:管理防火墙
-
管理默认防火墙账号:
- 在Python中,管理默认防火墙账号:
python -c "import nft; nft.configure(['default'], ['default', 'admin'])"
- 在命令提示符中,运行:
nft configure --default-adm
- 在Python中,管理默认防火墙账号:
-
管理防火墙端口规则:
- 如果需要,修改特定端口的防火墙翻墙规则:
python -c "import nft; nft.configure(['default'], ['default'], ['default', 'eth', 8], ['default', 'dport', 443],
- 如果需要,修改特定端口的防火墙翻墙规则:




