Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux HostsFree MagazinesJobs
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Networking
Reload this Page Iptables & Squid
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Networking Hardware/Software related, Modems, Internet connection sharing, IPTables etc.

Reply
 
Thread Tools Display Modes
Old 07-24-2008   #1 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 3
Iptables & Squid

I'm using iptables to calculate the amount of transferred data are using on a monthly basis. When my users go over a certain amount of bytes, I add a firewall rule which prevent them of accessing the internet. That's working great.

At this point, however, I would like to incorporate Squid, so all website from my users are cached in the proxy. I tried altering my script, but haven't succeeded yet.

Now I'm facing two problems: either the clients cannot surf the web or squid isn't used to cache. Plus when I do the math and calculate the exact amount of data went through the firewall, this is not correct.

This is my script:
PHP Code:
#!/bin/sh  
# squid server IP  
SQUID_SERVER="192.168.0.100\"  
# Interface connected to Internet  
INTERNET=\"eth0\"  
# Interface connected to LAN  
LAN_IN=\"eth1\"  
# Squid port  
SQUID_PORT=\"3128\"  

# Clean old firewall  
iptables -F  
iptables -Z  
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_tables  
modprobe iptable_nat  
modprobe ip_nat_irc  
modprobe ip_conntrack  
modprobe ip_conntrack_ftp  
modprobe ip_nat_ftp  

echo \"Done loading modules...\\n\"  

echo \" Enabling forwarding..\"  
echo 1 > /proc/sys/net/ipv4/ip_forward  

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

iptables -N accounting-in  
iptables -N accounting-out  

iptables -A FORWARD -i $INTERNET -o $LAN_IN -j accounting-in  

iptables -A FORWARD -i $LAN_IN -o $INTERNET -j accounting-out  

iptables -A accounting-out -s 192.168.0.101 -m mac --mac-source 00:19:B9:52:46:4A -j RETURN  
iptables -A accounting-out -s 192.168.0.102 -m mac --mac-source 00:90:4B:B0:01:A6 -j RETURN  

iptables -A accounting-out -j LOG --log-prefix \"Unknown mac:\" --log-ip-options  
iptables -A accounting-out -j REJECT  

iptables -A accounting-in -d 192.168.0.101 -j RETURN  
iptables -A accounting-in -d 192.168.0.102 -j RETURN  

iptables -A accounting-in -j LOG --log-prefix \"Unknown ip: \" --log-ip-options  
iptables -A accounting-in -j DROP  

iptables -t nat -A PREROUTING -i $INTERNET -p tcp --dport 80 -j REDIRECT --to-port 3128 
iptables -t nat -A POSTROUTING -o $INTERNET -j MASQUERADE 
Can someone help? Thx
flokky is offline   Reply With Quote
Old 07-24-2008   #2 (permalink)
Linux Enthusiast
 
Lazydog's Avatar
 
Join Date: Jun 2004
Location: Pennsylvania
Posts: 516
You have a default policy for INPUT and OUTPUT but none for FORWARD.

You have your forwards dropping to a sub chain and then returning.
What is IPTABLES doing with them once they are returned?
Instead of RETURN try replacing with ACCEPT?
__________________

Regards
Robert

It is not just an adventure.
It is my job!!

Linux User #296285
Get Counted
Lazydog is offline   Reply With Quote
Old 07-24-2008   #3 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 3
Quote:
Originally Posted by Lazydog View Post
You have a default policy for INPUT and OUTPUT but none for FORWARD.

You have your forwards dropping to a sub chain and then returning.
What is IPTABLES doing with them once they are returned?
Instead of RETURN try replacing with ACCEPT?
Hi Lazydog, thanks for trying to help me out!

First of all: I've added a default policy for FORWARD like this:
PHP Code:
iptables -P FORWARD ACCEPT 
I tried changing the sub-chains of FORWARD (accounting-in and accounting-out) with ACCEPT instead of RETURN, but cannot see any difference. Like this:

PHP Code:
iptables -A accounting-out -s 192.168.0.101 -m mac --mac-source 00:19:B9:52:46:4A -j ACCEPT
iptables 
-A accounting-in -d 192.168.0.101 -j ACCEPT 
At the moment the behaviour looks a bit like this: all html-traffic looks to be accounted for when doing 'iptables -L -vxn'. When firing up Youtube and start to viewing a movie, that isn't accounted for. BUT when I look at the Squid cache (parsed by LightSquid), all traffic which has been generated by the clients, looks OK. So basically, the amount of bytes isn't correct when doing 'iptables -L -vxn', which I parse to feed the database.

Do you have other thoughts?
Thx
flokky is offline   Reply With Quote
Old 07-24-2008   #4 (permalink)
Linux Enthusiast
 
Lazydog's Avatar
 
Join Date: Jun 2004
Location: Pennsylvania
Posts: 516
Maybe you should fine a way to use squid instead of iptables for this.
Isn't there some sort of metering/limit you can set in squid?
I don't use it so I don't know.
__________________

Regards
Robert

It is not just an adventure.
It is my job!!

Linux User #296285
Get Counted
Lazydog is offline   Reply With Quote
Old 07-25-2008   #5 (permalink)
Just Joined!
 
Join Date: Jul 2008
Posts: 3
Doesn't anyone has experience with this?
flokky is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
 

Free Magazines
Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe
Systems Management News, the newspaper for IT systems administration and data center managers!
Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe
The Enterprise Newsweekly
eWeek is the essential technology information source for builders of e-business.
subscribe
Oracle Magazine
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe
Total Telecom
Total Telecom is "The Economist of the communications industry".
subscribe
More free magazines »



All times are GMT. The time now is 03:45 PM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.2.0