viernes, 25 de mayo de 2012

how-to get IP from hostname using dig

$ dig www.groupon.com +short | tail -n1
184.28.147.170
 
$ dig www.groupon.com +short
www.groupon.com.edgekey.net.
e5352.b.akamaiedge.net.
184.28.147.170

miércoles, 18 de abril de 2012

iptables config script with stateful filtering and logs

#!/bin/bash
#
# iptables configuration script

IPTABLES=/sbin/iptables

#
# Flush all current rules
#
$IPTABLES -F

#
# Allow SSH connections on tcp port 22
# This is essential when working on remote servers
# via SSH to prevent locking yourself out of the system

#
$IPTABLES -A INPUT -p tcp --dport 22 -j ACCEPT

#
# Allow HTTP connections on tcp port 80 from 10.20.30.40
#
$IPTABLES -A INPUT -s 10.20.30.40 -p tcp --dport 80 -j ACCEPT

#
# Set default policies for INPUT, FORWARD and OUTPUT chains
#
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD DROP
$IPTABLES -P OUTPUT ACCEPT
#
# Set access for localhost
#
$IPTABLES -A INPUT -i lo -j ACCEPT
#
# Accept packets belonging to established and related connections
#
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT


# Log drops to /var/log/messages
LOGLIMIT="2/s"
$IPTABLES -N LOGDROP
$IPTABLES -A LOGDROP -p tcp -m limit --limit $LOGLIMIT -j LOG --log-prefix "TCP LOGDROP: "
$IPTABLES -A LOGDROP -p udp -m limit --limit $LOGLIMIT -j LOG --log-prefix "UDP LOGDROP: "
$IPTABLES -A LOGDROP -p icmp -m limit --limit $LOGLIMIT -j LOG --log-prefix "ICMP LOGDROP: "
$IPTABLES -A LOGDROP -f -m limit --limit $LOGLIMIT -j LOG --log-prefix "FRAGMENT LOGDROP: "
$IPTABLES -A LOGDROP -j DROP

$IPTABLES -A INPUT -p icmp -i eth0 -j LOGDROP
$IPTABLES -A INPUT -p tcp -i eth0 -j LOGDROP
$IPTABLES -A INPUT -p udp -i eth0 -j LOGDROP




#
# In case you want to save these settings
#
# /sbin/service iptables save
#

#
# List rules
#
$IPTABLES -L -v


ref:
http://www.linuxquestions.org/questions/linux-security-4/iptables-logging-385165/
http://www.centos.org/docs/5/html/5.1/Deployment_Guide/s1-iptables-saving.html

lunes, 9 de abril de 2012

float arithmetic

laptop:~ pablo$ python

CASE 1:

>>> a = 987654321123456.1
>>> a
987654321123456.1
>>> (a*20 - (a-1)*20)/20
1.0
>>> (a*100 - (a-1)*100)/100
0.96
>>> (a*1000 - (a-1)*1000)/1000
1.024
>>> (a*10000 - (a-1)*10000)/10000
1.024

CASE 2:

>>> a = 987654321123456.1
>>> b = 987654321123455.2
>>> a-b
0.875
>>> a
987654321123456.1
>>> b
987654321123455.2