netxfw provides powerful rule import/export functionality supporting multiple formats for different use cases:
netxfw rule import <type> <file>
| Type | Description | Example |
|---|---|---|
lock/deny |
Import blacklist rules | netxfw rule import lock blacklist.txt |
allow |
Import whitelist rules | netxfw rule import allow whitelist.txt |
rules |
Import IP+Port rules | netxfw rule import rules ipport.txt |
all |
Import all rule types | netxfw rule import all rules.json |
binary |
Import binary format blacklist | netxfw rule import binary rules.deny.bin.zst |
Blacklist/Whitelist Format:
# This is a comment
192.168.1.100
10.0.0.1
2001:db8::1
192.168.1.0/24
IP+Port Rules Format:
192.168.1.100:80:deny
10.0.0.1:443:allow
2001:db8::1:8080:deny
{
"blacklist": [
{"type": "blacklist", "ip": "192.168.1.100"},
{"type": "blacklist", "ip": "10.0.0.1"}
],
"whitelist": [
{"type": "whitelist", "ip": "127.0.0.1"},
{"type": "whitelist", "ip": "10.0.0.0/8"}
],
"ipport": [
{"type": "ipport", "ip": "192.168.1.100", "port": 80, "action": "deny"},
{"type": "ipport", "ip": "10.0.0.1", "port": 443, "action": "allow"}
]
}
type,ip,port,action
blacklist,192.168.1.100,,
whitelist,127.0.0.1,,
ipport,192.168.1.100,80,deny
ipport,10.0.0.1,443,allow
netxfw rule export <file> [--format <format>]
| Format | Description | Usage |
|---|---|---|
json |
JSON format | --format json or file extension .json |
yaml |
YAML format | --format yaml or file extension .yaml/.yml |
csv |
CSV format | --format csv or file extension .csv |
binary |
Binary format | --format binary or file extension .bin.zst |
# Export as JSON format
netxfw rule export rules.json
# Export as YAML format
netxfw rule export rules.yaml --format yaml
# Export as CSV format
netxfw rule export rules.csv --format csv
# Export as Binary format
netxfw rule export rules.deny.bin.zst --format binary
# Auto-detect format (based on file extension)
netxfw rule export rules.json
netxfw rule export rules.yaml
netxfw rule export rules.csv
netxfw rule export rules.deny.bin.zst
| Format | Pros | Cons | Use Cases |
|---|---|---|---|
| Text | Simple, human-readable, easy to edit | Limited functionality, single rule type only | Quick addition of few IPs |
| JSON/YAML | Structured, includes all rule types, readable | Larger file size, slower parsing | Config backup, version control |
| CSV | Tabular format, easy to edit in Excel | Large file size, no complex structure support | Data exchange, reporting |
| Binary | High performance, high compression ratio, fast parsing | Not human-readable, blacklist only | Large-scale rule storage, fast migration |
Use JSON or YAML format for regular backups:
# Regular backup of rules
netxfw rule export /backup/rules-$(date +%Y%m%d).json
Use Binary format for large-scale rule migration:
# Export all blacklist rules
netxfw rule export all-rules.bin.zst --format binary
# Import on another machine
netxfw rule import binary all-rules.bin.zst
Use Text format for batch import:
# Batch import IPs from file
netxfw rule import lock /path/to/blacklist.txt
Use CSV format for data analysis:
# Export as CSV for analysis in Excel
netxfw rule export rules.csv --format csv
sudo# View detailed help
netxfw rule import --help
netxfw rule export --help
# Check import results
netxfw list
# View current status
netxfw status