URN Logo
UNIX Resources » Linux » Linux Forum » Linux Security » Page.3 » Iptables Problems: Keep Open Only Some Ports
announcement The content of this page is collected from Linux Forum, All copyrights and other associated rights are reserved by the original authors of the articles.
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.com
  LinuxForum General Chat
  Linux Advocacy
  LinuxForum Polls
  Introductions
  Linux Kernel Support
  Patch Management
  Development Release
  Linux Programming
  Linux Security
  Linux Software
  Linux Hardware Problems
    Linux Video Problems
    Linux Sound Problems
  Linux Networking Support
  Linux Printing Support
  Linux Human Interface Devices Support
  Linux Data Storage Support
  Linux Applications Support
  Linux Installation Support
  Linux Laptops Support
  Linux Motherboard, Chipsets, CPU, Memory
  Miscellaneous
  Debian Linux Support
  Ubuntu Linux Support
  LiveCD Discussions
  Gentoo Linux Support
  Mandrake Linux Support
  Redhat / Fedora Linux Support
  Slackware Linux Support
  SuSE Linux Support
  CentOS Linux Support
  Linux Web Servers
  Linux DNS Servers
  Linux Database Servers
  Linux Email Servers
  Linux FTP Servers
  Linux Squid Proxy Server
  Linux Samba Help
  Linux cPanel Help
  Linux Ensim Help
  Linux Plesk Help
  Linux Webmin / Usermin Help
  Qmail Toaster Help
  Linux Games
  Windows Game Emulation
  Linux Discussions
  General Linux Discussions
  Red Hat Linux Discussions
  More Red Hat Linux Discussions
  Mandrake Linux Discussions
  Slackware Linux Discussions
  SuSE Linux Discussions
  Debian Discussions
  Samba Help
  Linux Security
  Linux Networking
  Gentoo Help
  Operating System Rant Forum
  Hardware Rants
   
Iptables Problems: Keep Open Only Some Ports
Subject: Iptables Problems: Keep Open Only Some Ports
Author: decola    Posted: 2006-01-30 08:29:49    Length: 1,465 byte(s)
[Original] [Print] [Top]
Hi all!
My distro is Debian Stable 3.1.
I've set this script (/etc/rc2.d/S97iptables) on my home PC inserting some iptables rules.

#!/bin/sh

#drop all rules
/sbin/iptables -F

#drop default rules
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT DROP
/sbin/iptables -P FORWARD DROP

#close all ports in input
iptables -A INPUT -i eth0 -m state --state NEW,INVALID -j DROP
iptables -A FORWARD -i eth0 -m state --state NEW,INVALID -j DROP

#open some ports in input
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
iptables -A INPUT -p udp --dport 53 -m state --state NEW -j ACCEPT

But I have some problems. I can't connect to any port of this computer from other computers of my net.
When I launch halt, PC stops all services but it doesn't switch off...it remain freezed on last system messages.

So I think the problem is that my rules don't allow pinging to the PC. In fact if I launch locally ping or nmap, "Operation not permitted" is shown.
So I add the rule below:
iptables -A INPUT -p icmp -m state --state NEW -j ACCEPT
or:
iptables -A INPUT -p icmp -j ACCEPT

but all problems remain.

where's the mistake?

Thanks in advance.

 
[Original] [Print] [Top]
Subject: Iptables Problems: Keep Open Only Some Ports
Author: mark_bj    Posted: 2006-02-05 09:06:02    Length: 83 byte(s)
[Original] [Print] [Top]
I have a experience that, you can reset the ipv4_forward to 1 . Hope can help you.
[Original] [Print] [Top]
Subject: Iptables Problems: Keep Open Only Some Ports
Author: pa4wdh    Posted: 2006-02-05 09:45:13    Length: 1,768 byte(s)
[Original] [Print] [Top]
Hi,

As far as the nmap issue: Some options require root privileges, so that might be the problem, however, ping should work (inless you do a broadcast or flood ping).

Assuming the eth0 interface is the one connected to the internet, your rules seem a bit strange.

First you disallow NEW and INVALID packets (which is not bad), but after that you drop the packet anyway (the -P setting).

If eth0 is your internet interface, i allways use:
iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -j DROP

This gives the same result as what you want to do (at least i think), with the difference that you specify what to drop, and i specify what to accept

And before any other PC on your network will be able to connect to the internet, you might have to setup NAT, which is done in the postrouting chain.

Assuming eth1 is the interface where the rest is connected, you might want to do:
iptables -t nat -A POSTROUTING -i eth1 -j MASQUERADE

If you don't use NAT, filtering in the FORWARD chain is usefull. In this case you made the same mistake again (DROP what you don't want, and ... wel drop the packet anyways :-) ). Using the line above for the FORWARD chain might fix it:
iptables -A FORWARD -i eth0 -m STATE --state RELATED,ESTABLISHED -j ACCEPT

But remember, you also need to accept some outgoing traffic if you set FORWARD default policy to DROP (like you did):
iptables -A FORWARD -i eth1 -j ACCEPT
This accepts any traffic from your network to anywhere.

Last but not least you can check if /proc/sys/net/ipv4/ip_forward is set to 1.

Best regards,
pa4wdh
----
The biggest difference between M$ stuff and the rest ? Most stuff is secure by design, M$ stuff is secure by accident.

bash# killall gaim
killall: Don't shoot the messenger !

If we have /dev/powerbutton, what would touch /dev/powerbutton do ?
[Original] [Print] [Top]
Subject: Iptables Problems: Keep Open Only Some Ports
Author: foobar47    Posted: 2006-02-06 04:55:12    Length: 60 byte(s)
[Original] [Print] [Top]
Excuse me but, where is the localhost entry ??
 ::
----
Linux is like sex, it's better when it's free...
My WebPage
[Original] [Print] [Top]
Subject: Iptables Problems: Keep Open Only Some Ports
Author: x86processor    Posted: 2006-02-07 03:42:40    Length: 313 byte(s)
[Original] [Print] [Top]
[div class='quotetop']QUOTE(foobar47 @ Feb 6 2006, 03:25 PM) [snapback]760469[/snapback][/div][div class='quotemain']
Excuse me but, where is the localhost entry ??
 ::
[/quote]
In /etc/hosts?
----
Linux is the kernel. The entire system is called GNU/Linux.
http://www.gnu.org/gnu/linux-and-gnu.html

My domain: shakthimaan.com (Offline)
orkut ID: shakthimaan
IRC nick: mbuf
[Original] [Print] [Top]
Subject: Iptables Problems: Keep Open Only Some Ports
Author: foobar47    Posted: 2006-02-08 08:21:37    Length: 310 byte(s)
[Original] [Print] [Top]
[div class='quotetop']QUOTE(x86processor @ Feb 7 2006, 03:42 AM) [snapback]760531[/snapback][/div][div class='quotemain']
In /etc/hosts?
[/quote]
No, in the iptable' decola script !!?
----
Linux is like sex, it's better when it's free...
My WebPage
[Original] [Print] [Top]
« Previous thread
Problems With Installing Openssh4.2
Linux Security
Page. 3
Next thread »
I Would Like To Use Spare Computer As Firewall
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
Powered by FreeBSD    webmaster: webmaster@unixresources.net
This page created on 2007-08-01 11:46:22, cost 0.027201890945435 ms.