-
Senior Member
registered user
IPtables script, submitted for consideration
--I know next to nothing about iptables, even went thru some HOWTO's and got nothing but mind-boggled. So I googled for "iptables basic protection" and a few other things, and hacked together a basic-protection script with the help of various sources.
--Anyone who knows ins/outs of iptables security, please examine and see if there's anything redundant or useful that can be added.
--Script as supplied is pppoe-centric (ppp0):
o Allows loopback 127.0.0.1
o Allows ping from inside and outside boxes
o Allows bittorrent
o Allows ssh
o Allows squid (port 3128)
o Disallows nmap except from localhost
o Blocks certain known-bad Windows ports.
--So far I haven't tested it yet for VNC or ssh port-forwarding. Bittorrent definitely works tho.
--Note: I had to re-edit and jump thru some hoops for ssh to work properly. First crack at this, my existing ssh session died. Then the existing session stayed, but I couldn't reconnect with a new session. The existing rules are a lot now, but allows ssh to work as you would expect. I'm wondering if I can cut this down a bit tho, and optimize it.
--In this post, I'll put the basic code; the full source with references and comments will go into a reply-topic. TIA.
Code:
#BEGIN basic-prot
#!/bin/sh
iptables -F
iptables -X
iptables -A INPUT -i lo -p all -j ACCEPT
iptables -A OUTPUT -o lo -p all -j ACCEPT
iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p icmp
iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p tcp
iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED -i eth0 -p udp
iptables -A INPUT -p icmp -j ACCEPT
iptables -A INPUT -i ppp0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 22 -j ACCEPT
iptables -A INPUT -p udp --sport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
iptables -A OUTPUT -p udp --sport 22 -j ACCEPT
iptables -A INPUT -i eth0 -p udp --dport 22 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -o eth0 -p udp --dport 22 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s 0/0 -p tcp --dport 8080 -j REJECT
iptables -A INPUT -s 127.0.0.1 -p tcp --dport 3128 -j ACCEPT
iptables -A INPUT -s 10.0.0.0/8 -p tcp --dport 3128 -j ACCEPT
iptables -A INPUT -s 0/0 -p tcp --dport 3128 -j REJECT
iptables -A INPUT -p tcp -s 0/0 -i ppp0 --dport 6881:6889 -j ACCEPT
iptables -A INPUT -p tcp -s 0/0 -i ppp0 --dport 6969 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp --dport 31337 --sport 31337 -j DROP
iptables -A FORWARD -p tcp --sport 137:139 -j DROP
iptables -A FORWARD -p udp --sport 137:139 -j DROP
iptables -A INPUT -s 10.0.0.0/8 -i ppp0 -j DROP
iptables -A INPUT -s 127.0.0.0/8 -i ppp0 -j DROP
iptables -A INPUT -s 172.16.0.0/12 -i ppp0 -j DROP
iptables -A INPUT -s 192.168.0.0/16 -i ppp0 -j DROP
iptables -A INPUT -i ppp0 -s 10.0.0.0/8 -d 0.0.0.0/0 -j DROP
iptables -A INPUT -p tcp -s 0/0 -d 0/0 --dport 1214 -j REJECT
iptables -A INPUT -p tcp -s 0/0 -d 0/0 --dport 139 -j REJECT
iptables -A INPUT -p tcp -s 0/0 -d 0/0 --dport 445 -j REJECT
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -A INPUT -p tcp --tcp-flags ALL SYN -j DROP
Similar Threads
-
By DieselDriver in forum Networking
Replies: 3
Last Post: 03-03-2005, 02:44 PM
-
By Neo-Rio in forum General Support
Replies: 2
Last Post: 04-08-2004, 08:05 AM
-
By zebul666 in forum Ideas
Replies: 4
Last Post: 04-07-2004, 07:00 AM
-
By Markus in forum Networking
Replies: 6
Last Post: 01-24-2004, 07:27 PM
-
By punk000 in forum General Support
Replies: 3
Last Post: 02-26-2003, 07:02 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules

RAM-HOL-SAM60CPU RAM USB-C Powered Dock for Samsung Tab Active5 - 3 - 2
$81.99

Samsung 2.5" 870 EVO SSD SATA III 250GB 500GB 1TB Internet Solid State Drive Lot
$60.00

Genuine Samsung K406S Black Toner Cartridge - New and Sealed Box
$35.99

WiFi Only Samsung Galaxy Tab A9 Plus 11.0" 128GB Black SM-X210
$139.99

Samsung PM961 512GB PCIe Gen 3x4 NVMe 2280 M.2 SSD MZVLW512HMJP-000D1
$60.00

RAM-GDS-SKIN-SAM54-NG-1 RAM Mounts IntelliSkin® Next Gen for Samsung Tab Active4
$93.99

RAM-HOL-SAM52CPU RAM USB-C Powered Dock Samsung Tab Active4 Pro & Tab Active Pro
$81.99

Cell Phone Smartphone Computer repair banner poster sign iphone Samsung
$89.99

NEW Samsung NoteBook NT930QCG touch LCD Full Screen Assembly Blue
$225.77

SAMSUNG FIT PLUS 128GB USB 3.1 Flash Drive - fully working & authentic
$24.95