LinuxQuestions.org
Review your favorite Linux distribution.
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 01-07-2006, 03:44 PM   #1
Plutonium
LQ Newbie
 
Registered: Jan 2006
Location: Sweden
Distribution: Slackware
Posts: 12

Rep: Reputation: 2
Problem whit my iptables


Hi..
First sorry for my bad english..

I, just made an iptables script, and i having a problem.
That i can't connect to sshd localhost (firewall computer) ..

This is my script..

#!/bin/sh
#######################
## Script made by ##
## Plutonium ##
#######################

#### Interface ####
INET_IFACE="eth0"

#### Remove all rules and chains ####
iptables -F
iptables -F INPUT
iptables -F FORWARD
iptables -F OUTPUT
iptables -X
iptables -Z

#### Blocl all traffic ####
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

#### Accept icmp ping osv ####
#iptables -A INPUT -p icmp --icmp-type 3 -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -A OUTPUT -p icmp --icmp-type 3 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

iptables -A INPUT -p icmp --icmp-type 8 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type 8 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT


#### Accept to talk to localhost ####
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

#### DHCP servern ####
iptables -A INPUT -i $INET_IFACE -p udp -s 0/0 -d 0/0 --sport 67:68 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o $INET_IFACE -p udp -s 0/0 -d 0/0 --dport 67:68 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

#### Accept SSH ####
## From all ##
iptables -A INPUT -p tcp -i $INET_IFACE --sport 22 -j ACCEPT
iptables -A OUTPUT -p tcp -o $INET_IFACE --dport 22 -j ACCEPT

## Or from an IP ##
#iptables -A INPUT -i $INET_IFACE -p tcp --sport 22 -m account --aaddr 192.168.0.100 -m state NEW -j ACCEPT
#iptables -A OUTPUT -o $INET_IFACE -p tcp --dport 22 -m account --aaddr 192.168.0.100 -m state NEW -j ACCEPT

#### Traffic IN ####

# DNS
iptables -A INPUT -i $INET_IFACE -p udp -s 0/0 -d 0/0 --sport 53 -m state --state ESTABLISHED,RELATED -j ACCEPT

# WEB
iptables -A INPUT -i $INET_IFACE -p tcp -s 0/0 -d 0/0 --sport 80 -m state --state ESTABLISHED,RELATED -j ACCEPT

# SSL
iptables -A INPUT -i $INET_IFACE -p tcp -s 0/0 -d 0/0 --sport 443 -m state --state ESTABLISHED,RELATED -j ACCEPT

# MSN
iptables -A INPUT -i $INET_IFACE -p tcp -s 0/0 -d 0/0 --sport 1863 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i $INET_IFACE -p udp -s 0/0 -d 0/0 --sport 33700:33800 -m state --state ESTABLISHED,RELATED -j ACCEPT

# Mail
iptables -A INPUT -i $INET_IFACE -p tcp -s 0/0 -d 0/0 --sport 25 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i $INET_IFACE -p tcp -s 0/0 -d 0/0 --sport 143 -m state --state ESTABLISHED,RELATED -j ACCEPT # IMAP

# Webradio
iptables -A INPUT -i $INET_IFACE -p tcp -s 0/0 -d 0/0 --sport 8500 -m state --state ESTABLISHED,RELATED -j ACCEPT # Radioseven
iptables -A INPUT -i $INET_IFACE -p tcp -s 0/0 -d 0/0 --sport 7799 -m state --state ESTABLISHED,RELATED -j ACCEPT # Ice Radio


#### Traffic OUT ####

# DNS
iptables -A OUTPUT -o $INET_IFACE -p udp -s 0/0 -d 0/0 --dport 53 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

# WEB
iptables -A OUTPUT -o $INET_IFACE -p tcp -s 0/0 -d 0/0 --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

# SSL
iptables -A OUTPUT -o $INET_IFACE -p tcp -s 0/0 -d 0/0 --dport 443 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

# MSN
iptables -A OUTPUT -o $INET_IFACE -p tcp -s 0/0 -d 0/0 --dport 1863 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o $INET_IFACE -p udp -s 0/0 -d 0/0 --dport 33700:33800 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

# Mail
iptables -A OUTPUT -o $INET_IFACE -p tcp -s 0/0 -d 0/0 --dport 25 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -o $INET_IFACE -p tcp -s 0/0 -d 0/0 --dport 143 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT # IMAP

# Webradio
iptables -A OUTPUT -o $INET_IFACE -p tcp -s 0/0 -d 0/0 --dport 8500 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT # Radioseven
iptables -A OUTPUT -o $INET_IFACE -p tcp -s 0/0 -d 0/0 --dport 7799 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT # Ice Radio

#### Block all Windows netbios broadcast packages ####
iptables -A INPUT -p UDP -i $INET_IFACE -s 0/0 --dport 135:139 -j DROP

#### Log ####

# Logga alla intrång på degbug nivå
#iptables -A INPUT -i $INET_IFACE -p ALL -j LOG --log-level debug

# Logga ssh attacker över 3 försök
#iptables -A INPUT -i $INET_IFACE -p tcp -s 0/0 -d 0/0 --sport 22 --syn -m limit --limit 3/m -j LOG --log-level debug --log-prefix 'SSH attack'

# Logga synflood attacker
iptables -A INPUT -i $INET_IFACE -p tcp --syn -m limit --limit 10/h -j LOG --log-level debug --log-prefix 'Synflood attack'

# Logga PoD attacker.
iptables -A INPUT -i $INET_IFACE -p icmp --icmp-type echo-request -m limit --limit 10/h -j LOG --log-level debug --log-prefix 'Ping of Death attack? '

# Protect from PoD.
iptables -A INPUT -i $INET_IFACE -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT

#### Print all rules/chains ####
#iptables -vL




And yes I will decide what traffic out..
 
Old 01-08-2006, 09:45 AM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
After looking at your firewall script I think I'm noticed a mistake. I will admit though that I'm not an IPTables expert so I could be wrong. In your script you have this

Code:
#### Accept SSH ####
## From all ##
iptables -A INPUT -p tcp -i $INET_IFACE --sport 22 -j ACCEPT
iptables -A OUTPUT -p tcp -o $INET_IFACE --dport 22 -j ACCEPT
The first line says "accept input to eth0 if tcp protocol and the source port is 22."

I believe it should say "accept input to eth0 if tcp protocol and the destination port is 22." In coding IPTables it means this

Code:
iptables -A INPUT -p tcp -i $INET_IFACE --dport 22 -j ACCEPT
Other than that the only thing I can think of would be to check your sshd configuration to make sure everything is configured correctly. Good luck and hope this helps.
 
Old 01-08-2006, 09:52 AM   #3
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
For your ssh rules, first remove '-m account --addr' and replace with '-s'. Also I believe that you have --sport and --dport reversed. Are you trying to allow connections to this machine or allow outbound connections from this machine to other systems running sshd?
 
Old 01-14-2006, 07:07 AM   #4
Plutonium
LQ Newbie
 
Registered: Jan 2006
Location: Sweden
Distribution: Slackware
Posts: 12

Original Poster
Rep: Reputation: 2
booth options im using..
 
Old 01-14-2006, 10:01 AM   #5
Capt_Caveman
Senior Member
 
Registered: Mar 2003
Distribution: Fedora
Posts: 3,658

Rep: Reputation: 69
Quote:
Originally Posted by Plutonium
booth options im using..
Then you'll need to allow incoming connections with a dport of 22. Use the iptables rule that Centinul posted above.
 
Old 01-14-2006, 10:03 AM   #6
micxz
Senior Member
 
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
Easy iptables script:

http://www.geocities.com/steve93138/
 
  


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
Help me please whit this x Server problem... juswes Linux - Networking 0 11-24-2004 05:02 AM
newbie having problem whit boot Hobbe Fedora - Installation 3 10-11-2004 02:31 PM
problem whit ./configure j.vilon Linux - Software 9 09-17-2004 12:02 PM
Problem whit configure. little_ball Slackware 3 02-07-2004 02:02 PM
problem whit Giptables little_ball Linux - Networking 0 11-16-2003 12:01 PM

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

All times are GMT -5. The time now is 04:28 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