viernes, 28 de febrero de 2014

Iptables

IPTABLES


Cortafuegos completo desde Webmin

sudo modprobe iptable_nat

sudo iptables -t nat -P PREROUTING ACCEPT

sudo iptables -t nat -P POSTROUTING ACCEPT

sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Red Proxy transparente

Red para proxy transparente‏



Premisas.
1) Se entenderá en todo momento que el sistema instalado es Ubuntu 12.04 Server con la opción LAMP instalada y configurada.
2) El sistema tendrá dos tarjetas de red, eth0 y eth1. La tarjeta de red eth1 estará conectada directamente al router y la tarjeta eth0 estará conectada a un switch.
3) La red interna (las máquinas contectadas al switch) tendrá ip en el formato 192.168.2.X
4) La red externa (la que conecta con el router) tendrá ip en el formato 192.168.1.X

Configurando la red
Para que la red conectada a eth0 pueda acceder a internet (que está en eth1) debemos habilitar el “ip forwarding”. Editaremos el siguiente archivo:
sudo nano /etc/sysctl.conf
Y nos aseguramos de que esta activado, recordemos que 1 es activado y 0 desactivado.
net.ipv4.ip_forward=1
También necesitaremos decirle al sistema que aplique un par de reglas para que cuando reciba un intento de acceder a una web lo redireccione a Dansguardian para que lo analice y permita o no el acceso. Hay muchas maneras de hacer esto pero a mi me gusta crear un pequeño script que arranque al inicio del sistema.
Crearemos un fichero llamado reglas_iptables en /etc/init.d
sudo nano /etc/init.d/reglas_iptables
y le añadiremos las siguientes lí­neas:
#! /bin/sh
iptables -F
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

Guardamos y le damos permiso de ejecución:
sudo chmod +x /etc/init.d/reglas_iptables
Crearemos un enlace simbólico en /etc/rc2.d/ para que se ejecute al iniciar.
sudo ln -sf /etc/init.d/reglas_iptables /etc/rc2.d/S20reglas_iptables
Ahora configuraremos las tarjetas de red (si es que aún no lo habeis hecho ya). Esto lo hacemos editando el fichero interfaces.
sudo nano /etc/network/interfaces
Y dejándolo como sigue:
auto eth1
iface eth1 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 8.8.8.8
#Segunda tarjeta red
auto eth0
iface eth0 inet static
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.0
Con estos cambios le hemos dicho al sistema que la tarjeta eth1 que poseera la direccion ip 192.168.1.2, se conectará al router que tiene la ip 192.168.1.1 y usará los servidores de nombres (dns) de google, que son 8.8.8.8. Esta tarjeta es la que da acceso a internet.
Tambien le decimos que la tarjeta eth0 poseerá la dirección 192.168.2.1, esta tarjeta es la que se comunica con nuestra red interna.
Dicho esto solo queda reiniciar el equipo o los servicios y cruzar los dedos para que no me haya equivocado al escribir este pequeño y básico tutorial.
Reiniciamos servicios



sudo service squid restart
sudo service dansguardian restart
sudo /etc/init.d/reglas_iptables

jueves, 27 de febrero de 2014

Proxy mínimo squid3

sudo service squid3 status

sudo cp /etc/squid3/squid.conf /etc/squid3/squid.conf.seg

sudo gedit /etc/squid3/squid.conf

#########################################


# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
#acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
#acl localnet src 172.16.0.0/12    # RFC1918 possible internal network
#acl localnet src 192.168.0.0/16    # RFC1918 possible internal network
#acl localnet src fc00::/7       # RFC 4193 local private network range
#acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

acl ai4 src 192.168.10.0/24

acl SSL_ports port 443
acl Safe_ports port 80        # http
acl Safe_ports port 21        # ftp
acl Safe_ports port 443        # https
acl Safe_ports port 70        # gopher
acl Safe_ports port 210        # wais
acl Safe_ports port 1025-65535    # unregistered ports
acl Safe_ports port 280        # http-mgmt
acl Safe_ports port 488        # gss-http
acl Safe_ports port 591        # filemaker
acl Safe_ports port 777        # multiling http
acl CONNECT method CONNECT


http_access allow manager localhost
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports


# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
#http_access allow localnet
http_access allow localhost
http_access allow ai4

# And finally deny all other access to this proxy
http_access deny all



# Squid normally listens to port 3128
http_port 3128

cache_mem 256 MB

cache_dir ufs /var/spool/squid3 100 16 256

access_log /var/log/squid3/access.log squid

# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid3


########################################################



sudo cat /var/log/squid3/access.log

sudo cat /var/log/squid3/cache.log

Axigen


Obtención del software

Aunque en los repositorios oficiales de Ubuntu están disponibles varios servidores de correo nos hemos inclinado por incluir aquí este otro, Axigen, porque aúna buenas prestaciones con la sencillez de su instalación y configuración.

Instalación del software

El fichero que utilizaremos para instalar el servidor –axigen-8.0.0.i386.deb.run– puedes encontrarlo en el sitio http://www.axigen.com donde deberías registrarte (gratuitamente) para poder acceder a las opciones de descarga y para recibir, en la dirección de correo que hayas facilitado al registrarte, el fichero axigen_lk.bin que te permitirá desbloquear la restricción de uso por 30 días.

Para realizar la instalación podremos copiar el fichero axigen-8.0.0.i386.deb.run a nuestro escritorio, abrir la terminal de consola, situar el prompt en el propio Escritorio ó en el mismo directorio donde tengamos el fichero de instalación y escribir lo siguiente:

sudo sh axigen-8.0.0.i386.deb.run

y seguir los pasos de un proceso cuya secuencia puedes ver en las sucesivas imágenes que te mostramos aquí debajo.
  ¡Cuidado! 


Ni que decir tiene que axigen-8.0.0.i386.deb.run es el nombre de la versión actual. En el momento en que se produzcan actualizaciones habrá que sustituirlo por el nombre del fichero obtenido en la descarga.

Mail x enviar correo y configuracion

Ya hemos visto anteriormente como podemos usar Gmail como servidor de correo electronico para nuestro dominio, pero también es posible enviar correos electrónicos directamente desde nuestro sistema linux Debian desde línea de comandos usando Gmail como relay de correo si instalamos la utilidad "mailx" (también conocida como "nail").

Podemos usar apt-get para instalarla.

apt-get install heirloom-mailx

La configuración general de "mailx" se realiza en el fichero /etc/nail.rc.

Aquí añadiremos las siguientes líneas para hacer que "mailx" use Gmail como nuestro relay de correo.

set smtp-use-starttls
set ssl-verify=ignore
set smtp-auth=login
set smtp=smtp://smtp.gmail.com:587
set from="tu.direccion.de.correo@tu.dominio"
set smtp-auth-user=tu.direccion.de.correo@tu­.dominio
set smtp-auth-password=tu.password
set ssl-verify=ignore

Bastante sencillo, ¿verdad?



Video explicativo

Enviar email con línea de comandos desde linux

viernes, 13 de diciembre de 2013

Editando el fichero del ftp

 Fichero de FTP modificado


# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
#
# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=YES
#
# Run standalone with IPv6?
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
# instead of an IPv4 one. This parameter and the listen parameter are mutually
# exclusive.
#listen_ipv6=YES
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
#write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=NO
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=NO
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# Customization
#
# Some of vsftpd's settings don't fit the filesystem layout by
# default.
#
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/private/vsftpd.pem

# Limitar el numero de usuarios que se pueden conectar al servidor ftp.

max_clients=20

# Enjaula a los usuarios dentro de su home (directorio personal).

chroot_local_user=YES


# Mensaje de bienvenida.

ftpd_banner=Bienvenidos al Servidor FTP AI4PC107!.


 Si le quieres poner lista de enjaulados

#Habilitar.

chroot_list_enable=YES

#En esta lista introducimos los usuarios no enjaulados.

chroot_list_file=/etc/vsftpd.chroot_list


miércoles, 11 de diciembre de 2013

Servidor FTP anónimo

Instalacion del vsftpd en caso de no tenerlo.

sudo apt-get install vsftpd

sudo cp /etc/vsftpd.conf  /etc/vsftpd.conf_original

sudo gedit /etc/vsftpd.conf


En el fichero dejarlo de esta forma 


listen=YES
local_enable=NO
anonymous_enable=YES
anon_root=/srv/ftp/

Se reinicia


sudo /etc/init.d/vsftpd restart


anonymous realmente es un usuario llamado 'ftp'

Seguimos los siguientes pasos

sudo mkdir /srv/ftp/incoming

sudo chmod 755 /srv/ftp
sudo chmod 777 /srv/ftp/incoming

sudo chown root:root /srv/ftp/incoming

directorio srv del usuario ftp (no debe tener permisos de escritura, propietario root)
drwxr-xr-x   root
/srv/ftp/

Directorio con permisos de escritura
drwxrwxrwx   root
/srv/ftp/incoming/



Continuación de la configuración del archivo vsftpd en la sección “Anonymus FTP user Settings”:
# Anonymus FTP user Settings ##
Permitir conexiones anónimas.
anonymous_enable=YES
# Directorio raíz para los usuarios anónimos. Carpeta creada
# en /srv/ftp/ como se comentó anteriormente.
anon_root=incoming
# Solo permite descargar a los usuarios anónimos aquellos archivos
# que tengan permisos de lectura.
anon_world_readable_only=YES
# Para mi caso especifiqué con la siguiente directiva que los
# usuarios anónimos no tengan permisos para subir archivos
# al servidor.
anon_upload_enable=NO
# Esta directiva permite a los usuarios anónimos a crear carpetas
# en ciertos casos.
anon_mkdir_write_enable=NO
# Directiva que permite establecer el límite de la velocidad máxima
# de transferencia de datos para los usuarios anónimos. Fui un
# poco drástico jeje (2kb/s)
anon_max_rate=2048



http://molons.wordpress.com/2012/01/17/instalar-vsftpd-en-ubuntu-10-04-webmin-y-habilitar-usuario-anonymous/


ftp://ftp.eppg.com/
servicios_en_red
star.tr3k



Forma como me funciono el FTP Anonimo

listen=YES
local_enable=YES
anonymous_enable=YES
write_enable=YES
anon_root=/srv/ftp/


chroot_local_user=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

anon_world_readable_only=YES

anon_upload_enable=YES