domingo, 17 de enero de 2016

Configurar red en Ubuntu

Wikijc:Sistemas redlinux

Configurar la red en Ubuntu


Para evitar el molesto beep de la consola poner en ~/profile lo siguiente:
echo -ne '\033[11;0]'
Con esto el beep de la consola queda en 0.

En este articulo vamos a ver que ficheros tenemos que editar para que nos funcione la red en Ubuntu
Editamos el fichero interfaces
$ vi /etc/network/interfaces
auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.0.0.0

auto eth0
iface eth0 inet static
address 192.168.33.44
gateway 192.168.33.1
netmask 255.255.255.0
network 192.168.33.0
broadcast 192.168.33.255

Editamos o creamos el fichero resolv.conf que es el que nos configura el DNS
$ vi /etc/resolv.conf
search val.blom.lan mad.blom.lan blom.es
nameserver 192.168.33.228
domain val.blom.lan
Editamos el fichero hostname que es donde va el nombre de maquina
$ vi /etc/hostname
#nombre_de_maquina.dominio
servidor.val.blom.lan

Editamos el fichero hosts
$ vi /etc/hosts
127.0.0.1 localhost
127.0.1.1 vallekas
127.0.1.1 vallekas.val.blom.lan
192.168.33.150 vallekas.val.blom.lan

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Editamos los ficheros hosts.allow y hosts.deny para poner lo que dejamos entrar en nuestro host
$ vi /etc/hosts.allow# /etc/hosts.allow: list of hosts that are allowed to access the system.
# See the manual pages hosts_access(5), hosts_options(5)
# and /usr/doc/netbase/portmapper.txt.gz
# # Example: ALL: LOCAL @some_netgroup
# ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
# # If you're going to protect the portmapper use the name "portmap" for the
# daemon name. Remember that you can only use the keyword "ALL" and IP
# addresses (NOT host or domain names) for the portmapper, as well as for
# rpc.mountd (the NFS mount daemon). See portmap(8), rpc.mountd(8) and
# /usr/share/doc/portmap/portmapper.txt.gz for further information.
#
sshd: 192.168.
ntpd: 192.168.

$ vi /etc/hosts.deny
# /etc/hosts.deny: list of hosts that are _not_ allowed to access the system.
# See the manual pages hosts_access(5), hosts_options(5)
# and /usr/doc/netbase/portmapper.txt.gz
#
# Example: ALL: some.host.name, .some.domain
# ALL EXCEPT in.fingerd: other.host.name, .other.domain
#
# If you're going to protect the portmapper use the name "portmap" for the
# daemon name. Remember that you can only use the keyword "ALL" and IP
# addresses (NOT host or domain names) for the portmapper. See portmap(8)
# and /usr/doc/portmap/portmapper.txt.gz for further information.
#
# The PARANOID wildcard matches any host whose name does not match its
# address.

# You may wish to enable this to ensure any programs that don't
# validate looked up hostnames still leave understandable logs. In past
# versions of Debian this has been the default.
# ALL: PARANOID

Vemos el sources.list que tenemos para las actualizaciones del sistema
$ vi /etc/apt/sources.list

## UBUNTU MAIN

deb http://us.archive.ubuntu.com/ubuntu/ gutsy main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ gutsy main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ gutsy-proposed main restricted universe multiverse

## BUG FIX UPDATES
deb http://us.archive.ubuntu.com/ubuntu/ gutsy-updates main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ gutsy-updates main restricted universe multiverse

## UBUNTU SECURITY UPDATES
deb http://security.ubuntu.com/ubuntu gutsy-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu gutsy-security main restricted universe multiverse

## BACKPORTS REPOSITORY
deb http://us.archive.ubuntu.com/ubuntu/ gutsy-backports main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ gutsy-backports main restricted universe multiverse

## CANONICAL COMMERCIAL REPOSITORY
deb http://archive.canonical.com/ubuntu gutsy partner

# Beryl 0.2.0
# deb http://ubuntu.beryl-project.org feisty main
# deb-src http://ubuntu.beryl-project.org feisty main

#Añadidos por Juan Carlos 19_11_2007
#----------------------no oficial ----------------
#Free fonts for Ubuntu Gutsy Gibbon
deb http://ppa.launchpad.net/corenominal/ubuntu gutsy main
deb-src http://ppa.launchpad.net/corenominal/ubuntu gutsy main

Para conectar con la red de madrid necesitamos los siguientes ficheros
$ vi /etc/network/alt-route-intranet
# Habilitar la salida por ONO desde Valladolid a Madrid
IF=eth0
NET=192.168.0.0
MASK=255.255.0.0
GW=192.168.33.31

$ vi /etc/network/if-up.d/altroutes
#!/bin/bash
# script para terminar las rutas puestas con ifup

# no para interface lo
if [ "$IFACE" = "lo" ]; then
exit 0
fi

# Si no existe un fichero alt-route-lo-que-sea, nos vamos
if ! [ -r /etc/network/alt-route* ] ; then
exit 0
fi

for file in `ls /etc/network/alt-route*`; do
. $file

if [ "$IF" = "$IFACE" ] ; then
if [ -z $NET ] || [ -z $MASK ] || [ -z $GW ] ; then
logger -t altroute -p user.notice -s \
"Parse error, check config file $file"
exit 1
else
route add -net $NET netmask $MASK gw $GW
if [ $? = 0 ] ; then
logger -t altroute -p user.notice \
"route add -net $NET netmask $MASK gw $GW"
else
logger -t altroute -p user.notice \
"Failed to add route to $NET."
fi
fi
fi
done

$ vi /etc/network/if-down.d/altroutes
#!/bin/bash
# script para terminar las rutas puestas con ifup

# lo is configured.
if [ "$IFACE" = "lo" ]; then
exit 0
fi

if ! [ -r /etc/network/alt-route* ] ; then
exit 0
fi

for file in `ls /etc/network/alt-route*`; do
. $file
if [ "$IF" = "$IFACE" ] ; then
if [ -z $NET ] || [ -z $MASK ] || [ -z $GW ] ; then
logger -t altroute -p user.notice -s \
"Parse error, check config file: $file"
exit 1
else
route del -net $NET netmask $MASK gw $GW \
&& logger -t altroute -p user.notice \
"route del -net $NET netmask $MASK gw $GW"
fi
fi
done

Para que las maquinas puedan salir a internet a traves del proxy, tenemos que añadir al fichero .bashrc del usuario las siguientes lineas
$ vi /home/jc/.bashrc
#En una red donde toda la salida a Internet pasa por un proxy hace falta avisar avisar a las utilidades de red
# sin esto no funciona ni wget(), ni curl(), ni lynx() y por lo tanto tampoco yum() o aptitude()
export https_proxy=http://192.168.33.86:3128
export http_proxy=http://192.168.33.86:3128
export ftp_proxy=http://192.168.33.86:3128
export no_proxy="localhost,127.0.0.1,blom.lan,192.168.0.0/16"
--- Este es un fichero con alias para la red
$ vi /etc/network/interfaces
auto lo
iface lo inet loopback

#The primary network interface
auto eth0
iface eth0 inet static
address 192.168.33.230
netmask 255.255.255.0
network 192.168.33.0
broadcast 192.168.33.255

auto eth1
iface eth1 inet static
address 10.0.33.1
netmask 255.255.255.0
network 10.0.33.0
broadcast 10.0.33.255

auto eth2 eth2:3 eth2:4 eth2:5 eth2:6
iface eth2 inet static
address 84.124.4.82
netmask 255.255.255.248
gateway 84.124.4.81
network 84.124.4.80
broadcast 84.124.4.87

iface eth2:3 inet static
address 84.124.4.83
netmask 255.255.255.248

iface eth2:4 inet static
address 84.124.4.84
netmask 255.255.255.248

iface eth2:5 inet static
address 84.124.4.85
netmask 255.255.255.248

iface eth2:6 inet static
address 84.124.4.86
netmask 255.255.255.248

Para crear rutas en una maquina usamos route
$ route del default
$ route del -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.33.230
$ route add default gw 192.168.33.1
$ route add -net 192.168.33.0 netmask 255.255.255.0 gw 192.168.33.1
Añadir la ruta al fichero /etc/rc.local para que se ejecute al inicio
$ nano /etc/rc.local
$ route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.33.31
Para poder ver las rutas podemos usar el comando route
$ route -n
Tabla de rutas IP del núcleo
Destino Puerta de Enlace Genmask Banderas Metrica Ref Uso Interfaz
192.168.34.0 192.168.33.45 255.255.255.0 UG 0 0 0 eth0
192.168.33.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
192.168.0.0 192.168.33.31 255.255.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.33.1 0.0.0.0 UG 100 0 0 eth0

Para ver las conexiones que tiene un equipo
$ netstat -tanp

No hay comentarios:

Publicar un comentario

Nota: solo los miembros de este blog pueden publicar comentarios.