LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-14-2011, 10:37 AM   #1
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,199

Rep: Reputation: 47
comments on iptables


Kindly comment on the following iptable rules which I think may be useful for me since I need to only use web browser for my net connection.


iptables --policy INPUT DROP
iptables --policy OUTPUT DROP
iptables --policy FORWARD DROP
iptables -t nat --policy PREROUTING ACCEPT
iptables -t nat --policy OUTPUT ACCEPT
iptables -t nat --policy POSTROUTING ACCEPT
iptables -t mangle --policy PREROUTING ACCEPT
iptables -t mangle --policy OUTPUT ACCEPT
iptables -t mangle --policy INPUT ACCEPT
iptables -t mangle --policy FORWARD DROP
iptables -t mangle --policy POSTROUTING ACCEPT
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -j DROP
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -j DROP
iptables -A FORWARD -j DROP
 
Old 09-15-2011, 03:44 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Hello,

Let me ask you this - Does it work as advertised for you? To me, it looks good, but I don't know what the full desired output is. Overall, yes it looks good, but you need to be happy with the configuration. If it works, then it works!

Cheers,

Josh
 
1 members found this post helpful.
Old 09-15-2011, 06:41 AM   #3
slimm609
Member
 
Registered: May 2007
Location: Chas, SC
Distribution: slackware, gentoo, fedora, LFS, sidewinder G2, solaris, FreeBSD, RHEL, SUSE, Backtrack
Posts: 430

Rep: Reputation: 67
Quote:
Originally Posted by rng View Post
iptables -A OUTPUT -j DROP
iptables -A FORWARD -j DROP


you don't need the last 2 lines because you set the default policy at the beginning to drop. They wont hurt anything but they are also not doing anything
 
Old 09-15-2011, 07:14 AM   #4
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,199

Original Poster
Rep: Reputation: 47
Will these iptables rules prevent programs installed on my system from communicating data or info across the net? If not, what rules can be added to prevent that and allow only firefox to connect to the network?
Can there be a script having a combination of netstat and iptables commands which can do this?
 
Old 10-03-2011, 07:30 AM   #5
goossen
Member
 
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224

Rep: Reputation: 41
You don't need the following lines because the packets will be dropped by the default policy (which BTW, is not a good idea to use)

Code:
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP
iptables -A FORWARD -j DROP
And you will need the return of the DNS
Code:
iptables -A INPUT -p udp --sport 53 -j ACCEPT
Now, why is not a good idea to use default policy drop:

Lets say you are working remotely and flush the iptables rules (which is not a good idea either, but its not uncommon), your server will be inaccessible immediately. All the packets will be dropped since they match the default policy in the chain. And you will need physical access to the machine to solve the problem.
It's better to explicitly drop everything at the bottom of every chain.
 
Old 10-04-2011, 10:30 AM   #6
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally Posted by goossen View Post
And you will need the return of the DNS
Code:
iptables -A INPUT -p udp --sport 53 -j ACCEPT
There's already a rule in there for packets in state ESTABLISHED, so it's all good. Sending UDP packets with source port 53 to ACCEPT would open up a giant hole in the firewall, as all a bad guy would need to do in order to get his UDP packets through is set source port 53 on them (destination port could be anything). So, I'd say stay away from these types of rules.

Last edited by win32sux; 10-04-2011 at 10:31 AM.
 
1 members found this post helpful.
Old 10-05-2011, 06:38 AM   #7
goossen
Member
 
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224

Rep: Reputation: 41
You are right win32sux, my bad. Thanks for pointing!
 
Old 10-05-2011, 11:41 AM   #8
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,199

Original Poster
Rep: Reputation: 47
Thanks for your replies. I am using ubuntu at two computers. The above script works well at my home computer where I connect directly to the internet (through wired adsl modem) but at my office computer where the internet access is through institutional LAN proxy (I have entered proxy details in browser), it works for a minute or so and then stops. On the other hand, if I use ufw firewall with 'default deny' options, it works perfectly. Where could be the fault in my script?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 error in android: iptables-save and iptables-restore not working preetb123 Linux - Mobile 5 04-11-2011 01:56 PM
any comments coolb General 1 10-13-2007 02:47 PM
FC6 need comments on my iptables please. gimmee Fedora 7 07-02-2007 07:34 AM
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
Comments request for "O'Reilly's Linux iptables Pocket Reference" carboncopy General 3 03-03-2005 09:24 PM

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

All times are GMT -5. The time now is 04:44 AM.

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