Configure Linux networking with iptables, DNS, and SSH
✓Works with OpenClaudeYou are a Linux systems administrator. The user wants to configure Linux networking with iptables firewall rules, DNS resolution, and SSH access.
What to check first
- Run
iptables --list --table filterto see current firewall rules - Check
cat /etc/resolv.confto view current DNS configuration - Verify
systemctl status sshdto confirm SSH service is running - Run
ip addr showto identify network interfaces and their IPs
Steps
- Flush existing iptables rules with
iptables --flushandiptables --delete-chainto start clean - Set default policies with
iptables --policy INPUT DROP,OUTPUT ACCEPT,FORWARD DROPto deny by default - Allow loopback traffic:
iptables --append INPUT --in-interface lo --jump ACCEPT - Allow SSH on port 22:
iptables --append INPUT --protocol tcp --dport 22 --jump ACCEPT - Allow established connections:
iptables --append INPUT --match state --state ESTABLISHED,RELATED --jump ACCEPT - Allow HTTP/HTTPS:
iptables --append INPUT --protocol tcp --dport 80 --jump ACCEPTand--dport 443 - Configure DNS by editing
/etc/resolv.confwithnameserver 8.8.8.8andnameserver 8.8.4.4 - Save rules with
iptables-save > /etc/iptables/rules.v4(requires iptables-persistent package) - Restore rules on boot:
systemctl enable iptables-restoreor use netfilter-persistent - Verify SSH key-based authentication in
/etc/ssh/sshd_configwithPubkeyAuthentication yesand restartsystemctl restart sshd
Code
#!/bin/bash
# Linux Networking Configuration Script
# Configures iptables, DNS, and SSH
set -e
# Backup existing iptables rules
iptables-save > /tmp/iptables.backup.$(date +%s)
# Flush all existing rules and chains
iptables --flush
iptables --flush -t nat
iptables --delete-chain
iptables --delete-chain -t nat
# Set default policies
iptables --policy INPUT DROP
iptables --policy FORWARD DROP
iptables --policy OUTPUT ACCEPT
# Allow loopback interface
iptables --append INPUT --in-interface lo --jump ACCEPT
iptables --append OUTPUT --out-interface lo --jump ACCEPT
# Allow established and related connections
iptables --append INPUT --match state --state ESTABLISHED,RELATED --jump ACCEPT
# Allow SSH (port 22)
iptables --append INPUT --protocol tcp --dport 22 --jump ACCEPT
# Allow HTTP (port 80) and HTTPS (port 443)
iptables --append INPUT --protocol tcp
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Linux Skills
Other Claude Code skills in the same category — free to download.
Linux Bash Script
Write Bash scripts with variables, loops, and error handling
Linux Systemd
Create and manage systemd services and timers
Linux Permissions
Manage file permissions, ownership, and ACLs
Linux Process
Monitor and manage processes with ps, top, htop, and signals
Linux Disk
Manage disks, partitions, LVM, and filesystem mounts
Linux systemd Service Setup
Create a production-grade systemd service with logging, restart, and security hardening
Linux Performance Profiling
Find performance bottlenecks on Linux with perf, strace, and bpftrace
Want a Linux skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.