LinuxQuestions.org
Social Bookmarking all things Linux and Open Source
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Thread Tools Search this Thread
Old 06-29-2009, 12:58 AM   #1
cirano
LQ Newbie
 
Registered: Jun 2009
Posts: 2
Thanked: 0
I block myseft using IPTABLE


[Log in to get rid of this advertisement]
Here is my script, i can access my server from my LAN but not form the outside world. Also i notice that i can ping my own ip but not my gateway therefore i don;t have any connection to the outside world either. Any help is more than welcome.


#!/bin/bash
# script author :* cirano
# DATE :********** 04/14/08

SERVER_IP="10.10.11.161"
IPT="/sbin/iptables"

# flush iptables
# The following rules will clear out any existing firewall rules,
# and any chains that might have been created.
$IPT -F
$IPT -F INPUT
$IPT -F OUTPUT
$IPT -F FORWARD
# $IPT -F -t mangle
# $IPT -F -t nat
$IPT -X

# These will setup our policies.
$IPT -P INPUT DROP
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD DROP

# INPUT
# Always accept connections for lo which is your local loopback 127.0.0.1
$IPT -A INPUT -i lo -j ACCEPT

# connection states
$IPT -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# ftp
$IPT -A INPUT -i eth0 -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
$IPT -A INPUT -i eth0 -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT

# SSH
# rate-limit all incoming SSH connections to 8 in a one minute
# brute force attacks will be dropped , limiting the number of possible account
# combinations from unlimited, to 8.

$IPT -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH -j ACCEPT

$IPT -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 8 --rttl --name SSH -j DROP

$IPT -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -j LOG --log-prefix "New SSH Request "

# http
$IPT -A INPUT -i eth0 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
$IPT -A INPUT -i eth0 -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT

# Rule to enable ICMP ping incoming client requesT.
$IPT -A INPUT -p icmp --icmp-type 8 -s 0/0 -d $SERVER_IP -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

$IPT -A OUTPUT -p icmp --icmp-type 0 -s $SERVER_IP -d 0/0 -m state --state ESTABLISHED,RELATED -j ACCEPT

# My webmin custom port
$IPT -A INPUT -p tcp -m tcp --dport 10000 -j ACCEPT
# end webmin

# log INPUT
$IPT -A INPUT -j LOG --log-prefix "IPTABLES-IN Default Drop: " --log-level 7

# reject everything else
$IPT -A INPUT -j REJECT --reject-with icmp-port-unreachable

# OUTPUT
$IPT -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

$IPT -A OUTPUT -p tcp -m tcp --dport 20 -j ACCEPT
$IPT -A OUTPUT -p tcp -m tcp --dport 21 -j ACCEPT
$IPT -A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT
$IPT -A OUTPUT -p tcp -m tcp --dport 43 -j ACCEPT
$IPT -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT
$IPT -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPT
$IPT -A OUTPUT -p tcp -m tcp --dport 443 -j ACCEPT

$IPT -A OUTPUT -d 127.0.0.1 -j ACCEPT

#To enable ICMP ping outgoing request use following iptables rule:

$IPT -A OUTPUT -p icmp --icmp-type 8 -s $SERVER_IP -d 0/0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$IPT -A INPUT -p icmp --icmp-type 0 -s 0/0 -d $SERVER_IP -m state --state ESTABLISHED,RELATED -j ACCEPT

$IPT -A OUTPUT -j LOG --log-prefix "IPTABLES-OUT Default Drop: " --log-level 7
cirano is offline     Reply With Quote
Old 06-29-2009, 01:23 AM   #2
Febi881
Member
 
Registered: Jun 2009
Location: India
Distribution: Fedora,Redhat
Posts: 61
Blog Entries: 1
Thanked: 7
Please tell me What service want to access externally
Febi881 is offline     Reply With Quote
Old 06-29-2009, 04:24 AM   #3
nowonmai
Member
 
Registered: Jun 2003
Posts: 393
Thanked: 17
Post the output of ifconfig... there doesn't seem to be any rules for eth1
nowonmai is offline     Reply With Quote
Old 06-30-2009, 02:23 AM   #4
cirano
LQ Newbie
 
Registered: Jun 2009
Posts: 2
Thanked: 0

Original Poster
ip table script

I found out that SELinux was blocking me, according to this link http://www.howtoforge.com/perfect-server-fedora-10-p3 i disable it and problem solved.
Now im trying to modify my script to block DoS attacts, any good idea?


THnks
Cirano
cirano is offline     Reply With Quote
Old 06-30-2009, 02:42 AM   #5
kirukan
Member
 
Registered: Jun 2008
Location: Srilanka
Distribution: Redhat, Solaris, Suse
Posts: 611
Thanked: 55
Refer the following site
http://bipinkdas.blogspot.com/2008/0...-in-linux.html
kirukan is offline     Reply With Quote
Old 07-01-2009, 07:03 AM   #6
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: KirraMail Live Email Server
Posts: 1,158
Thanked: 11
Quote:
Originally Posted by cirano View Post
I found out that SELinux was blocking me, according to this link http://www.howtoforge.com/perfect-server-fedora-10-p3 i disable it and problem solved.
Now im trying to modify my script to block DoS attacts, any good idea?


THnks
Cirano
Checkout www.netfilter.org, a great resource of iptables scripts and information. Many of the scripts have a lot of logging and limiting of data packets to stop Dos attacks and others types of nasty stuff.

If you would like more security, look into TCPWrappers, which is installed on all linux distros. If you running a webserver, you definitely need to run mod-security, it's IDS for apache webservers, blocks in realtime.

Also look at running scripts or programs that scan your log files for any security alerts, most of these will also email you when a threat is detected.
fotoguy is offline     Reply With Quote

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
what is an iptable? & how to seperate the network on the basis of iptable vinod.wagh Linux - Networking 1 09-11-2008 02:28 AM
Error reading block "x" (Attempt to read block from....... pvandyk2005 Slackware 6 07-06-2008 06:25 AM
iptable block not working dryheat Linux - Security 4 06-04-2008 01:06 PM
IPTables and PPTPD :S (to block or not to block) thewonka Linux - Networking 0 03-24-2005 07:58 PM
Iptable-rules block port 80 goldenmag Linux - Security 3 09-05-2003 07:56 PM


All times are GMT -5. The time now is 06:02 PM.

Main Menu
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.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration