LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-31-2010, 09:50 PM   #1
packets
Member
 
Registered: Oct 2005
Posts: 339

Rep: Reputation: 32
help in iptables commands


I've setup a machine that will act as a gateway and installed squid for proxying.

However, can someone lead me how to disable all ports except for port 80 for those clients who has 10.0.1.x network. I tried to put iptables -t nat -A PREROUTING -i $LAN_IN -p tcp -j DROP after iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$SQUID_PORT but still I can do p2p,bittorrent and other apps that don't rely on port 80. I also change iptables -A INPUT -i $LAN_IN -j ACCEPT to iptables -A INPUT -i $LAN_IN -j DROP but still the same.

Quote:
#!/bin/sh
# squid server IP
SQUID_SERVER="10.0.1.210"
# Interface connected to Internet
INTERNET="eth0"
# Interface connected to LAN
LAN_IN="eth1"
# Squid port
SQUID_PORT="8080"
UNIVERSE="0.0.0.0/0"
EXT_IPADDR="1.2.3.4"
UNPRIVPORTS="1024:65535"

# DO NOT MODIFY BELOW
# Clean old firewall
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X

# Load IPTABLES modules for NAT and IP conntrack support
modprobe ip_conntrack
modprobe ip_conntrack_ftp

# For win xp ftp client
#modprobe ip_nat_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward

# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT

# Unlimited access to loop back
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Allow UDP, DNS and Passive FTP
iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT

# set this system as a router for Rest of LAN
iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE
iptables --append FORWARD --in-interface $LAN_IN -j ACCEPT

# DNAT port 80 request comming from LAN systems to squid 3128 ($SQUID_PORT) aka transparent proxy
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$SQUID_PORT


# unlimited access to LAN
iptables -A INPUT -i $LAN_IN -j ACCEPT
iptables -A OUTPUT -o $LAN_IN -j ACCEPT

# DROP everything and Log it
iptables -A INPUT -j DROP
 
Old 05-31-2010, 09:57 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by packets View Post
how to disable all ports except for port 80 for those clients who has 10.0.1.x network.
Example:
Code:
iptables -A FORWARD -p TCP -i eth1 --dport ! 80 -s 10.0.1.0/24 -j REJECT
This would need to replace the FORWARD rule you've got there currently.
 
Old 05-31-2010, 10:15 PM   #3
packets
Member
 
Registered: Oct 2005
Posts: 339

Original Poster
Rep: Reputation: 32
Quote:
iptables -A FORWARD -p TCP -i eth1 --dport ! 80 -s 10.0.1.0/24 -j REJECT
It works. I'm now modifying it for certain ip address exemption.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables commands problem naaman Linux - Security 6 02-23-2010 02:20 AM
iptables commands sujitkale Linux - Networking 5 09-25-2007 01:42 PM
incorrect iptables commands? devel Linux - Networking 3 06-02-2005 09:35 PM
iptables save commands are not working tarheel92x Linux - Networking 1 01-19-2004 05:16 PM
iptables commands downlaw Linux - Networking 3 06-09-2003 01:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration