iptables segédlet

Magyar nyelven, Firewall scripts No Comments »

iptables láncok (chains):
 INPUT
 OUTPUT
 FORWARD

Az iptables a csomagokat a filter táblázatban az alábbi láncokban kezeli:
-Ha a csomag errol a szamitogeprol indul ki (egy olyan program generalta, amely erre a gepre lett telepitve) akkor a csomag CSAK az OUTPUT chain-be fog menni.
-Ha a csomag erre a gepre erkezik, akkor CSAK az INPUT chain-en halad keresztul.
-Ha a csomag valahova mashova megy, akkor CSAK a FORWARD chain-en fog keresztul haladni.

Tehat egy mashova meno csomag SOHA sem erinti az INPUT chaint, hasonloan egy tovabbitott csomag (forwarded packet) SOHA nem lesz benne az OUTPUT chain-ben.
Az iptables minden kapcsolatot nyilvantart amit a `cat /proc/net/ip_conntract` paranccsal lehet listazni.

Mikor es hogyan kell letrehozni es hasznalni egyedileg letrehozott chaineket?
A kovetkezo peldaban letre fogunk hozni egy sajat “mychain”-t annak erdekeben, hogy az INPUT es FORWARD chain-ek szinten felhasznaljak a szabalyait.


# iptables -N mychain
# iptables -A mychain -m state --state ESTABLISHED,RELATED -j ACCEPT
# ...tovabbi tuzfal szabalyok...
# iptables -A mychain -j DROP
# iptables -A INPUT -j mychain
# iptables -A FORWARD -j mychain

Ezzel a modszerrel azt ertuk el, hogy nem kell kulon programozni az INPUT es FORWARD chaineket, hanem felhasznaljak az uj “mychain” szabalyait.

A tuzfalak rendszerint legalabb ket halozati kartyat tartalmaznak. Az egyik az internet fele, a tobbi pedig a lokalis halozatnak biztositja az eleresi feluletet. Ha egy csomag a kulso illeszton keresztul beerkezik azt lehet, hogy tovabbitani kell a helyi halozat fele (FORWARD chain), ami a halozat szempontjabol INPUT chain. Ezert tehat elkepzelheto, hogy egy csomag vezerlesehez tobb szabalyra van szukseg.

Az iptables az alabbi tablakat tartalmazza (`cat /proc/net/ip_tables_names`):

  • A “filter” az elso es alapertelmezett tabla, amely tartalmazza az INPUT (a gepre cimzett csomagok), OUTPUT (lokalisan generalt csomagok), es FORWARD (a gepen keresztul routolando csomagok) lancokat.
  • A “nat” tablaban olyan csomagok vannak amelyek uj kapcsolatokat hoztak letre. A nat tabla harom alapertelmezett lancot tartalmaz. Ezek PREROUTING (az eppen beerkezo csomagok megvaltoztatasara), OUTPUT (helyileg generalt csomagok routolas elotti megvaltoztatasara) es POSTROUTING (a gepet eppen elhagyo csomagok megvaltoztatasara) lancok.
  • A “mangle” tabla a csomagok specialis megvaltoztatasara van fenntartva. Lancai a PREROUTING (beerkezo csomagok routolas elotti modositasara) es OUTPUT (lokalisan generalt csomagok megvaltoztatasara).

További hasznos iptables parancsok:

# iptables -t nat -L -n (Nem kell idot vesztegetni a DNS lekereshez a helyi cimek forditasahoz: -n )
# iptables -p tcp --help
# iptables -m state --help
# iptables -j LOG --help

MEGJ. Ezt a cikket Hauser István írta, először 2005 május. 23.-án.

Make a hole into firewall to make your web server visible to others

Firewall scripts No Comments »

# Make a hole into firewall to make your web server visible to others.

iptables -I INPUT 1 -p tcp –dport 80 -j ACCEPT
iptables-save > /etc/sysconfig/iptables
 

Startup script for Tomcat Servlet Engine

shell scripts, Java No Comments »

Example shell script usage:

  • /etc/rc.d/tomcat start
  • /etc/rc.d/tomcat stop
  • /etc/rc.d/tomcat restart


#!/bin/sh
#
# Startup script for Tomcat, the Apache Servlet Engine
#
# chkconfig: 345 80 20
# description: Tomcat is the Apache Servlet Engine
# processname: tomcat
# pidfile: /var/run/tomcat.pid
#
# Mike Millson <mmillson@meritonlinesystems.com>
#
# version 1.02 - Clear work directory on shutdown per John Turner suggestion.
# version 1.01 - Cross between RedHat Tomcat RPM and Chris Bush scripts
# Tomcat name :)
TOMCAT_PROG=tomcat
# if TOMCAT_USER is not set, use tomcat like Apache HTTP server
if [ -z “$TOMCAT_USER” ]; then
 TOMCAT_USER=”tomcat”
fi
RETVAL=0
# start and stop functions
start() {
    echo -n “Starting tomcat: ”
    chown -R $TOMCAT_USER:$TOMCAT_USER /usr/java/jakarta-tomcat/*
    chown -R $TOMCAT_USER:$TOMCAT_USER /home/tomcat/*
    su -l $TOMCAT_USER -c ‘/usr/java/jakarta-tomcat/bin/startup.sh’
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat
    return $RETVAL
}
stop() {
    echo -n "Stopping tomcat: "
    su -l $TOMCAT_USER -c '/usr/java/jakarta-tomcat/bin/shutdown.sh'
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat /var/run/tomcat.pid
}
#    rm -rf /usr/java/jakarta-tomcat/work/*

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        # Ugly hack
        # We should really make sure tomcat
        # is stopped before leaving stop
        sleep 2
        start
        ;;
  *)
        echo "Usage: $0 start|stop|restart"
        exit 1
esac
exit $RETVAL

iptables firewall script

Firewall scripts No Comments »


#!/bin/bash
###############################################
#
# Copyright (c) webHauser
# iptables packet filtering firewall script
# RedHat Linux 9
# Kernel 2.4.20-8

NET=eth0
LAN=eth1
IPTABLES=/sbin/iptables

#
# ipkernel security settings
# /etc/sysctl.conf
#
# This setting is default
# echo 1 > /proc/sys/net/ipv4/ip_forward
# Drop ICMP echo-request messages sent to broadcast or multicast addresses
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

# Drop source routed packets
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route

# Enable TCP SYN cookie protection from SYN floods
echo 1 > /proc/sys/net/ipv4/tcp_syncookies

# Don't accept ICMP redirect messages
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects

# Don't send ICMP redirect messages
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects

# Enable source address spoofing protection
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter

# Log packets with impossible source addresses
echo 0 > /proc/sys/net/ipv4/conf/all/log_martians
# Flush all tables and chains
$IPTABLES -F
$IPTABLES -X
$IPTABLES -t mangle -F
$IPTABLES -t mangle -X
$IPTABLES -t filter -F
$IPTABLES -t filter -X
$IPTABLES -t nat -F
$IPTABLES -t nat -X

# Set default policies
$IPTABLES --policy INPUT DROP
$IPTABLES --policy FORWARD DROP
$IPTABLES --policy OUTPUT DROP
# Allow unlimited traffic on the loopback interface
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT
# Previously initiated and accepted exchanges bypass rule checking
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow unlimited outbound traffic
$IPTABLES -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
# Allow incoming port 22 (ssh) connections on LAN interface
$IPTABLES -A INPUT -i $LAN -p tcp --destination-port 22 -m state --state NEW -j ACCEPT

# Allow ICMP ECHO REQUESTS on LAN interface
$IPTABLES -A INPUT -i $LAN -p icmp --icmp-type echo-request -j ACCEPT

# Allow incoming 80 (http) connections from LAN interface
$IPTABLES -A INPUT -i $LAN -p tcp --destination-port 80 -m state --state NEW -j ACCEPT
# Allow incoming 8080 (tomcat) connections from LAN interface
$IPTABLES -A INPUT -i $LAN -p tcp --destination-port 8080 -m state --state NEW -j ACCEPT
# Create a LOGDROP chain to log and drop packets to /var/log/messages
####$IPTABLES -N LOGDROP
####$IPTABLES -A LOGDROP -j LOG
####$IPTABLES -A LOGDROP -j DROP
####$IPTABLES -A INPUT -j LOGDROP

# Drop all other traffic
$IPTABLES -A INPUT -j DROP

/sbin/iptables-save > /root/setup/firewall/iptables-new

Group Fields

HTML/OS No Comments »

Group Fields is a feature of HTML/OS’s Web-oriented database technology. It allows user to define a “special” field composed of a list of other fields in the database. Group fields have the special quality they are “word indexed.” So multi-word searches of group fields are particularly fast - even on databases with hundreds of thousands or millions of records.

Group fields are often used to build “Find” boxes in sites that perform multi-field, multi-word searches.

Incremental Indexing

HTML/OS No Comments »

Incremental indexing is the ability to index a database in steps. Incremental database indexing allows one to index large databases over the Web. It allows one to index databases in steps - so they can be indexed despite browser timeout - a problem that (under other circumstances) dissuades web users from performing computational tasks that exceed the time it takes a browser to time out.

Power Search

HTML/OS No Comments »

HTML/OS is well-suited to providing users a wide variety of search options.

HTML/OS has powerful database search capabilities. We even support a concept known as “Group Fields” whereby you define a set of fields in a database as a “group field”. Once set up (using a point-and-click utility called dbConsole that is included with HTML/OS), multi-word searches of the group field automatically performs a high-speed search across all of the specified fields.

Alternatively, you can use a more conventional approach and define a search form with multiple inputs that, upon submission, performs a search of your product database.

About Aestiva HTML/OS

HTML/OS No Comments »

What is HTML/OS?

Aestiva HTML/OS is a software package installed on standard Internet and Intranet servers that gives HTML documents dynamic capabilities, server-side file management functionality, sophisticated programming capabilities, database access abilities and inherent security.

Aestiva HTML/OS, like HTML documents, is cross-platform and server-independent. It eliminates the need for CGI programming and it is 100% Web-compatible.

Aestiva HTML/OS works by giving servers the ability to read HTML documents and perform translations on “Overlay Tags” placed within them. Its highly efficient kernel automatically maintains a multi-page, multi-user environment. Developing dynamic content is drastically simplified and, at the same time, capabilities are greatly expanded. Sophisticated Web-sites and Web-applications, previously too difficult to write, are now designable — for anyone with at least some HTML coding skills. 

Aestiva HTML/OS is a software package installed on standard Internet and Intranet servers that gives HTML documents dynamic capabilities, server-side file management functionality, sophisticated programming capabilities, database access abilities and inherent security.

Aestiva HTML/OS, like HTML documents, is cross-platform and server-independent. It eliminates the need for CGI programming and it is 100% Web-compatible.

Aestiva HTML/OS works by giving servers the ability to read HTML documents and perform translations on “Overlay Tags” placed within them. Its highly efficient kernel automatically maintains a multi-page, multi-user environment. Developing dynamic content is drastically simplified and, at the same time, capabilities are greatly expanded. Sophisticated Web-sites and Web-applications, previously too difficult to write, are now designable — for anyone with at least some HTML coding skills.