Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-14-2011, 10:37 AM
|
#1
|
Senior Member
Registered: Aug 2011
Posts: 1,199
Rep:
|
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
|
|
|
09-15-2011, 03:44 AM
|
#2
|
LQ Guru
Registered: Apr 2005
Location: /dev/null
Posts: 5,818
|
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.
|
09-15-2011, 06:41 AM
|
#3
|
Member
Registered: May 2007
Location: Chas, SC
Distribution: slackware, gentoo, fedora, LFS, sidewinder G2, solaris, FreeBSD, RHEL, SUSE, Backtrack
Posts: 430
Rep:
|
Quote:
Originally Posted by rng
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
|
|
|
09-15-2011, 07:14 AM
|
#4
|
Senior Member
Registered: Aug 2011
Posts: 1,199
Original Poster
Rep:
|
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?
|
|
|
10-03-2011, 07:30 AM
|
#5
|
Member
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224
Rep:
|
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.
|
|
|
10-04-2011, 10:30 AM
|
#6
|
LQ Guru
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870
|
Quote:
Originally Posted by goossen
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.
|
10-05-2011, 06:38 AM
|
#7
|
Member
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224
Rep:
|
You are right win32sux, my bad. Thanks for pointing!
|
|
|
10-05-2011, 11:41 AM
|
#8
|
Senior Member
Registered: Aug 2011
Posts: 1,199
Original Poster
Rep:
|
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?
|
|
|
All times are GMT -5. The time now is 04:44 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|