Why Firewall Configuration is Required
The Kernel Interference Problem
When paqet receives packets on its configured port, two things happen:- paqet receives a copy via pcap directly from the network driver
- The kernel also sees the packet as it passes through the normal TCP/IP stack
- Corruption of connection state in NAT devices
- Stateful firewall interference
- Connection instability and packet drops
- Premature connection termination
The Solution
You must configureiptables to:
- Bypass connection tracking for the paqet port
- Prevent RST packet generation by the kernel
Port Selection Guidelines
Recommended ports:9999- Common choice for paqet8888- Alternative high port7777- Another high port option- Any non-standard port above 1024
Server Firewall Configuration
Set Your Port Number
Replace
<PORT> in all commands below with your actual server listen port (e.g., 9999).For convenience, set it as a variable:Bypass Connection Tracking
These rules tell the kernel’s netfilter to ignore packets on the paqet port for state tracking:What this does:
-t raw- Uses the raw table (processed before connection tracking)PREROUTING- Incoming packetsOUTPUT- Outgoing packets--dport/--sport- Matches destination/source portNOTRACK- Disables connection tracking for these packets
Prevent RST Packet Generation
This rule drops any RST packets the kernel tries to send from the paqet port:What this does:
-t mangle- Uses the mangle table for packet alteration--tcp-flags RST RST- Matches packets with RST flag setDROP- Discards the packet before it’s sent
Alternative Rules (If Issues Persist)
If you still experience connection issues, try these alternative accept rules:These rules explicitly accept traffic on the paqet port, which can help in some firewall configurations.
Complete Example
Here’s a complete script to configure iptables for paqet on port 9999:configure-iptables.sh, make it executable, and run:
Cloud Provider Firewalls
In addition to iptables, cloud providers have their own firewall systems:- AWS
- Google Cloud
- Azure
- DigitalOcean
Security Groups:
- Go to EC2 → Security Groups
- Select your instance’s security group
- Add an inbound rule:
- Type: Custom TCP
- Protocol: TCP
- Port Range: 9999 (your paqet port)
- Source: Your client IP or 0.0.0.0/0 for any source
Removing Rules
To remove paqet iptables rules:Troubleshooting
Connection Times Out
-
Verify iptables rules are applied:
-
Check for conflicting rules:
Look for DROP or REJECT rules that might block your port.
- Verify cloud provider firewall: Ensure your security group/firewall allows TCP traffic on your port.
Rules Not Persisting
-
Check if iptables-persistent is installed:
-
Manually verify saved rules:
Server Can’t Make Outbound Connections
This happens if you used a standard port like 80 or 443:- Change your paqet port to a non-standard port (e.g., 9999)
- Remove old iptables rules for the standard port
- Re-apply rules with the new port
- Update your configuration files (both client and server)