Copy Link
Add to Bookmark
Report

IP aliases

Death Knights Issue 5

eZine's profile picture
Published in 
Death Knights
 · 2 years ago

by Cacaio


Ae, vou ensinar aqui algo que pode ser util. IP aliases no linux. Nao to afim de introducao e por isso vou logo dizer como fazer.

Carregue o modo de IP alias (se ja nao estiver compilado no kernel):

/sbin/insmod /lib/modules/`uname -r`/ipv4/ip_alias.o

Agora arrume o loopback, eth0 e todos os IPs comecando com o numero do IP princial para a interface do eth0:

/sbin/ifconfig lo 127.0.0.1 
/sbin/ifconfig eth0 up
/sbin/ifconfig eth0 196.16.3.1
/sbin/ifconfig eth0:0 196.16.3.10
/sbin/ifconfig eth0:1 196.16.3.100

196.16.3.1 e' o numero de IP principal, enquanto .10 e .100 sao aliases. A parada e' o 'eth0:x' onde x=0,1,2,... para os IPs diferentes... O IP principal nao precisa ser colocado no alias.

Agora arrume as rotas. Primeiro o loopback, depois os varios IPs comecando com o padrao:

/sbin/route add -net 127.0.0.0 
/sbin/route add -net 196.16.3.0 dev eth0
/sbin/route add -host 196.16.3.1 dev eth0
/sbin/route add -host 196.16.3.10 dev eth0:0
/sbin/route add -host 196.16.3.100 dev eth0:1
/sbin/route add default gw 196.16.3.200

E e' isso ae!

Ah... peraih!

Neste exemplo eu uso so 3 IPs. O numero maximo ta' definido pra 256 no arquivo /usr/include/linux/net_alias.h. 256 IPs e' MUITA coisa! :P

Aqui ta como o meu /sbin/ifconfig e':

lo        Link encap:Local Loopback 
inet addr:127.0.0.1 Bcast:196.255.255.255 Mask:255.0.0.0
UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1
RX packets:5088 errors:0 dropped:0 overruns:0
TX packets:5088 errors:0 dropped:0 overruns:0

eth0 Link encap:10Mbps Ethernet HWaddr 00:8E:B8:83:19:20
inet addr:196.16.3.1 Bcast:196.16.3.255 Mask:255.255.255.0
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:334036 errors:0 dropped:0 overruns:0
TX packets:11605 errors:0 dropped:0 overruns:0
Interrupt:7 Base address:0x378

eth0:0 Link encap:10Mbps Ethernet HWaddr 00:8E:B8:83:19:20
inet addr:196.16.3.10 Bcast:196.16.3.255 Mask:255.255.255.0
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0
TX packets:0 errors:0 dropped:0 overruns:0

eth0:1 Link encap:10Mbps Ethernet HWaddr 00:8E:B8:83:19:20
inet addr:196.16.3.100 Bcast:196.16.3.255 Mask:255.255.255.0
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:1 errors:0 dropped:0 overruns:0
TX packets:0 errors:0 dropped:0 overruns:0

O /proc/net/aliases:

device family address
eth0:0 2 196.16.3.10
eth0:1 2 196.16.3.100

O /proc/net/alias_types:

type name n_attach
2 ip 2

E, claro, as coisas do /proc/net foram criadas pelo ifconfig e nao manualmente.

E como fazer para que sempre que o micro for iniciado isto ser feito automaticamente?

Creio que no seu sistema tenha um arquivo /etc/rc.d/rc.local. Coloque nele mais ou menos isto:

#arrumando os IP aliases 
echo "Arrumando os aliases: 196.16.3.1, 196.16.3.10, 196.16.3.100 ..."
/sbin/ifconfig lo 127.0.0.1
/sbin/ifconfig eth0 up
/sbin/ifconfig eth0 196.16.3.1
/sbin/ifconfig eth0:0 196.16.3.10
/sbin/ifconfig eth0:1 196.16.3.100
#roteando...
echo "Roteando ..."
/sbin/route add -net 127.0.0.0
/sbin/route add -net 196.16.3.0 dev eth0
/sbin/route add -host 196.16.3.1 eth0
/sbin/route add -host 196.16.3.10 eth0:0
/sbin/route add -host 196.16.3.100 eth0:1
/sbin/route add default gw 196.16.3.200
#

Altere o que for necessario.

E como eu faco para a maquina que esta usando o alias para receber e-mail para outros aliases(usando sendmail)?

Crie um arquivo chamado, por exemplo, de /etc/mynames.cw. Ele nao precisa ter este nome ou estar no /etc. Neste arquivo, coloque os nomes de dominios oficiais dos IPs com alias. Se estes IPs nao tem um dominio, voce pode colocar apenas o numero do IP.

/etc/mynames.cw: 
----------------
# /etc/mynames.cw - tem todos os alias da sua maquina
dominio.um.mil
dominio.dois.com
dominio.tres.org
4.5.6.7

No seu arquivo sendmail.cf, onde temdefinida a classe da macro Fw, coloque o seguinte:

. 
.
.
##################
# local info #
##################
.
.
# arquivo que contem nomes dos hosts que receberao e-mail
Fw/etc/mynames.cw
.
.
.

Isto deve servir. Teste a configuracao chamando o sendmail no modo de teste por exemplo:

$ /usr/lib/sendmail -bt 
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter < ruleset> < address>
> 0 me@4.5.6.7
rewrite: ruleset 0 input: me @ 4 . 5 . 6 . 7
rewrite: ruleset 98 input: me @ 4 . 5 . 6 . 7
rewrite: ruleset 98 returns: me @ 4 . 5 . 6 . 7
rewrite: ruleset 97 input: me @ 4 . 5 . 6 . 7
rewrite: ruleset 3 input: me @ 4 . 5 . 6 . 7
rewrite: ruleset 96 input: me < @ 4 . 5 . 6 . 7 >
rewrite: ruleset 96 returns: me < @ 4 . 5 . 6 . 7 . >
rewrite: ruleset 3 returns: me < @ 4 . 5 . 6 . 7 . >
rewrite: ruleset 0 input: me < @ 4 . 5 . 6 . 7 . >
rewrite: ruleset 98 input: me < @ 4 . 5 . 6 . 7 . >
rewrite: ruleset 98 returns: me < @ 4 . 5 . 6 . 7 . >
rewrite: ruleset 0 returns: $# local $: me
rewrite: ruleset 97 returns: $# local $: me
rewrite: ruleset 0 returns: $# local $: me
> 0 me@4.5.6.8
rewrite: ruleset 0 input: me @ 4 . 5 . 6 . 8
rewrite: ruleset 98 input: me @ 4 . 5 . 6 . 8
rewrite: ruleset 98 returns: me @ 4 . 5 . 6 . 8
rewrite: ruleset 97 input: me @ 4 . 5 . 6 . 8
rewrite: ruleset 3 input: me @ 4 . 5 . 6 . 8
rewrite: ruleset 96 input: me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 96 returns: me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 3 returns: me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 0 input: me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 98 input: me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 98 returns: me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 95 input: < > me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 95 returns: me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 0 returns: $# smtp $@ 4 . 5 . 6 . 8 $: me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 97 returns: $# smtp $@ 4 . 5 . 6 . 8 $: me < @ 4 . 5 . 6 . 8 >
rewrite: ruleset 0 returns: $# smtp $@ 4 . 5 . 6 . 8 $: me < @ 4 . 5 . 6 . 8 >
>

Ta tudo certinho agora... ajudei em algo? Espero que sim! :P

Cacaio               Cacaio@DeathKnights.com 
`'`'`' `'`'`'`'`'`'`'`'`'`'`'`

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT