aelius Posted March 8, 2014 Report Posted March 8, 2014 (edited) Stiu ca toti sunteti tentati sa faceti alias-uri, insa in cazul in care aveti sa spunem 200 de adrese ip de configurat pe un server, nu cred ca veti sta sa scrieti cele 200 de linii intr-un script de init. Mai mult, la comanda 'ifconfig -a' or sa fie afisate ca alias-uri (adica, mai pe romaneste, o sa vomite prima interfata de retea + 200 de alias-uri ale acesteia in CLI).Exemplu standard:root@rst:~# ifconfig eth0:1 10.0.0.2 netmask 255.255.255.0root@rst:~# ifconfig eth0:2 10.0.0.3 netmask 255.255.255.0root@rst:~# ifconfig eth0:3 10.0.0.4 netmask 255.255.255.0root@rst:~# ifconfig eth0:4 10.0.0.5 netmask 255.255.255.0root@rst:~# ifconfig eth0 Link encap:Ethernet HWaddr 08:00:27:02:c0:f1 inet addr:192.168.0.77 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe02:c0f1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2014 errors:0 dropped:0 overruns:0 frame:0 TX packets:1105 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:181623 (177.3 KiB) TX bytes:157231 (153.5 KiB)eth0:1 Link encap:Ethernet HWaddr 08:00:27:02:c0:f1 inet addr:10.0.0.2 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1eth0:2 Link encap:Ethernet HWaddr 08:00:27:02:c0:f1 inet addr:10.0.0.3 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1eth0:3 Link encap:Ethernet HWaddr 08:00:27:02:c0:f1 inet addr:10.0.0.4 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1eth0:4 Link encap:Ethernet HWaddr 08:00:27:02:c0:f1 inet addr:10.0.0.5 Bcast:10.0.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 TX bytes:0 (0.0 root@rst:~# Idee:root@rst:~# for i in {2..30} ; do ip addr add 10.0.0.$i broadcast 10.0.0.255 dev eth0 ; doneroot@rst:~# ifconfig -aeth0 Link encap:Ethernet HWaddr 08:00:27:02:c0:f1 inet addr:192.168.0.77 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe02:c0f1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2522 errors:0 dropped:0 overruns:0 frame:0 TX packets:1405 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:225333 (220.0 KiB) TX bytes:204095 (199.3 KiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 TX bytes:0 (0.0 root@rst:~# ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:02:c0:f1 brd ff:ff:ff:ff:ff:ff inet 192.168.0.77/24 brd 192.168.0.255 scope global eth0 inet 10.0.0.2/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.3/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.4/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.5/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.6/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.7/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.8/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.9/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.10/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.11/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.12/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.13/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.14/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.15/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.16/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.17/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.18/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.19/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.20/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.21/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.22/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.23/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.24/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.25/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.26/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.27/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.28/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.29/32 brd 10.0.0.255 scope global eth0 inet 10.0.0.30/32 brd 10.0.0.255 scope global eth0 inet6 fe80::a00:27ff:fe02:c0f1/64 scope link valid_lft forever preferred_lft foreverroot@rst:~# Din cate vedeti, la ifconfig imi este afisata o singura adresa ip. No alias, no shits.Cum ar arata fisierul de configuratie al retelei in cazul in care utilizati alias-uri pe eth0 si aveti o gramada de adrese ip ?auto eth0allow-hotplug eth0iface eth0 inet static address 192.168.0.42 netmask 255.255.255.0 gateway 192.168.1.1auto eth0:0allow-hotplug eth0:0iface eth0:0 inet static address 192.168.0.43 netmask 255.255.255.0auto eth0:1allow-hotplug eth0:1iface eth0:1 inet static address 192.168.0.44 netmask 255.255.255.0..............................................Pentru a face permanente modificarile (sa se configureze adresele ip la restart):root@rst:~# cat >> /etc/ipaddr << EOF> #!/bin/bash> for i in {2..30} ; do ip addr add 10.0.0.\$i broadcast 10.0.0.255 dev eth0 ; done> EOFroot@rst:~# chmod 711 /etc/ipaddrIn fisierul '/etc/network/interfaces' adaugati:post-up /etc/ipaddrExemplu:# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).# The loopback network interfaceauto loiface lo inet loopback# The primary network interfaceallow-hotplug eth0iface eth0 inet static address 192.168.0.77 netmask 255.255.255.0 gateway 192.168.0.1 post-up /etc/ipaddr Note: - Testele au fost facute pe Debian. Functioneaza pe Debian si orice distributie derivata din aceasta. - Comanda 'ip addr' functioneaza pe orice distributie linux. Face parte din pachetul iproute2- Tema, daca aveti fetishuri cu cititul: http://www.policyrouting.org/iproute2.doc.html Edited March 8, 2014 by aelius Quote
gogusan Posted March 10, 2014 Report Posted March 10, 2014 asteptam si tutorialul promis pentru firewall Quote
Nicotin Posted March 10, 2014 Report Posted March 10, 2014 O versiune si pentru centos ? :D:D:D Quote
aelius Posted March 10, 2014 Author Report Posted March 10, 2014 (edited) @Nicotin: pe centos ai range (iti autoconfigureaza el alias-uri)Pentru ip range pe Centos:cd /etc/sysconfig/network-scriptscat >> ifcfg-eth0-range0 << EOFTYPE="Ethernet"IPADDR_START=10.0.0.2IPADDR_END=10.0.0.200IPV6INIT=noEOFchmod 755 ifcfg-eth0-range0Note:- Asta o sa-ti faca alias-uri cu eth0:0, eth0:1 ..... pentru toate adresele ip de la 10.0.0.2 la 10.0.0.200- Nu adaugati in rc.local; Se initializeaza ultimul (dupa ce au pornit toate serviciile), caz in care serviciile ce se listeaza pe adresele ip configurate in rc.local, nu o sa porneasca.Pentru a implementa scriptul 'ipaddr' prezentat mai sus, poti arunca o privire aici: How to run a startup script automatically after a network interface is up on CentOS - Linux FAQ Edited March 11, 2014 by aelius Quote
sirsorin Posted March 18, 2014 Report Posted March 18, 2014 incercati si asta : OVH : IpAlias este si pt centos si pt debian etc.mie imi merge bine asta. Quote
aelius Posted March 18, 2014 Author Report Posted March 18, 2014 incercati si asta : OVH : IpAlias este si pt centos si pt debian etc.mie imi merge bine asta.Aia era ideea, sa eviti eth0:0, eth0:1 ... etchttps://www.dropbox.com/s/9b7ey7s5tsbyrzm/Screenshot%202014-03-18%2013.28.30.png Quote