LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-23-2009, 03:52 AM   #1
satish
Member
 
Registered: Jan 2006
Posts: 171

Rep: Reputation: 15
Need of Strong Firewall


I have Red hat linux 9 proxy server in my office and needed of strong firewall for my internal network, as anyone start utorrent and download from torrent sites. i want a firewall which open only ftp port,pop3 port,smtp port and ssl smtp 465, 995 port.

Here i am giving my current firewall rules.




#!/bin/sh
# Initial SIMPLE IP Masquerade test for 2.4.x kernels
# using IPTABLES.
#
# Once IP Masquerading has been tested, with this simple
# ruleset, it is highly recommended to use a stronger
# IPTABLES ruleset either given later in this HOWTO or
# from another reputable resource.
#
#
#
# Log:
# 0.75 - Added more kernel modules to the comments section
# 0.74 - the ruleset now uses modprobe vs. insmod
# 0.73 - REJECT is not a legal policy yet; back to DROP
# 0.72 - Changed the default block behavior to REJECT not DROP
# 0.71 - Added clarification that PPPoE users need to use
# "ppp0" instead of "eth0" for their external interface
# 0.70 - Added commented option for IRC nat module
# - Added additional use of environment variables
# - Added additional formatting
# 0.63 - Added support for the IRC IPTABLES module
# 0.62 - Fixed a typo on the MASQ enable line that used eth0
# instead of $EXTIF
# 0.61 - Changed the firewall to use variables for the internal
# and external interfaces.
# 0.60 - 0.50 had a mistake where the ruleset had a rule to DROP
# all forwarded packets but it didn't have a rule to ACCEPT
# any packets to be forwarded either
# - Load the ip_nat_ftp and ip_conntrack_ftp modules by default
# 0.50 - Initial draft
#

echo -e "\n\nLoading simple rc.firewall version $FWVER..\n"


# The location of the iptables and kernel module programs
#
# If your Linux distribution came with a copy of iptables,
# most likely all the programs will be located in /sbin. If
# you manually compiled iptables, the default location will
# be in /usr/local/sbin
#
# ** Please use the "whereis iptables" command to figure out
# ** where your copy is and change the path below to reflect
# ** your setup
#
IPTABLES=/sbin/iptables
DEPMOD=/sbin/depmod
MODPROBE=/sbin/modprobe


#Setting the EXTERNAL and INTERNAL interfaces for the network
#
# Each IP Masquerade network needs to have at least one
# external and one internal network. The external network
# is where the natting will occur and the internal network
# should preferably be addressed with a RFC1918 private address
# scheme.
#
# For this example, "eth0" is external and "eth1" is internal"
#
#
# NOTE: If this doesnt EXACTLY fit your configuration, you must
# change the EXTIF or INTIF variables above. For example:
#
# If you are a PPPoE or analog modem user:
#
# EXTIF="ppp0"
#
#
EXTIF="eth1"
INTIF="eth0"
echo " External Interface: $EXTIF"
echo " Internal Interface: $INTIF"


#======================================================================
#== No editing beyond this line is required for initial MASQ testing ==


echo -en " loading modules: "

# Need to verify that all modules have all required dependencies
#
echo " - Verifying that all kernel modules are ok"
$DEPMOD -a

# With the new IPTABLES code, the core MASQ functionality is now either
# modular or compiled into the kernel. This HOWTO shows ALL IPTABLES
# options as MODULES. If your kernel is compiled correctly, there is
# NO need to load the kernel modules manually.
#
# NOTE: The following items are listed ONLY for informational reasons.
# There is no reason to manual load these modules unless your
# kernel is either mis-configured or you intentionally disabled
# the kernel module autoloader.
#

# Upon the commands of starting up IP Masq on the server, the
# following kernel modules will be automatically loaded:
#
# NOTE: Only load the IP MASQ modules you need. All current IP MASQ
# modules are shown below but are commented out from loading.
# ===============================================================

echo "----------------------------------------------------------------------"

#Load the main body of the IPTABLES module - "iptable"
# - Loaded automatically when the "iptables" command is invoked
#
# - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "ip_tables, "
$MODPROBE ip_tables


#Load the IPTABLES filtering module - "iptable_filter"
# - Loaded automatically when filter policies are activated


#Load the stateful connection tracking framework - "ip_conntrack"
#
# The conntrack module in itself does nothing without other specific
# conntrack modules being loaded afterwards such as the "ip_conntrack_ftp"
# module
#
# - This module is loaded automatically when MASQ functionality is
# enabled
#
# - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "ip_conntrack, "
$MODPROBE ip_conntrack


#Load the FTP tracking mechanism for full FTP tracking
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -en "ip_conntrack_ftp, "
$MODPROBE ip_conntrack_ftp


#Load the IRC tracking mechanism for full IRC tracking
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -en "ip_conntrack_irc, "
$MODPROBE ip_conntrack_irc


#Load the general IPTABLES NAT code - "iptable_nat"
# - Loaded automatically when MASQ functionality is turned on
#
# - Loaded manually to clean up kernel auto-loading timing issues
#
echo -en "iptable_nat, "
$MODPROBE iptable_nat


#Loads the FTP NAT functionality into the core IPTABLES code
# Required to support non-PASV FTP.
#
# Enabled by default -- insert a "#" on the next line to deactivate
#
echo -en "ip_nat_ftp, "
$MODPROBE ip_nat_ftp


#Loads the IRC NAT functionality into the core IPTABLES code
# Required to support NAT of IRC DCC requests
#
# Disabled by default -- remove the "#" on the next line to activate
#
#echo -e "ip_nat_irc"
#$MODPROBE ip_nat_irc

echo "----------------------------------------------------------------------"

# Just to be complete, here is a partial list of some of the other
# IPTABLES kernel modules and their function. Please note that most
# of these modules (the ipt ones) are automatically loaded by the
# master kernel module for proper operation and don't need to be
# manually loaded.
# --------------------------------------------------------------------
#
# ip_nat_snmp_basic - this module allows for proper NATing of some
# SNMP traffic
#
# iptable_mangle - this target allows for packets to be
# manipulated for things like the TCPMSS
# option, etc.
#
# --
#
# ipt_mark - this target marks a given packet for future action.
# This automatically loads the ipt_MARK module
#
# ipt_tcpmss - this target allows to manipulate the TCP MSS
# option for braindead remote firewalls.
# This automatically loads the ipt_TCPMSS module
#
# ipt_limit - this target allows for packets to be limited to
# to many hits per sec/min/hr
#
# ipt_multiport - this match allows for targets within a range
# of port numbers vs. listing each port individually
#
# ipt_state - this match allows to catch packets with various
# IP and TCP flags set/unset
#
# ipt_unclean - this match allows to catch packets that have invalid
# IP/TCP flags set
#
# iptable_filter - this module allows for packets to be DROPped,
# REJECTed, or LOGged. This module automatically
# loads the following modules:
#
# ipt_LOG - this target allows for packets to be
# logged
#
# ipt_REJECT - this target DROPs the packet and returns
# a configurable ICMP packet back to the
# sender.
#

echo -e " Done loading modules.\n"



#CRITICAL: Enable IP forwarding since it is disabled by default since
#
# Redhat Users: you may try changing the options in
# /etc/sysconfig/network from:
#
# FORWARD_IPV4=false
# to
# FORWARD_IPV4=true
#
echo " Enabling forwarding.."
echo "1" > /proc/sys/net/ipv4/ip_forward


# Dynamic IP users:
#
# If you get your IP address dynamically from SLIP, PPP, or DHCP,
# enable this following option. This enables dynamic-address hacking
# which makes the life with Diald and similar programs much easier.
#
echo " Enabling DynamicAddr.."
echo "1" > /proc/sys/net/ipv4/ip_dynaddr


# Enable simple IP forwarding and Masquerading
#
# NOTE: In IPTABLES speak, IP Masquerading is a form of SourceNAT or SNAT.
#
# NOTE #2: The following is an example for an internal LAN address in the
# 192.168.0.x network with a 255.255.255.0 or a "24" bit subnet mask
# connecting to the Internet on external interface "eth0". This
# example will MASQ internal traffic out to the Internet but not
# allow non-initiated traffic into your internal network.
#
#
# ** Please change the above network numbers, subnet mask, and your
# *** Internet connection interface name to match your setup
#


#Clearing any previous configuration
#
# Unless specified, the defaults for INPUT and OUTPUT is ACCEPT
# The default for FORWARD is DROP (REJECT is not a valid policy)
#
echo " Clearing any existing rules and setting default policy.."
$IPTABLES -P INPUT ACCEPT
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
$IPTABLES -t nat -F

echo " FWD: Allow all connections OUT and only existing and related ones IN"
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT
#$IPTABLES -A FORWARD -j LOG

echo " Enabling SNAT (MASQUERADE) functionality on $EXTIF"
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

echo -e "\nrc.firewall-2.4 v$FWVER done.\n"


Please suggest me any strong firewall rules.

Regards

Satish
 
Old 11-23-2009, 07:23 AM   #2
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,693
Blog Entries: 1

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Quote:
I have Red hat linux 9 proxy server
PLEASE tell me this is Fedora 9 and not Red Hat 9. Both are obsolete and completely unsupported (and should be replaced, particularly on something connected to the internet) but at least Fedora 9 is less completely obsolete than Red Hat 9. Red Hat 9 is beyond ancient.


Quote:
#Clearing any previous configuration
#
# Unless specified, the defaults for INPUT and OUTPUT is ACCEPT
# The default for FORWARD is DROP (REJECT is not a valid policy)
#
echo " Clearing any existing rules and setting default policy.."
$IPTABLES -P INPUT ACCEPT
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
$IPTABLES -t nat -F
To be honest, this is completely insane. If you want to have a decent firewall, the default policies should be DROP, not ACCEPT. The way iptables works is that a packet is handled according to the first rule that it matches, and if it never matches one, it is handled by the default for the table. In your case since the default is ACCEPT, The firewall will pass absolutely EVERYTHING that it doesn't recognize. A good firewall should do exactly the opposite, it should DROP everything and only accept packets that have been explicitly accepted.

I would strongly suggest becoming familiar with this tutorial before you go mucking about with iptables. And I would also strongly suggest finding a modern, supported distro to replace whatever you've got on this thing.
 
Old 11-23-2009, 01:55 PM   #3
okcomputer44
Member
 
Registered: Jun 2008
Location: England
Distribution: CentOS, Fedora
Posts: 198

Rep: Reputation: 43
Hi,

try this: http://www.linuxquestions.org/questi...script-719523/

Laz
 
Old 11-23-2009, 03:02 PM   #4
Jim Bengtson
Member
 
Registered: Feb 2009
Location: Iowa
Distribution: Ubuntu 9.10
Posts: 164

Rep: Reputation: 38
Try Vyatta: http://www.vyatta.org/

It's based on Debian, and has very good documentation.
 
Old 11-23-2009, 03:49 PM   #5
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,449

Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
Quote:
Originally Posted by satish View Post
I have Red hat linux 9 proxy server in my office and needed of strong firewall for my internal network....

...Please suggest me any strong firewall rules...
A nice idea -that there are 'strong' firewall rules that are somehow better than 'weak' firewall rules- but I'm not sure what you mean.

Nothing about firewalling works without a context. Stuff that works well in one context can be horribly dangerous in another and if you don't give complete information about that, you won't get help that you can just 'plug in and use'.

Note that if this is just a proxy server, there may well be the possibility of just going around it; you would have to say something about the overall networking architecture to know that (although eth0 and eth1 are a good sign) and that would make strong firewall rules, whatever they are, ineffective.

Quote:
as anyone start utorrent and download from torrent sites
Presumably, you are saying that this would be a problem to you. You can explicitly block off the conventional port, but could someone use an unconventional port?

Quote:
open only ftp port,pop3 port,smtp port and ssl smtp 465, 995 port
This should be easy enough for you to do; if you have read the frozentux tutorial and you still don't know how to do it, please state exactly what your area of confusion is, because then you might be able to get help.

When you do block or open ports you should ensure that you comment the script adequately because someone who reads it later (which may be you) may not know which port number relates to which service. If you go back to this a year later, you may need all the help that you can get.

Quote:
To be honest, this is completely insane. If you want to have a decent firewall, the default policies should be DROP, not ACCEPT. The way iptables works is that a packet is handled according to the first rule that it matches, and if it never matches one, it is handled by the default for the table. In your case since the default is ACCEPT, The firewall will pass absolutely EVERYTHING that it doesn't recognize. A good firewall should do exactly the opposite, it should DROP everything and only accept packets that have been explicitly accepted.
A little strong -partially insane, maybe- given that you can produce the same result as a policy by putting an unconditional drop at the end of each table. But
  • you don't do that, either
  • it wouldn't have any advantage over a policy
so what you have today certainly doesn't seem sensible and trying to bolt on a 'strong rule' somewhere just doesn't make any sense unless you are prepared to fix that problem one way or another.

Note that this approach:
Quote:
echo "1" > /proc/sys/net/ipv4/ip_forward
of squirting some data at the proc filesystem works on some distros, but not others, and while I think that this will work with Fedora/RedHat/Centos, when you change to something that is still in support, a bit of testing is indicated.

Overall, my largest concern is that you seem to be (I could easily be wrong...I am guessing a bit here, absent sufficient information) picking up a script written by someone else that you do not thoroughly understand and you hope that a bunch of people who don't know the context can bolt on a few bits and pieces that will give you good security. That won't work, unless the audience here 'guesses lucky' with what is going on at your site. Hoping that people guess lucky seems like the antithesis of good security.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strong password help MarlinM Linux - Laptop and Netbook 2 06-08-2009 04:15 PM
strong willed Daniel Baker LinuxQuestions.org Member Intro 0 04-24-2007 06:15 AM
strong passwords csaunders Red Hat 5 02-24-2007 09:33 AM
strong gpasswd cachemonet Linux - Security 1 07-26-2006 02:45 PM
Working IPTABLES STRONG firewall for TWO internal networks kennedy01 Linux - Wireless Networking 3 08-24-2004 11:10 PM


All times are GMT -5. The time now is 11:17 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.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration