administration unix - cours jussieu - 2009-2010

470
Administration de systèmes UNIX Formation ARS 2009 – 2010 Partie 3 Thierry Besançon Formation Permanente de l’Université Pierre et Marie Curie c T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 1 / 803

Upload: atlantis75007

Post on 26-Jul-2015

223 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Administration UNIX - Cours Jussieu - 2009-2010

Administration de systèmes UNIXFormation ARS 2009 – 2010

Partie 3Thierry Besançon

Formation Permanente de l’UniversitéPierre et Marie Curie

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 1 / 803

Page 2: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 1

Ethernet

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 2 / 803

1 Ethernet 1.1 Principe d’Ethernet : CSMA/CDChapitre 1 • Ethernet§1.1 • Principe d’Ethernet : CSMA/CD

Le principe d’Ethernet : Carrier Sence Multiple Access / Collision Detect(CSMA/CD)

2 cas de figure :1 Emission dans le cas du câble libre2 Emission lorsque deux stations émettent simultanément = collision

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 3 / 803

Page 3: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.1 Principe d’Ethernet : CSMA/CD

� Emission dans le cas du câble libre

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 4 / 803

1 Ethernet 1.1 Principe d’Ethernet : CSMA/CD

� Collision lorsque deux stations émettent simultanément

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 5 / 803

Page 4: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.2 Ethernet 10 Base 5Chapitre 1 • Ethernet§1.2 • Ethernet 10 Base 5

Cablage obsolète

� � � � � �� � � � � � � �

� � � � � � �� � � � � � � � � � �

� � �� � � � � � � � � �

� � �� � � � �

� � � � � � � � � � � � � � � � � � � � � � � � � � � � �

� � � � � � � � �� � ! � � � � � � � � � �

� � �

" � � � � � � � � � # � � �

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 6 / 803

1 Ethernet 1.2 Ethernet 10 Base 5

DTE DTE DTE

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 7 / 803

Page 5: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.2 Ethernet 10 Base 5

� Un ensemble monté

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 8 / 803

1 Ethernet 1.2 Ethernet 10 Base 5

� Une prise vampire démontée

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 9 / 803

Page 6: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.2 Ethernet 10 Base 5

� Le cable AUI, une prise vampire et son transceiver

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 10 / 803

1 Ethernet 1.2 Ethernet 10 Base 5

� Connecteurs 10 Base 5 sur un mini-transceiver et un drop cable

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 11 / 803

Page 7: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.2 Ethernet 10 Base 5

� Carte combo 10Base5 et 10BaseT

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 12 / 803

1 Ethernet 1.2 Ethernet 10 Base 5

� Mini transceiver low profile 10Base5 - RJ45

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 13 / 803

Page 8: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.2 Ethernet 10 Base 5

� Mini transceiver low profile 10Base5 - RJ45 au dos d’une machine

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 14 / 803

1 Ethernet 1.3 Ethernet 10 Base 2Chapitre 1 • Ethernet§1.3 • Ethernet 10 Base 2

Cablage obsolète

� � � � � �

� � � � � � � � � � � � �

Male BNC 50 Ohm� � � � � � � �

� � � � � � � � � � � � � �� � � � � � � � � � � �

� � � � � � � � � � �

� � � � � � � � � � �

� � � � � � �� � � � � � � � � � !"# � � � � � � � � � � � �

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 15 / 803

Page 9: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.3 Ethernet 10 Base 2

DTE

DTE

DTE

DTE

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 16 / 803

1 Ethernet 1.3 Ethernet 10 Base 2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 17 / 803

Page 10: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.3 Ethernet 10 Base 2

� Sertissage d’une prise 10Base2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 18 / 803

1 Ethernet 1.3 Ethernet 10 Base 2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 19 / 803

Page 11: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.3 Ethernet 10 Base 2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 20 / 803

1 Ethernet 1.3 Ethernet 10 Base 2

La prise sertie

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 21 / 803

Page 12: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.3 Ethernet 10 Base 2

� Raccordement : té 10Base2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 22 / 803

1 Ethernet 1.3 Ethernet 10 Base 2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 23 / 803

Page 13: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.3 Ethernet 10 Base 2

� En fin de cable : terminateur 50 Ohms 10Base2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 24 / 803

1 Ethernet 1.3 Ethernet 10 Base 2

� Carte combo 10Base2 et 10BaseT

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 25 / 803

Page 14: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.4 Ethernet 10 Base T, 100 Base TChapitre 1 • Ethernet§1.4 • Ethernet 10 Base T, 100 Base T

10 Base T = Cablage obsolète� � � � � � � � � � � � � � � � � �

���

���

���

���

���

� � � � � � � �

� � � � � � � � �� � � � � � � � � � � � � �

� � ! � � � � � ! " � ! !# � � � $ � � � � � � � � � � � �

� � � � � � � � � � � � � � �

% % %%

� � � � & ' ( )

BNC

* � & & � � � � �+ , )

� + , ) � � � & � - � � & � ! � � , � � . �� � & / - � � & � ! � � , � � � �� � & 0 - � � � � � � � , � � . �� � & 1 - � � � � � � � , � � � �

2 � 3 � � & � �) & � � � # � �

+ ' (��4

5 � � 3 ) & � � � & � + ' (

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 26 / 803

1 Ethernet 1.4 Ethernet 10 Base T, 100 Base T

HUB

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 27 / 803

Page 15: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.4 Ethernet 10 Base T, 100 Base T

� Prise à sertir

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 28 / 803

1 Ethernet 1.4 Ethernet 10 Base T, 100 Base T

� Cable croisé pour relier deux ordinateurs entre eux ou deux switches

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 29 / 803

Page 16: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.4 Ethernet 10 Base T, 100 Base T

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 30 / 803

1 Ethernet 1.5 Format d’une adresse EthernetChapitre 1 • Ethernet§1.5 • Format d’une adresse Ethernet

Format d’une adresse Ethernet : 6 octets écrits sous la forme hexadécimale« xx:yy:zz:rr:ss:tt » avec :

partie « xx:yy:zz » : elle identifie un constructeurpartie « rr:ss:tt » : elle identifie un appareil chez le constructeur

Liste des constructeurs : liste des OUI (Organizationally UniqueIdentifiers) : « http://standards.ieee.org/regauth/oui/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 31 / 803

Page 17: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.5 Format d’une adresse Ethernet

Il existe une adresse de broadcast Ethernet : « ff:ff:ff:ff:ff:ff »Toutes les machines du segment Ethernet sont censées écouter le paquet.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 32 / 803

1 Ethernet 1.6 Trouver son adresse Ethernet sur UNIX/LINUXChapitre 1 • Ethernet§1.6 • Trouver son adresse Ethernet sur UNIX/LINUX

Pour trouver son adresse Ethernet sur UNIX/LINUX : plusieurs méthodes :

1 repérer les périphériques dans la sortie de « dmesg » au moment duboot

2 utiliser la commande de configuration des interfaces pour visualiser lesadresses Ethernet

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 33 / 803

Page 18: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.6 Trouver son adresse Ethernet sur UNIX/LINUX

� Méthode via « dmesg »

# dmesg...

Intel(R) PRO/1000 Network Driver - version 7.2.7-k2-NAPI

Copyright (c) 1999-2006 Intel Corporation.

e1000: 0000:02:01.0: e1000_probe: (PCI-X:66MHz:64-bit) 00:11:09:5a:f0:d8e1000: eth0: e1000_probe: Intel(R) PRO/1000 Network Connection

...

e1000: 0000:02:01.1: e1000_probe: (PCI-X:66MHz:64-bit) 00:11:09:5a:f0:d9e1000: eth1: e1000_probe: Intel(R) PRO/1000 Network Connection

...

Attention à ne pas attendre trop longtemps pour ne pas perdre le contenude « dmesg ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 34 / 803

1 Ethernet 1.6 Trouver son adresse Ethernet sur UNIX/LINUX� Méthode via « dmesg »

# ifconfig -aeth0 Link encap:Ethernet HWaddr 00:11:09:5A:F0:D8

inet addr:134.157.13.95 Bcast:134.157.13.127 Mask:255.255.255.192

inet6 addr: fe80::211:9ff:fe5a:f0d8/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:12923628 errors:0 dropped:0 overruns:0 frame:0

TX packets:6317041 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:2836026670 (2.6 GiB) TX bytes:3564552940 (3.3 GiB)

Base address:0x2000 Memory:d0100000-d0120000

eth1 Link encap:Ethernet HWaddr 00:11:09:5A:F0:D9BROADCAST MULTICAST MTU:1500 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:1000

RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

Base address:0x2040 Memory:d0120000-d0140000

...

C’est la méthode la plus universelle.c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 35 / 803

Page 19: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.7 Trouver son adresse Ethernet sur WINDOWSChapitre 1 • Ethernet§1.7 • Trouver son adresse Ethernet sur WINDOWS

Commande « getmac.exe » à partir de MICROSOFT Windows XP.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 36 / 803

1 Ethernet 1.8 Format d’une trame EthernetChapitre 1 • Ethernet§1.8 • Format d’une trame Ethernet

Trame Ethernet == Paquet Ethernet

62 bits

2 bits

6 bytes

6 bytes

2 bytes

4 bytes

de 46 bytes

à

1500 bytes

Série alternée de 0 et de 1

Série de 2 bits à 1

Adresse de destination

Adresse de l’émetteur

Longueur du paquet (standard 802.3)Type du paquet (standard Ethernet)

Données

Frame Check Sequence

Taille de la trame : 18 octetsd’entête + au maximum 1500octets de données = 1518 octets

La capacité de 1500 octets estappelée MTU (MaximumTransmission Unit).

Il existe des Jumbo frames : tramede 9000 octets de données. Souventnon supporté par les équipementsréseau. A éviter.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 37 / 803

Page 20: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.9 Address Resolution Protocol (ARP)Chapitre 1 • Ethernet§1.9 • Address Resolution Protocol (ARP)

RFC 826

Le protocole ARP apporte la réponse à « comment dialoguer avec uneautre machine IP du même brin Ethernet sans connaitre au préalable sonadresse Ethernet ».

Synthétiquement le protocole fonctionne ainsi :Je suis la machine d’adresse IP IP1 et d’adresse Ethernet MAC1.Ecoutez moi tous sur le brin Ethernet. Je veux dialoguer avec lamachine d’adresse IP IP2. Que la machine avec cette adresse IP mecommunique son adresse Ethernet MAC2.J’ai bien entendu. Je suis la machine avec IP2. Voici mon adresseEthernet MAC2.Les autres machines en profitent pour noter la réponse.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 38 / 803

1 Ethernet 1.9 Address Resolution Protocol (ARP)

QUI A L’ADRESSEIP a.b.c.d ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 39 / 803

Page 21: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.9 Address Resolution Protocol (ARP)

J’AI L’ADRESSEIP a.b.c.d

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 40 / 803

1 Ethernet 1.10 Table ARP : commande arp, /proc/net/arpChapitre 1 • Ethernet§1.10 • Table ARP : commande arp, /proc/net/arp

Syntaxe : « arp -a » ou « arp -an »

Exemple :

% arp -a

Net to Media Table: IPv4

Device IP Address Mask Flags Phys Addr

------ -------------------- --------------- ----- ---------------

eri0 solaris.example.org 255.255.255.255 SP 00:03:ba:0f:15:35

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 41 / 803

Page 22: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.10 Table ARP : commande arp, /proc/net/arp

Autre façon d’obtenir la table ARP d’une machine LINUX :

% cat /proc/net/arpIP address HW type Flags HW address Mask Device

134.157.46.254 0x1 0x2 00:02:7E:21:F7:9C * eth0

192.168.4.18 0x1 0x2 00:48:54:6B:E5:B0 * eth3

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 42 / 803

1 Ethernet 1.11 Réglages ARP : commande arpChapitre 1 • Ethernet§1.11 • Réglages ARP : commande arp

Syntaxes de la commande « arp » :1 « arp -a » pour lister les adresses MAC connues2 « arp -d hostname » pour effacer une adresse MAC du cache ARP3 « arp -s hostname adresse-ethernet » pour mettre en cache

une adresse MAC

Pourquoi les options 2 et 3 ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 43 / 803

Page 23: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.11 Réglages ARP : commande arp

Exemple : configuration initiale d’un boitier ethernet / parallèle (ou USB)pour une imprimante :

On connait l’adresse MAC du boitier (par exemple impression surl’imprimante moyennant une combinaison de touche) ; par exemple« 11:22:33:44:55:66 »On associe alors cette adresse MAC à une adresse IP sur la machineoù l’on se trouve : « arp -s 192.168.1.1 11:22:33:44:55:66 »On peut alors se connecter en IP pour finir de configurer le boitier

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 44 / 803

1 Ethernet 1.12 Surveillance ARP : commande arpwatchChapitre 1 • Ethernet§1.12 • Surveillance ARP : commande arpwatch

« http://www.arpwatch.org »

ARPWATCH surveille les échanges du protocole ARP et stocke lesadresses échangées.

Attention : forte utilisation des switches désormais ⇒ difficile d’écouter lespaquets qui ne nous sont pas destinés

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 45 / 803

Page 24: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.12 Surveillance ARP : commande arpwatch

� Détection d’une nouvelle machine

Date: Tue, 17 Feb 2009 16:07:40 +0100 (CET)

From: [email protected] (Arpwatch)

To: [email protected]

Subject: new station

hostname: <unknown>

ip address: 134.157.52.51

ethernet address: 0:1e:68:be:93:32

ethernet vendor: <unknown>

timestamp: Tuesday, February 17, 2009 16:07:39 +0100

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 46 / 803

1 Ethernet 1.12 Surveillance ARP : commande arpwatch

� Changement d’adresse Ethernet sur une machine

Date: Tue, 17 Feb 2009 16:11:07 +0100 (CET)

From: [email protected] (Arpwatch)

To: [email protected]

Subject: changed ethernet address (host-12-08.dhcp.math.jussieu.fr)

hostname: host-12-08.dhcp.math.jussieu.fr

ip address: 134.157.12.8

ethernet address: 0:1e:68:be:93:32

ethernet vendor: <unknown>

old ethernet address: 0:3:93:42:72:de

old ethernet vendor: <unknown>

timestamp: Tuesday, February 17, 2009 16:11:07 +0100

previous timestamp: Tuesday, February 17, 2009 13:22:08 +0100

delta: 2 hours

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 47 / 803

Page 25: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.12 Surveillance ARP : commande arpwatch

� Flip flop d’adresses

Date: Tue, 17 Feb 2009 16:11:54 +0100 (CET)

From: [email protected] (Arpwatch)

To: [email protected]

Subject: flip flop

hostname: <unknown>

ip address: 0.0.0.0

ethernet address: 0:3:93:3:8e:b8

ethernet vendor: <unknown>

old ethernet address: 0:1f:5b:f6:29:90

old ethernet vendor: <unknown>

timestamp: Tuesday, February 17, 2009 16:11:53 +0100

previous timestamp: Tuesday, February 17, 2009 16:11:14 +0100

delta: 39 seconds

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 48 / 803

1 Ethernet 1.13 (Windows : : purge du cache ARP : netsh)Chapitre 1 • Ethernet§1.13 • (Windows : : purge du cache ARP : netsh)

Une machine WINDOWS utilise un cache ARP comme n’importe quelleautre machine faisant de l’IP.

On peut purger le cache ARP par la commande« netsh interface ip delete arpcache ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 49 / 803

Page 26: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.14 Reverse Address Resolution Protocol (RARP)Chapitre 1 • Ethernet§1.14 • Reverse Address Resolution Protocol (RARP)

(en anglais Reverse Address Resolution Protocol)

Le protocole répond à « je suis la machine d’adresse Ethernet MAC1 ; quipeut me donner mon adresse IP ? ».

Exemple de telles machines :stations UNIX sans disque (dite diskless)terminaux X, clients légersimprimantes réseauwebcams réseauboitiers ethernet/USB ou ethernet/parallèle pour imprimante

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 50 / 803

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclientChapitre 1 • Ethernet§1.15 • DHCP, dhcpd, dhcpd.conf, dhclient

Question RARP : « je suis la machine d’adresse Ethernet MAC1 ; qui peutme donner mon adresse IP ? ».

Réponse : Dynamic Host Configuration Protocol (DHCP)

RFC 2131 et RFC 2132« http://www.lip6.fr/pub/rfc/rfc/rfc2131.txt »« http://www.lip6.fr/pub/rfc/rfc/rfc2132.txt »

Port TCP 67 (port d’écoute du serveur)Port TCP 68 (port de réponse du serveur)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 51 / 803

Page 27: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

On distingue :

le serveur DHCP : à l’écoute surses interfaces réseau, il distribuepar son autorité des adresses IPrésidant dans des plages

le DHCP relay agent : il sait routerles paquets IP du protocole DHCPentre un client et un serveur

le client DHCP : il utilise leprotocole DHCP pour découvrirson adresse IP et d’autresparamètres réseau ou autresparamètres (dits DHCP options ;par exemple le serveur NTP)

DHCP agent

DHCP

DHCP

CLIENT

SERVER

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 52 / 803

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

� Protocole DHCP

Principe :

DHCPDISCOVER (broadcast)

DHCPOFFER (unicast)

DHCPACK (unicast)

DHCPREQUEST (broadcast)

CLIENTDHCP

SERVEURDHCP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 53 / 803

Page 28: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

Principe :1 Une machine démarre dans l’état « INIT »2 Elle cherche un serveur DHCP en envoyant un paquet

« DHCPDISCOVER ».3 Un ou plusieurs serveurs DHCP répondent par un paquet

« DHCPOFFER » contenant une adresse IP et des options DHCP.4 Le client sélectionne un serveur DHCP parmi ceux qui ont répondu.

Par exemple, le premier.5 Le client broadcaste un paquet « DHCPREQUEST » spécifiant l’adresse

IP retenue.6 Le serveur retenu répond au client en lui envoyant un paquet

« DHCPACK ».7 Après, le client posséde l’adresse IP pour un laps de temps appelé

lease.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 54 / 803

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

Lorsqu’une machine qui a obtenu une adresse IP via DHCP reboote, ellene recommence pas exactement les étapes ci-dessus. Elle commence dansl’état « INIT-REBOOT ». Elle envoie un paquet « DHCPREQUEST »reprenant l’adresse précédemment acquise. En cas de disponibilité del’adresse, le serveur répond par « DHCPACK ». En cas de non disponibilité(par exemple, le portable a changé de réseau), un serveur DHCP répondpar « DHCPNACK ». A ce moment-là, la machine reprend à l’étape 1 deci-dessus.

Mécanisme de détection de duplicate IP address :le serveur DHCP envoie un paquet « ICMP Echo » ; en cas deréponse, le serveur propose une autre adressele client DHCP envoie un paquet « ARP » ; en cas de réponse, le clientenvoie un paquet « DHCPDECLINE » ; le serveur proposera alors unenouvelle adresse

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 55 / 803

Page 29: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

� Faiblesses du protocole DHCP

Denial of Service possible ; « DHCPDISCOVER » puis « DHCPNAK »jusqu’à épuisement des numéros libres sur le serveur DHCP parexemplesingle point of failure ; pas de mécanisme de serveur DHCP de secourspas d’authentification du client au serveur et vice-versainadéquation de l’adresse MAC comme Client Identifier ; par exempleun portable et un dock, une carte PCMCIA réseau

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 56 / 803

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

� ISC DHCP

« http://www.isc.org/products/DHCP/ »« ftp://ftp.isc.org/isc/dhcp/dhcp-3.0pl1.tar.gz »

Version 3 : supporte le Dynamic DNS Update, l’authentification DHCPPeut répondre à des requêtes BOOTP.

Fichier de configuration : en général « /etc/dhcp.conf »

En cas de modification au fichier de configuration, il faut arrêter le démon« dhcpd » et le relancer (par exemple « /etc/rc.d/dhcp restart »).Pas de « SIGHUP » pour le reconfigurer on the fly.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 57 / 803

Page 30: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

Exemple de « /etc/dhcpd.conf » :

ddns-update-style none;

always-reply-rfc1048 on;

option domain-name-servers 192.168.1.1;

option domain-name "jardiniers.org";

option subnet-mask 255.255.255.0;

option broadcast-address 192.168.1.255;

option log-servers 192.168.1.1;

subnet 192.168.1.0 netmask 255.255.255.0 {

range 192.168.1.200 192.168.1.210;

default-lease-time 120;

max-lease-time 180;

}

host gutenberg {

# Apple 12/640

hardware ethernet 08:00:07:24:46:59;

fixed-address 192.168.1.2;

}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 58 / 803

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

Le serveur écrit les leases sur disque : « /var/run/dhcpd.leases » ;ancienne base « dhcpd.leases~ »

Exemple de « /var/run/dhcpd.leases » :

# All times in this file are in UTC (GMT), not your local timezone. This is

# not a bug, so please don’t ask about it. There is no portable way to

# store leases in the local timezone, so please don’t request this as a

# feature. If this is inconvenient or confusing to you, we sincerely

# apologize. Seriously, though - don’t ask.

# The format of this file is documented in the dhcpd.leases(5) manual page.

# This lease file was written by isc-dhcp-V3.0.1rc6

lease 192.168.1.210 {

starts 0 2002/09/08 22:57:10;

ends 0 2002/09/08 22:59:10;

binding state active;

next binding state free;

hardware ethernet 00:04:76:48:4f:65;

}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 59 / 803

Page 31: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

Sur Red Hat Linux, on peut dire à la machine de configurer son adresseréseau via DHCP au niveau de« /etc/sysconfig/network-scripts/ifcfg-eth0 » :

DEVICE = eth0

IPADDR = 0.0.0.0

NETMASK = 255.255.255.0

NETWORK =

BROADCAST = 0.0.0.255

GATEWAY = none

ONBOOT = yes

DYNAMIC = dhcp

Une machine UNIX utilisant DHCP fait tourner « dhclient »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 60 / 803

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

Possibilité d’avoir une configuration du comportement DHCP du client aumoyen du fichier « /etc/dhclient.conf ». Par exemple :

timeout 60;

retry 60;

reboot 10;

select-timeout 5;

initial-interval 2;

reject 192.33.137.209;

interface "ep0" {

send host-name "andare.fugue.com";

send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;

send dhcp-lease-time 3600;

supersede domain-name "fugue.com rc.vix.com home.vix.com";

prepend domain-name-servers 127.0.0.1;

request subnet-mask, broadcast-address, time-offset, routers,

domain-name, domain-name-servers, host-name;

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 61 / 803

Page 32: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

Suite :

...

require subnet-mask, domain-name-servers;

script "/sbin/dhclient-script";

media "media 10baseT/UTP", "media 10base2/BNC";

}

alias {

interface "ep0";

fixed-address 192.5.5.213;

option subnet-mask 255.255.255.255;

}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 62 / 803

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

� Options DHCP pour clients Microsoft

Cf : « http://www.microsoft.com/windows2000/en/server/help/\

default.asp?url=/windows2000/en/server/help/\

sag_DHCP_add_OptionsMsVendorSpecific.htm »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 63 / 803

Page 33: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

� Exemple de dialogue DHCPScenario : une machine A fonctionne en mode DHCP. On change sa carteréseau et la machine continue de fonctionner en mode DHCP.Au niveau du serveur DHCP, on voit :

Sep 27 17:58:22 dhcp.example.com dhcpd: [ID 702911 daemon.info] DHCPREQUEST for 192.168.1.11 from 00:0c:29:44:44:0d via eri0: lease 192.168.1.11 unavailable.

Sep 27 17:58:22 dhcp.example.com dhcpd: [ID 702911 daemon.info] DHCPNAK on 192.168.1.11 to 00:0c:29:44:44:0d via eri0

Sep 27 17:58:31 dhcp.example.com dhcpd: [ID 702911 daemon.info] DHCPDISCOVER from 00:0c:29:44:44:0d via eri0

Sep 27 17:58:31 dhcp.example.com dhcpd: [ID 702911 daemon.info] DHCPOFFER on 192.168.1.13 to 00:0c:29:44:44:0d via eri0

Sep 27 17:58:31 dhcp.example.com dhcpd: [ID 702911 daemon.info] DHCPREQUEST for 192.168.1.13 (192.168.1.1) from 00:0c:29:44:44:0d via eri0

Sep 27 17:58:31 dhcp.example.com dhcpd: [ID 702911 daemon.info] DHCPACK on 192.168.1.13 to 00:0c:29:44:44:0d via eri0

1 la machine A réclame l’adresse IP qu’elle obtenait avec sa carteréseau précd́ente

2 le serveur refuse cette adresse car il attribue les adresses en modestatique (une adresse ethernet bien précise = une adresse IP bienprécise)

3 la machine demande donc poliment une adresse IP au serveur DHCP4 le serveur DHCP propose une adresse IP5 la machine accepte la machine et confirme l’adresse IP au serveur

DHCP6 le serveur DHCP prend note de l’affectation de l’adresse IPc©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 64 / 803

1 Ethernet 1.15 DHCP, dhcpd, dhcpd.conf, dhclient

� Outils satellites pour DHCP

Quelques outils :

logiciel « dhcpdump » :« http://www.mavetju.org/download/dhcpdump-1.4.tar.gz »logiciel « dhcping » :« http://www.mavetju.org/download/dhcping-1.2.tar.gz »# ./dhcping -c 195.220.117.6 -s 195.220.117.22 -h 8:0:20:cf:62:12

Got answer from: 195.220.117.22

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 65 / 803

Page 34: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.16 Mode promiscuousChapitre 1 • Ethernet§1.16 • Mode promiscuous

En théorie une carte réseau n’écoute que les paquets qui lui sont destinés.

Si une carte Ethernet est en mode promiscuous, elle peut capturer despaquets qui ne lui sont pas destinés.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 66 / 803

1 Ethernet 1.16 Mode promiscuous

� FREEBSD

La commande « ifconfig » indique l’état promiscuous en cas delancement d’un programme faisant passer en mode promiscuous :

# ifconfig -a...

bge1: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500

options=1b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING>

inet 134.157.13.124 netmask 0xffffffc0 broadcast 134.157.13.127

inet 134.157.13.102 netmask 0xffffffff broadcast 134.157.13.102

inet 192.168.1.1 netmask 0xffff0000 broadcast 192.168.255.255

ether 00:19:bb:21:2f:01

media: Ethernet autoselect (1000baseTX <full-duplex>)

status: active

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 67 / 803

Page 35: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.16 Mode promiscuous

Le passage en mode promiscuous est aussi notifié par le noyau qui remontel’information via « dmesg » :

# dmesg...

bge1: promiscuous mode enabled...

bge1: promiscuous mode disabled...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 68 / 803

1 Ethernet 1.16 Mode promiscuous

� LINUX

La commande « ifconfig » n’indique pas l’état promiscuous en cas delancement d’un programme faisant passer en mode promiscuous :

# ifconfig -a...

eth0 Link encap:Ethernet HWaddr 00:11:09:5A:F0:D8

inet addr:134.157.13.95 Bcast:134.157.13.127 Mask:255.255.255.192

inet6 addr: fe80::211:9ff:fe5a:f0d8/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:12923628 errors:0 dropped:0 overruns:0 frame:0

TX packets:6317041 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:100

RX bytes:2836026670 (2.6 GiB) TX bytes:3564552940 (3.3 GiB)

Base address:0x2000 Memory:d0100000-d0120000

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 69 / 803

Page 36: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.16 Mode promiscuous

Le passage en mode promiscuous est notifié par le noyau qui remontel’information via « dmesg » :

# dmesg...

device eth0 entered promiscuous mode...

device eth0 left promiscuous mode...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 70 / 803

1 Ethernet 1.16 Mode promiscuous

� SOLARIS

La commande « ifconfig » n’indique pas l’état promiscuous en cas delancement d’un programme faisant passer en mode promiscuous :

# snoop -d eri0Using device /dev/eri (promiscuous mode)

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 71 / 803

Page 37: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.17 Capture de trames Ethernet : librairie libpcapChapitre 1 • Ethernet§1.17 • Capture de trames Ethernet : librairie libpcap

(en anglais library packet capture)

Cf « http://www.tcpdump.org »

C’est une bibliothèque de programmation C spécialisée dans la capture depaquets réseau.

Elle repose sur un driver réseau présent dans le noyau, le packet filter BPF.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 72 / 803

1 Ethernet 1.18 Capture de trames Ethernet : tcpdumpChapitre 1 • Ethernet§1.18 • Capture de trames Ethernet : tcpdump

Cf « http://www.tcpdump.org »

C’est le logiciel de référence en ce qui concerne l’analyse des trames IPcirculant sur un réseau. Il est bâti au dessus de la libpcap qui fait tout letravail en fait. C’est juste de l’enrobage au dessus de libpcap.

En cas de problème réseau, on utilisera ce logiciel si l’origine du problèmen’est pas évidente.

Exemple :

# tcpdump -s 1500 host www.example.com# tcpdump -s 1500 arp# tcpdump -s 1500 icmp# tcpdump -s 1500 dst sgbd.example.com port 5432

# tcpdump -s 1500 -w fichier# tcpdump -s 1500 -r fichier

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 73 / 803

Page 38: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.19 Capture de trames Ethernet : wireshark (ethereal)Chapitre 1 • Ethernet§1.19 • Capture de trames Ethernet : wireshark (ethereal)

« http://www.wireshark.com »

Ancien nom : « ethereal » (« http://www.ethereal.com »)

C’est un logiciel graphique d’analyse des trames IP circulant sur un réseau.

On l’utilise conjointement à tcpdump :1 on demande à « tcpdump » d’enregistrer les trames :

« tcpdump -s 1500 -w enregistrement »2 on demande à « ethereal » de relire a posteriori ce fichier

d’enregistrement :« ethereal enregistrement »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 74 / 803

1 Ethernet 1.19 Capture de trames Ethernet : wireshark (ethereal)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 75 / 803

Page 39: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.20 (Windows : : capture de trames Ethernet : wireshark.exe)Chapitre 1 • Ethernet§1.20 • (Windows : : capture de trames Ethernet : wireshark.exe)

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 76 / 803

1 Ethernet 1.21 Wake On LanChapitre 1 • Ethernet§1.21 • Wake On Lan

Sur les machines modernes, la carte réseau reste alimentée électriquement⇒ la carte réseau peut alors démarrer la carte mère sur réception depaquets réseau spéciaux et démarrer l’OS = Wake On Lan

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 77 / 803

Page 40: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.21 Wake On Lan

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 78 / 803

1 Ethernet 1.21 Wake On Lan

Manifestement dépend aussi dudriver de la carte réseau :

Manifestement dépend aussi de labonne qualité du driver de la carteréseau :

Salle de TP de la FormationPermanenteCarte mère ASUS P4P800XBoot de Windows ; shutdownpropre ⇒ WOL possibleBoot de Mandriva 2006 ;shutdown propre ⇒ WOLimpossible

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 79 / 803

Page 41: Administration UNIX - Cours Jussieu - 2009-2010

1 Ethernet 1.21 Wake On Lan

Comment contacter une machine ?

Envoi d’un paquet Ethernet spécial :paquet UDP à destination du port discard le plus souventcontenu du paquet UDP (dit magic sequence) :

6 fois « 0xFF »16 fois l’adresse Ethernet

Par exemple, pour réveiller la carte d’adresse « 01:02:03:04:05:06 » :

FFFFFFFFFFFF010203040506010203040506010203040506010203040506

010203040506010203040506010203040506010203040506010203040506

010203040506010203040506010203040506010203040506010203040506

010203040506010203040506

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 80 / 803

1 Ethernet 1.21 Wake On Lan

Logiciels :

« wakeonlan » :« http://gsd.di.uminho.pt/jpo/software/wakeonlan/ »

« wakeonlan » : « http://www.moldaner.de/wakeonlan/ »(« java -jar wakeonlan.jar -i 192.168.0.255 01:02:03:04:05:06 »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 81 / 803

Page 42: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 2

Protocole IP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 82 / 803

2 Protocole IP 2.1 IP v4 / IP v6Chapitre 2 • Protocole IP§2.1 • IP v4 / IP v6

Plusieurs versions de TCP/IP :

1 IP version 42 IP version 6

IP version 6 : revu plus tard page 165

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 83 / 803

Page 43: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.2 Adresses IPChapitre 2 • Protocole IP§2.2 • Adresses IP

Quelques caractéristiques :protocole IP version 4adresse IP sur 4 octets « a.b.c.d »a, b, c, d sont compris entre 0 et 255 et écrits en base 10 pour éviterdes erreurs% man 3 inet

...

All numbers supplied as ‘‘parts’’ in a ‘.’ notation may be decimal, oc-

tal, or hexadecimal, as specified in the C language (i.e., a leading 0x

or 0X implies hexadecimal; otherwise, a leading 0 implies octal; other-

wise, the number is interpreted as decimal).

...

des organismes attribuent des lots d’adresses aux sociétés (pour laFrance AFNIC : « http://www.afnic.asso.fr »)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 84 / 803

2 Protocole IP 2.3 Adresses de réseaux : classes A, B et CChapitre 2 • Protocole IP§2.3 • Adresses de réseaux : classes A, B et C

Notion de classes d’adresses : A, B et C :

Classe Format des adresses

A

7 bits 24 bits

0 netid hostid

0.0.0.0 à 127.255.255.255

B

16 bits14 bits

1 0 netid hostid

128.0.0.0 à 191.255.255.255

C

21 bits 8 bits

01 1 netid hostid

192.0.0.0 à 223.255.255.255

Devient obsolète.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 85 / 803

Page 44: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.4 Adresses de réseaux : sous-réseaux, écriture CIDRChapitre 2 • Protocole IP§2.4 • Adresses de réseaux : sous-réseaux, écriture CIDR

(en anglais subnets)

Un sous-réseau = découpage plus fin ou plus large que les classes A, B ouC.

Le principe reste le même :une longueur N de bits imposésune longueur 32 - N de bits laissés variables

Ecriture d’une adresse réseau : « adresse-du-réseau/N »(écriture dite CIDR, Class Inter Domain Routing)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 86 / 803

2 Protocole IP 2.4 Adresses de réseaux : sous-réseaux, écriture CIDR

Par exemple : « 134.157.13.128/25 »

Signification :25 bits imposés32 - 25 = 7 bits variables

134.157.13.128 = 10000110.10011101.00001101.10000000

<----------- 25 -----------><- 7 ->

Conclusion : les adresses disponibles sur ce subnet vont de« 10000110.10011101.00001101.10000000 » (134.157.13.128) à« 10000110.10011101.00001101.11111111 » (134.157.13.255).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 87 / 803

Page 45: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.4 Adresses de réseaux : sous-réseaux, écriture CIDR

Combien d’adresses IP utilisables par sous-réseau ?

Réponse : si N bits variables alors 2N − 2 :l’adresse avec tous les bits variables à 0 est réservée pour désigner lesous-réseaul’adresse avec tous les bits variables à 1 est réservée pour désignerl’adresse de broadcast (voir page 96)

Par exemple : « 134.157.13.128/25 »128 adresses dans le sous-réseau27 − 2 = 128− 2 = 126 adresses utilisables pour des machines

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 88 / 803

2 Protocole IP 2.4 Adresses de réseaux : sous-réseaux, écriture CIDR

Combien d’adresses IP utilisables par sous-réseau ?

Masque Nombres d’adresses Nombre d’adresses utilisables

CIDR

/ 8 224 = 16777216 224 − 2 = 16777214

/ 16 216 = 65536 216 − 2 = 65534

/ 24 28 = 256 28 − 2 = 254

/ 25 27 = 128 27 − 2 = 126

/ 26 26 = 64 26 − 2 = 62

/ 27 25 = 32 25 − 2 = 30

/ 28 24 = 16 24 − 2 = 14

/ 29 23 = 8 23 − 2 = 6

/ 30 22 = 4 22 − 2 = 2

/ 31 21 = 2 21 − 2 = 0

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 89 / 803

Page 46: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.5 Masque réseau, netmaskChapitre 2 • Protocole IP§2.5 • Masque réseau, netmask

Le problème : comment la station A construit-elle les paquets Ethernetpour dialoguer avec la machine B, où que soit la station B ?

Deux cas de figure :1 A et B sont sur le même réseau Ethernet local : A peut envoyer un

paquet Ethernet directement à B2 A et B ne sont pas sur le même réseau Ethernet local : A doit passer

par un routeur intermédiaire. Il faut alors construire un paquet avecpour adresse Ethernet de destination l’adresse Ethernet du routeur etnon pas avec l’adresse Ethernet de B.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 90 / 803

2 Protocole IP 2.5 Masque réseau, netmask

Comment diagnostiquer si A et B sont sur le même réseau Ethernet oupas ?

La solution : A et B sont sur le même réseau physique si IP(A) et IP(B)partagent une même propriété : avoir la même adresse de réseau.

On calcule l’adresse de réseau d’une adresse A en appliquant un masquede bits sur l’adresse IP de A.

Le masque de bits est appelé le masque de réseau de A (ou netmask).

IP(A) & netmask(A) = adresse-réseau(A)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 91 / 803

Page 47: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.5 Masque réseau, netmask

Comment diagnostiquer si A et B sont sur le même réseau Ethernet oupas ?En l’occurence si :

IP(A) & netmask(A) = IP(B) & netmask(A)

(avec « & » désignant le « ET logique »)

Rappel sur le ET logique :

bit A 0 1 0 1bit B 0 0 1 1bit A ET bit B 0 0 0 1

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 92 / 803

2 Protocole IP 2.5 Masque réseau, netmask

Le netmask se construit ainsi :la partie fixe des bits est mise à 1la partie variable des bits est mise à 0

Bits Masque

00000000 0

10000000 128

11000000 192

11100000 224

11110000 240

11111000 248

11111100 252

11111110 254

11111111 255

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 93 / 803

Page 48: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.5 Masque réseau, netmask

� Exemple 1 : réseau « 134.157.13.128/25 »

Netmask : « 255.255.255.128 »

A : 134.157.13.129

A : 10000110.10011101.00001101.10000001

netmask(A) : 11111111.11111111.11111111.10000000

<----------- 25 -----------><- 7 ->

A & netmask(A) : 10000110.10011101.00001101.10000000

B : 134.157.13.130

B : 10000110.10011101.00001101.10000010

netmask(A) : 11111111.11111111.11111111.10000000

<----------- 25 -----------><- 7 ->

B & netmask(A) : 10000110.10011101.00001101.10000000

Donc les machines sont sur le même réseau.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 94 / 803

2 Protocole IP 2.5 Masque réseau, netmask

� Exemple 2 : réseau « 134.157.13.128/25 »

Netmask : « 255.255.255.128 »

A : 134.157.13.129

A : 10000110.10011101.00001101.10000001

netmask(A) : 11111111.11111111.11111111.10000000

<----------- 25 -----------><- 7 ->

A & netmask(A) : 10000110.10011101.00001101.10000000

B : 134.157.0.129

B : 10000110.10011101.00000000.10000001

netmask(A) : 11111111.11111111.11111111.10000000

<----------- 25 -----------><- 7 ->

B & netmask(A) : 10000110.10011101.00000000.10000000

Donc les machines ne sont pas sur le même réseau.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 95 / 803

Page 49: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.6 Adresse de broadcast IPChapitre 2 • Protocole IP§2.6 • Adresse de broadcast IP

Chaque machine IP écoute un paquet IP avec l’adresse de broadcast pouradresse de destination et répond peut-être suivant le type du paquet.

Construction de l’adresse de broadcast d’une machine A dans le réseau« réseau/N » :

les bits de la longueur N de bits restent inchangésles 32 - N bits (variables dans le subnet) sont mis à 1

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 96 / 803

2 Protocole IP 2.6 Adresse de broadcast IP

� Exemple 1 : réseau « 134.157.12.0/24 »

A : 134.157.12.3

A : 10000110.10011101.00001100.00000011

<----------- 24 ----------><- 8 -->

netmask(A) : 11111111.11111111.11111111.00000000

broadcast(A) : 10000110.10011101.00001100.11111111

broadcast(A) : 134.157.12.255

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 97 / 803

Page 50: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.6 Adresse de broadcast IP

� Exemple 2 : réseau « 134.157.13.128/25 »

A : 134.157.13.129

A : 10000110.10011101.00001101.10000001

<----------- 25 -----------><- 7 ->

netmask(A) : 11111111.11111111.11111111.10000000

broadcast(A) : 10000110.10011101.00001101.11111111

broadcast(A) : 134.157.13.255

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 98 / 803

2 Protocole IP 2.6 Adresse de broadcast IP

� Exemple 3 : réseau « 134.157.13.64/26 »

A : 134.157.13.71

A : 10000110.10011101.00001101.01000111

<----------- 26 ------------><- 6->

netmask(A) : 11111111.11111111.11111111.11000000

broadcast(A) : 10000110.10011101.00001101.01111111

broadcast(A) : 134.157.13.127

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 99 / 803

Page 51: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.7 Unicast, Broadcast, MulticastChapitre 2 • Protocole IP§2.7 • Unicast, Broadcast, Multicast

� Diffusion unicast

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 100 / 803

2 Protocole IP 2.7 Unicast, Broadcast, Multicast

� Diffusion broadcast

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 101 / 803

Page 52: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.7 Unicast, Broadcast, Multicast

� Diffusion multicast

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 102 / 803

2 Protocole IP 2.8 Adresse spéciale : adresse de loopbackChapitre 2 • Protocole IP§2.8 • Adresse spéciale : adresse de loopback

Interface virtuelle de loopback d’adresse IP « 127.0.0.1 »

L’adresse « 127.0.0.1 » est appelée « localhost ».

Permet de faire des connexions réseau avec soi-même.

INTERNET

Adresse IPa.b.c.d Adresse IP

127.0.0.1APPL2APPL1

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 103 / 803

Page 53: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.8 Adresse spéciale : adresse de loopback

� Adresse de loopback sur UNIX/LINUX

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 104 / 803

2 Protocole IP 2.8 Adresse spéciale : adresse de loopback

� Adresse de loopback sur WINDOWS

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 105 / 803

Page 54: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.9 Adresses spéciales : adresses privées / RFC 1918Chapitre 2 • Protocole IP§2.9 • Adresses spéciales : adresses privées / RFC 1918

RFC 1918 : adresses privées :« 10.0.0.0/8 »« 172.16.0.0/12 »« 192.168.0.0/16 »

Adresses utilisables sur des réseaux sans interconnexion avec Internet ouavec NAT (Network Address Translation ; par exemple : boites ADSL).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 106 / 803

2 Protocole IP 2.10 Adresses spéciales : autres adresses / RFC 3330Chapitre 2 • Protocole IP§2.10 • Adresses spéciales : autres adresses / RFC 3330

RFC 3330 :

Adresses Réseau Documentation« 0.0.0.0/8 » "This" Network RFC1700, page 4« 10.0.0.0/8 » Private-Use Networks RFC1918« 14.0.0.0/8 » Public-Data Networks RFC1700, page 181« 24.0.0.0/8 » Cable Television Networks –« 39.0.0.0/8 » Reserved but subject to al-

locationRFC1797

« 127.0.0.0/8 » Loopback RFC1700, page 5« 128.0.0.0/16 » Reserved but subject to al-

location–

« 169.254.0.0/16 » Link Local –« 172.16.0.0/12 » Private-Use Networks RFC1918« 191.255.0.0/16 » Reserved but subject to al-

location–

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 107 / 803

Page 55: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.10 Adresses spéciales : autres adresses / RFC 3330

RFC 3330 (suite) :

Adresses Réseau Documentation« 192.0.0.0/24 » Reserved but subject to al-

location–

« 192.0.2.0/24 » Test-Net –« 192.88.99.0/24 » 6to4 Relay Anycast RFC3068« 192.168.0.0/16 » Private-Use Networks RFC1918« 198.18.0.0/15 » Network Interconnect De-

vice Benchmark TestingRFC2544

« 223.255.255.0/24 » Reserved but subject to al-location

« 224.0.0.0/4 » Multicast RFC3171« 240.0.0.0/4 » Reserved for Future Use RFC1700, page 4

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 108 / 803

2 Protocole IP 2.11 Encapsulation des paquetsChapitre 2 • Protocole IP§2.11 • Encapsulation des paquets

Principe des poupées russes.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 109 / 803

Page 56: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.11 Encapsulation des paquets

headerEthernet

trailerEthernetdata

Trame Ethernet

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 110 / 803

2 Protocole IP 2.11 Encapsulation des paquets

headerEthernet

trailerEthernet

Trame Ethernet

Trame ARP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 111 / 803

Page 57: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.11 Encapsulation des paquets

headerEthernet

trailerEthernet

Trame Ethernet

Trame IP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 112 / 803

2 Protocole IP 2.11 Encapsulation des paquets

headerEthernet

trailerEthernet

Trame Ethernet

Trame IP

headerIP

Trame UDP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 113 / 803

Page 58: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.11 Encapsulation des paquets

headerEthernet

trailerEthernet

Trame Ethernet

Trame IP

headerIP

Trame TCP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 114 / 803

2 Protocole IP 2.11 Encapsulation des paquets

headerEthernet

trailerEthernet

Trame Ethernet

Trame IP

headerIP

Trame ICMP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 115 / 803

Page 59: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.12 Configuration d’adresse IP : ifconfigChapitre 2 • Protocole IP§2.12 • Configuration d’adresse IP : ifconfig

(en anglais interface configuration)

La commande « ifconfig » sert à régler les paramètres des cartes réseau :

# ifconfig le0 inet 134.157.253.1# ifconfig le0 netmask 0xffffff80# ifconfig le0 broadcast 134.157.253.127# ifconfig -alo0: flags=849<UP,LOOPBACK,RUNNING,MULTICAST> mtu 8232

inet 127.0.0.1 netmask ff000000

le0: flags=863<UP,BROADCAST,NOTRAILERS,RUNNING,MULTICAST> mtu 1500

inet 134.157.253.1 netmask ffffff80 broadcast 134.157.253.127

ether 8:0:20:83:12:4a

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 116 / 803

2 Protocole IP 2.12 Configuration d’adresse IP : ifconfig

Sur une machine Linux, les cartes réseau ont pour noms « eth0 »,« eth1 », « eth2 », etc.

Sur une machine Linux, la paramètrage réseau de la carte « eth0 » setrouve au niveau du fichier« /etc/sysconfig/network-scripts/ifcfg-eth0 » (ainsi de suitepour les autres interfaces) :

DEVICE=eth0

BOOTPROTO=static

BROADCAST=134.157.46.255

IPADDR=134.157.46.129

NETMASK=255.255.255.128

NETWORK=134.157.46.128

ONBOOT=yes

GATEWAY=134.157.46.254

TYPE=Ethernet

USERCTL=no

PEERDNS=no

La commande « dmesg » renvoie la liste des interfaces.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 117 / 803

Page 60: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.12 Configuration d’adresse IP : ifconfig

Sur une machine SOLARIS, les cartes réseau ont des noms dépendant dutype de carte. Par exemple « le0 », « eri0 », « qfe0 » + « qfe1 » +« qfe2 » + « qfe3 » (carte quad port 10/100), etc.

Sur une machine SOLARIS, la paramètrage réseau de la carte XYZ setrouve au niveau du fichier « /etc/hostname.XYZ » :

-rw-r--r-- 1 root root 19 Dec 4 01:35 /etc/hostname.eri0

qui contient le hostname associé à la carte : hostname → adresse réseauvia « /etc/hosts »

Broadcast, netmask déduits

La commande « dmesg » renvoie la liste des interfaces.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 118 / 803

2 Protocole IP 2.13 Adresses IP virtuellesChapitre 2 • Protocole IP§2.13 • Adresses IP virtuelles

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 119 / 803

Page 61: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.14 Configuration d’adresses IP virtuelles : ifconfigChapitre 2 • Protocole IP§2.14 • Configuration d’adresses IP virtuelles : ifconfig

Sur une machine Linux, si la carte réseau s’appelle par exemple « eth0 »,alors les adresses virtuelles utiliseront les interfaces réseau virtuelles denoms « eth0:0 », « eth0:1 », « eth0:2 », etc.

Sur une machine Linux, la paramètrage réseau de l’adresse virtuelle« eth0:0 » se trouve au niveau du fichier« /etc/sysconfig/network-scripts/ifcfg-eth0:0 » (ainsi de suitepour les autres interfaces) :

DEVICE=eth0:0BOOTPROTO=static

BROADCAST=134.157.46.255

IPADDR=134.157.46.130

NETMASK=255.255.255.128

NETWORK=134.157.46.128

ONBOOT=yes

TYPE=Ethernet

USERCTL=no

PEERDNS=no

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 120 / 803

2 Protocole IP 2.14 Configuration d’adresses IP virtuelles : ifconfig

Sur une machine SOLARIS, si la carte réseau s’appelle par exemple« eri0 », alors les adresses virtuelles utiliseront les interfaces réseauvirtuelles de noms « eri0:1 », « eri0:2 », « eri0:3 », etc.

Sur une machine SOLARIS, la paramètrage réseau d’une interfacevirtuelle « eri0:1 » se trouvera donc au niveau du fichier« /etc/hostname.eri0:1 » :

-rw-r--r-- 1 root root 19 Dec 4 01:35 /etc/hostname.eri0:1

qui contient le hostname associé à l’interface virtuelle :hostname → adresse réseau via « /etc/host »

Broadcast, netmask déduits

Manuellement « ifconfig eri0 addif 192.168.0.1/prefix up »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 121 / 803

Page 62: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.15 (Windows 98 : : winipcfg.exe)Chapitre 2 • Protocole IP§2.15 • (Windows 98 : : winipcfg.exe)

La commande « winipcfg.exe » permet de connaitre en mode graphiquela configuration réseau des interfaces.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 122 / 803

2 Protocole IP 2.15 (Windows 98 : : winipcfg.exe)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 123 / 803

Page 63: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.16 (Windows : : ipconfig.exe)Chapitre 2 • Protocole IP§2.16 • (Windows : : ipconfig.exe)

La commande « ipconfig.exe » permet de connaitre en mode ligne decommande la configuration réseau des interfaces.

interfacesDHCPetc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 124 / 803

2 Protocole IP 2.16 (Windows : : ipconfig.exe)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 125 / 803

Page 64: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.16 (Windows : : ipconfig.exe)

� Libération d’une adresse DHCP / Renouvellement d’une adresse DHCP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 126 / 803

2 Protocole IP 2.17 (Windows : : netsh.exe)Chapitre 2 • Protocole IP§2.17 • (Windows : : netsh.exe)

La commande « netsh » permet de configurer en mode ligne decommande beaucoup d’aspects réseau :

configuration des interfacesconfiguration DHCPconfiguration du firewall Microsoftconfiguration WIFIconfiguration IPSECetc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 127 / 803

Page 65: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Désactivation d’une interface

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 128 / 803

2 Protocole IP 2.17 (Windows : : netsh.exe)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 129 / 803

Page 66: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Affichage de la configuration d’une interface

(on notera que c’est plus facile en anglais car le nom de l’interface estfacile à écrire)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 130 / 803

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Configuration manuelle d’une interface

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 131 / 803

Page 67: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Configuration via DHCP d’une interface

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 132 / 803

2 Protocole IP 2.17 (Windows : : netsh.exe)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 133 / 803

Page 68: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.17 (Windows : : netsh.exe)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 134 / 803

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Effacement de la table ARP de la machine

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 135 / 803

Page 69: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Sauvegarde de la configuration et rechargement ultérieur

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 136 / 803

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Ouverture sur le firewall d’un port

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 137 / 803

Page 70: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.17 (Windows : : netsh.exe)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 138 / 803

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Autorisation sur le firewall d’une application

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 139 / 803

Page 71: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.17 (Windows : : netsh.exe)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 140 / 803

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Affichage des applications autorisées sur le firewall

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 141 / 803

Page 72: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.17 (Windows : : netsh.exe)

� Affichage des ports autorisées sur le firewall

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 142 / 803

2 Protocole IP 2.18 Connexions IP / ports IPChapitre 2 • Protocole IP§2.18 • Connexions IP / ports IP

Une connexion IP est constituée des éléments suivants :

une adresse IP sourceun numéro de port source sur la machine de départune adresse IP de destinationun numéro de port sur la machine de destinationprotocole TCP ou UDP

IP1 IP2

port 2

port 1

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 143 / 803

Page 73: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.18 Connexions IP / ports IP

En pratique il y a 3 catégories de port :Les Well Known Ports de 0 à 1023Les Registered Ports de 1024 à 49151Les Dynamic and/or Private Ports de 49152 à 65535

Attention :Sur UNIX, la fonction C obtenant un port source < 1024 nefonctionne que pour l’UID 0.Sur Windows, la fonction C obtenant un port source < 1024fonctionne quel que soit l’UID

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 144 / 803

2 Protocole IP 2.19 Fichier /etc/servicesChapitre 2 • Protocole IP§2.19 • Fichier /etc/services

Le fichier « /etc/services » mentionne des triplets (numéro de port,protocole, nom du service).

On peut obtenir un triplet officiellement pour un programme à soi auprèsde l’IANA « http://www.iana.org/assignments/port-numbers »

Le fichier « /etc/services » sert à convertir un port numérique en unnom symbolique plus parlant. Voir les fonctions C « getservbyname() »,« getservbyport() », « getservent() ».

ATTENTION : Le fichier « /etc/services »n’indique pas les services réseau activés sur lamachine.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 145 / 803

Page 74: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.19 Fichier /etc/services

Extrait d’un fichier « /etc/services » :

...

chargen 19/tcp ttytst source #Character Generator

chargen 19/udp ttytst source #Character Generator

ftp-data 20/tcp #File Transfer [Default Data]

ftp-data 20/udp #File Transfer [Default Data]

ftp 21/tcp #File Transfer [Control]

ftp 21/udp #File Transfer [Control]

ssh 22/tcp #Secure Shell Login

ssh 22/udp #Secure Shell Login

telnet 23/tcp

telnet 23/udp

smtp 25/tcp mail #Simple Mail Transfer

smtp 25/udp mail #Simple Mail Transfer

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 146 / 803

2 Protocole IP 2.20 Liste des ports réseau actifs : netstat -a, netstat -anChapitre 2 • Protocole IP§2.20 • Liste des ports réseau actifs : netstat -a, netstat -an

La commande « netstat -a » renvoie la liste des connexions réseauétablies ou en attente d’établissement de connexion. Les noms affichésproviennent de « /etc/services » :

% netstat -aActive Internet connections (including servers)

Proto Recv-Q Send-Q Local Address Foreign Address (state)

tcp4 0 0 *.ssh *.* LISTEN

tcp46 0 0 *.ssh *.* LISTEN

udp4 0 0 *.syslog *.*udp6 0 0 *.syslog *.*udp4 0 0 *.bootpc *.*Active UNIX domain sockets

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 147 / 803

Page 75: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.20 Liste des ports réseau actifs : netstat -a, netstat -an

La commande « netstat -an » renvoie la liste des connexions réseauétablies ou en attente d’établissement de connexion, sans les traduire ennoms via « /etc/services ». Ils sont affichés sous forme numérique :

% netstat -anActive Internet connections (including servers)

Proto Recv-Q Send-Q Local Address Foreign Address (state)

tcp4 0 0 *.22 *.* LISTEN

tcp46 0 0 *.22 *.* LISTEN

udp4 0 0 *.514 *.*udp6 0 0 *.514 *.*udp4 0 0 *.68 *.*Active UNIX domain sockets

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 148 / 803

2 Protocole IP 2.21 (Windows : : Liste des ports réseau actifs : netstat.exe)Chapitre 2 • Protocole IP§2.21 • (Windows : : Liste des ports réseau actifs : netstat.exe)

Même principe sur UNIX :

Microsoft Windows XP [Version 5.1.2600]

(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\ars>netstat -an | more

Active Connections

Proto Local Address Foreign Address State

TCP 0.0.0.0:25 0.0.0.0:0 LISTENING

TCP 0.0.0.0:80 0.0.0.0:0 LISTENING

TCP 0.0.0.0:135 0.0.0.0:0 LISTENING

TCP 0.0.0.0:443 0.0.0.0:0 LISTENING

TCP 0.0.0.0:445 0.0.0.0:0 LISTENING

TCP 0.0.0.0:1025 0.0.0.0:0 LISTENING

TCP 127.0.0.1:1027 0.0.0.0:0 LISTENING

TCP 192.168.1.1:139 0.0.0.0:0 LISTENING

TCP 192.168.2.1:139 0.0.0.0:0 LISTENING

TCP 192.168.8.1:139 0.0.0.0:0 LISTENING

UDP 0.0.0.0:445 *:*UDP 0.0.0.0:500 *:*

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 149 / 803

Page 76: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.22 Liste des connexions réseau : lsofChapitre 2 • Protocole IP§2.22 • Liste des connexions réseau : lsof

(en anglais List of open files)

ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/

« lsof » permet de connaître les filedescriptors ouverts sur une machineUNIX. Cela comprend les connexions réseau.

Par exemple, pour voir quels processus utilisent la partition « /var/run » :

% lsof /var/runCOMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

lpd 410 daemon 6u VREG 0,1 4 2193737 /var/run (swap)

dhcpd 12548 root 6w VREG 0,1 469 1571881 /var/run (swap)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 150 / 803

2 Protocole IP 2.22 Liste des connexions réseau : lsof

Par exemple pour voir qui utilise une certaine connexion TCP :

% lsof -i tcp:32771COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

inetd 320 root 18u IPv4 0x3000200f350 0t0 TCP *:32771 (LISTEN)

Par exemple pour voir qui utilise une certaine connexion UDP :

% lsof -i [email protected]:3853COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

ss_logd 232 root 3u IPv4 0x30001d961c0 0t0 UDP localhost:3853 (Idle)

(format « [protocol][@hostname|hostaddr][:service|port] »)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 151 / 803

Page 77: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.23 (Windows : : Liste des connexions réseau : tcpview.exe)Chapitre 2 • Protocole IP§2.23 • (Windows : : Liste des connexions réseau : tcpview.exe)

Logiciel TCPVIEW sur « http://www.sysinternals.com ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 152 / 803

2 Protocole IP 2.23 (Windows : : Liste des connexions réseau : tcpview.exe)

TCPVIEW a une version en ligne de commande : TCPVCON

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 153 / 803

Page 78: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.24 Commande de connexion : telnetChapitre 2 • Protocole IP§2.24 • Commande de connexion : telnet

Syntaxe : telnet host

Exemples d’utilisation :connexion à une machine UNIXconnexion à une imprimanteconnexion à un équipement réseauetc.

A chaque fois que ce sera possible, préférer une connexion shelldistante en utilisant SSH.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 154 / 803

2 Protocole IP 2.24 Commande de connexion : telnet

Autre syntaxe importante : telnet host port

Exemples d’utilisation :connexion manuelle à un serveur POPconnexion manuelle à un serveur IMAPconnexion manuelle à un serveur HTTPetc.

Non remplaçable par SSH.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 155 / 803

Page 79: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.24 Commande de connexion : telnet

� Exemple : connexion à une machine UNIX

% telnet server.example.comTrying 1.2.3.4...

Connected to server.example.com.

Escape character is ’^]’.

SunOS 5.7

login: besancon

Password: XXXXXXXX

Last login: Sun Oct 12 15:18:22 from ppp-3

Sun Microsystems Inc. SunOS 5.5 Generic November 1995

server%

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 156 / 803

2 Protocole IP 2.24 Commande de connexion : telnet

� Exemple : connexion à une imprimante

% telnet hp4100.example.comTrying 1.2.3.4...

Connected to hp4100.example.com.

Escape character is ’^]’.

HP JetDirect

Password: XXXXXXXX

You are logged in

Please type "?" for HELP, or "/" for current settings

> /

===JetDirect Telnet Configuration===

Firmware Rev. : G.08.49

MAC Address : 00:30:c1:0a:45:b2

Config By : USER SPECIFIED

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 157 / 803

Page 80: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.24 Commande de connexion : telnet

IP Address : 1.2.3.4

Subnet Mask : 255.255.255.0

Default Gateway : 1.2.3.254

Syslog Server : Not Specified

Idle Timeout : 90 Seconds

Set Cmnty Name : Not Specified

Host Name : Not Specified

Default Get Cmnty : Enabled

DHCP Config : Disabled

Passwd : Enabled

IPX/SPX : Disabled

DLC/LLC : Disabled

Ethertalk : Enabled

Banner page : Disabled

> exit

EXITING WITHOUT SAVING ANY ENTRIES

> Connection closed by foreign host.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 158 / 803

2 Protocole IP 2.24 Commande de connexion : telnet

� Exemple : interruption d’une connexion par Ctrl-] (Control crochetfermant)

% telnet obsolete.example.comTrying 1.2.3.4...

Connected to obsolete.example.com.

Escape character is ’^]’.

telnet login: besancon

Password: XXXXXXXX

Login incorrect

login:

^] <-- taper Ctrl-]

telnet> quit

Connection closed.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 159 / 803

Page 81: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.24 Commande de connexion : telnet

� Exemple : tentative de connexion à une machine sans telnet

% telnet notelnet.example.comTrying 1.2.3.4...

telnet: connect to address 1.2.3.4: Connection refused

telnet: Unable to connect to remote host

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 160 / 803

2 Protocole IP 2.24 Commande de connexion : telnet

� Humour

Faire « telnet towel.blinkenlights.nl »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 161 / 803

Page 82: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.25 (Windows : : Commande de connexion : telnet.exe)Chapitre 2 • Protocole IP§2.25 • (Windows : : Commande de connexion : telnet.exe)

Programme « telnet.exe » :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 162 / 803

2 Protocole IP 2.26 Duplicate IP addressChapitre 2 • Protocole IP§2.26 • Duplicate IP address

Un problème régulier : les duplicate IP addresses :

deux machines sur le même réseau Ethernet ont la même adresse IP

Le pire scenario : l’usurpateur prend l’adresse du routeur par défaut.

Solution : tracer les adresses Ethernet au niveau des tables ARP desswitches

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 163 / 803

Page 83: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.26 Duplicate IP address

Symptôme d’un duplicate IP address : un Apple MacOS X affiche :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 164 / 803

2 Protocole IP 2.27 IP v6Chapitre 2 • Protocole IP§2.27 • IP v6

2e+08

4e+08

6e+08

8e+08

1e+09

1.2e+09

1.4e+09

1.6e+09

83 84 85 86 87 88 89 90 91 92 93

Add

ress

es a

lloca

ted

Year

Total address space allocated

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 165 / 803

Page 84: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.27 IP v6

5e+08

1e+09

1.5e+09

2e+09

2.5e+09

3e+09

3.5e+09

4e+09

4.5e+09

5e+09

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02 03 04 05 06 07 08 09

Add

ress

es a

lloca

ted

Year

Total address space allocated

Epuisement prévu des numéros IP ⇒ création de IP v6.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 166 / 803

2 Protocole IP 2.27 IP v6

From: James Carlson <[email protected]>

To: [email protected]

Subject: Re: (IPng) GENERAL IPNG ISSUES

Date: Mon, 26 Sep 94 07:29:53 -0400

>> PS why do people say that 16 bytes is enough to address the people

>> on the entire planet squillions of times over when addresses relate

>> to location geography?

16 bytes is 2^128 = 340,282,366,920,938,463,463,374,607,431,768,211,456.

This is a humorously large address space. Taking a SWAG at the size

of the Earth, about 201,062,400 square miles, this comes to around

1,692,421,690,584,308,470,720,406,239,216 addresses per square mile of

Earth’s surface, or about 421,578,297,421,497,485,189 addresses per

square inch.

Even if we chop off three bytes to indicate galaxy, solar system and

planet, we’d still have 25,128,024 addresses per square *mil* here on

Earth. Pathology will never be the same after every microbe has its

own address...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 167 / 803

Page 85: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.28 Annexe 1Chapitre 2 • Protocole IP§2.28 • Annexe 1

Ci joint dans la version imprimée de ce cours, un diagramme d’états deTCP/IP.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 168 / 803

Page 86: Administration UNIX - Cours Jussieu - 2009-2010
Page 87: Administration UNIX - Cours Jussieu - 2009-2010

2 Protocole IP 2.29 Annexe 2Chapitre 2 • Protocole IP§2.29 • Annexe 2

Ci joint dans la version imprimée de ce cours, un tableau du top 10% desAS fournissant des prefixes IPv6.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 169 / 803

Page 88: Administration UNIX - Cours Jussieu - 2009-2010

« http://bgpmon.net/blog/?p=228 »

Each network in the global Internet has a unique Autonomous System (AS) number. An Autonomous System canbe an Internet Service Provider (ISP), Enterprise network, content provider or any other sort of network. Each ASnumber announces one or more prefixes. By using Geo IP libraries we are able to determine a country for each prefix.This in turn allows us to determine the unique number of networks (AS numbers) per country. Doing this for both IPv4as well as IPv6 will result in the IPv4/IPv6 deployment ratio.

Let’s look at for example at Canada. There are 816 Autonomous Systems that originate a prefix registered as inuse in Canada. If we look at the IPv6 routing tables we see that 50 Autonomous Systems announce a Canadian IPv6prefix. This results in an IPv6 deployment percentage of 6.1

TAB. 1: Top 10%

Country code Country Ipv6 deployment rate Ipv6 network / Ipv4 networksJE Jersey 100% 1 / 1CU Cuba 75% 3 / 4OM Oman 50% 1 / 2MC Monaco 50% 1 / 2VA Holy See (Vatican City State) 50% 1 / 2FJ Fiji 50% 1 / 2TN Tunisia 33% 1 / 3ML Mali 33% 1 / 3UY Uruguay 31% 8 / 26EE Estonia 26% 10 / 39BT Bhutan 25% 1 / 4SN Senegal 25% 1 / 4IM Isle of Man 25% 1 / 4LU Luxembourg 24% 10 / 42LK Sri Lanka 23% 3 / 13IS Iceland 21% 6 / 29EU 20% 22 / 109CZ Czech Republic 19% 34 / 176NZ New Zealand 18% 35 / 194JP Japan 17% 92 / 545CI Cote D’Ivoire 17% 1 / 6NL Netherlands 17% 85 / 511MY Malaysia 17% 13 / 78MU Mauritius 17% 1 / 6VE Venezuela 16% 6 / 38PT Portugal 15% 11 / 75CR Costa Rica 15% 2 / 13TW Taiwan, Province of China 15% 18 / 122RW Rwanda 14% 1 / 7NO Norway 14% 17 / 120ZA South Africa 14% 13 / 92VI Virgin Islands, U.s. 14% 1 / 7HT Haiti 14% 1 / 7IE Ireland 14% 18 / 130MT Malta 13% 3 / 23DE Germany 13% 149 / 1183

Suite à la page suivante. . .

1

Page 89: Administration UNIX - Cours Jussieu - 2009-2010

TAB. 1: Top 10%

Country code Country Ipv6 deployment rate Ipv6 network / Ipv4 networksQA Qatar 13% 1 / 8LI Liechtenstein 13% 2 / 15VN Viet Nam 12% 6 / 50AN Netherlands Antilles 12% 2 / 17CH Switzerland 12% 51 / 437EG Egypt 11% 5 / 46SE Sweden 11% 38 / 344TT Trinidad and Tobago 11% 1 / 9SK Slovakia 10% 8 / 83

2

Page 90: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 3

Routage IP par défaut

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 170 / 803

3 Routage IP par défaut 3.1 Notion de routageChapitre 3 • Routage IP par défaut§3.1 • Notion de routage

Routage : acheminement des paquets IP à leur destination selon unchemin déterminé par la destination

Cas le plus simple : routage par défaut : tous les paquets IP sontacheminés vers un routeur qui les transmet plus loin.

Les autres cas : protocoles spécialisés : ROUTED, BGP, OSPF, etc. (voircours réseau)

Un cas très spécial : routage selon l’adresse IP source : policy basedroutingAttention : souvent un hack au niveau de l’OS !

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 171 / 803

Page 91: Administration UNIX - Cours Jussieu - 2009-2010

3 Routage IP par défaut 3.2 Relation entre routage IP et paquets ethernetChapitre 3 • Routage IP par défaut§3.2 • Relation entre routage IP et paquets ethernet

ETH = AA:BB:CC:11:11:11

ETH = 11:22:33:44:55:66

IP = 2.2.2.2

IP = 1.1.1.1

IP = 1.1.1.254

IP = 2.2.2..254ETH = AA:BB:CC:22:22:22

ROUTEUR

machine A

machine B

ETH src = 11:22:33:44:55:66ETH dest = AA:BB:CC:11:11:11

ETH src = AA:BB:CC:22:22:22ETH dest = 77:88:99:00:AA:BB

IP src = 1.1.1.1IP dest = 2.2.2.2

IP data

IP

ETH IP src = 1.1.1.1

IP dest = 2.2.2.2

IP data

IP

ETH IP src = 1.1.1.1

IP dest = 2.2.2.2

IP data

IPETH = 77:88:99:00:AA:BB

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 172 / 803

3 Routage IP par défaut 3.3 Routage par défautChapitre 3 • Routage IP par défaut§3.3 • Routage par défaut

Routage par défaut : tous les paquets IP sont acheminés vers un routeurqui les transmet plus loin.La destination du routage par défaut : le réseau « 0.0.0.0 »En utilisant la commande « netstat » (voir page ‘pagerefnetstat) etl’option « -n », on voit bien ce réseau spécial :

% netstat -rKernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

192.168.1.0 * 255.255.255.0 U 0 0 0 eth0

default 192.168.1.254 0.0.0.0 UG 0 0 0 eth0

% netstat -rnKernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 eth0

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 173 / 803

Page 92: Administration UNIX - Cours Jussieu - 2009-2010

3 Routage IP par défaut 3.4 Configuration du routage LINUX : routeChapitre 3 • Routage IP par défaut§3.4 • Configuration du routage LINUX : route

La commande « route » sert à configurer le routage.

# route add default gw 134.157.253.126

gw = gateway = routeur

Sur une machine LINUX, se reporter au fichier« /etc/sysconfig/network » :

NETWORKING=yes

FORWARD_IPV4=false

HOSTNAME=pcars5.formation.jussieu.fr

DOMAINNAME=formation.jussieu.fr

NISDOMAIN=real.world

GATEWAY=134.157.253.126GATEWAYDEV=eth0

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 174 / 803

3 Routage IP par défaut 3.5 Configuration du routage SOLARIS : routeChapitre 3 • Routage IP par défaut§3.5 • Configuration du routage SOLARIS : route

La commande « route » sert à configurer le routage.

# route add default 134.157.253.126

Sur une machine SOLARIS, se reporter au fichier « /etc/defaultrouter » :

134.157.253.126

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 175 / 803

Page 93: Administration UNIX - Cours Jussieu - 2009-2010

3 Routage IP par défaut 3.6 (Windows : : route.exe)Chapitre 3 • Routage IP par défaut§3.6 • (Windows : : route.exe)

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 176 / 803

3 Routage IP par défaut 3.7 Routage : netstatChapitre 3 • Routage IP par défaut§3.7 • Routage : netstat

La commande « netstat -r » renvoie la table de routage d’une machineUNIX :

% netstat -rn

Routing Table:

Destination Gateway Flags Ref Use Interface

-------------------- -------------------- ----- ----- ------ ---------

255.255.255.255 134.157.253.1 UGH 0 0

134.157.253.0 134.157.253.1 U 3 227555 le0

224.0.0.0 134.157.253.1 U 3 0 le0

default 134.157.253.126 UG 0 230176

127.0.0.1 127.0.0.1 UH 0 28650 lo0

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 177 / 803

Page 94: Administration UNIX - Cours Jussieu - 2009-2010

3 Routage IP par défaut 3.8 (Windows : : netstat.exe)Chapitre 3 • Routage IP par défaut§3.8 • (Windows : : netstat.exe)

Même principe sur UNIX :

C:\Documents and Settings\ars>netstat -rn

Route Table

===========================================================================

Interface List

0x1 ........................... MS TCP Loopback interface

0x2 ...00 50 56 c0 00 02 ...... VMware Virtual Ethernet Adapter for VMnet2

0x3 ...00 50 56 c0 00 08 ...... VMware Virtual Ethernet Adapter for VMnet8

0x4 ...00 50 56 c0 00 01 ...... VMware Virtual Ethernet Adapter for VMnet1

0x5 ...00 90 4b 64 10 88 ...... Dell TrueMobile 1400 Dual Band WLAN Mini-PCI Card - Packet Scheduler Miniport

0x6 ...00 0d 56 ad cc be ...... Broadcom 440x 10/100 Integrated Controller - Packet Scheduler Miniport

===========================================================================

===========================================================================

Active Routes:

Network Destination Netmask Gateway Interface Metric

127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1

192.168.1.0 255.255.255.0 192.168.1.1 192.168.1.1 20

192.168.1.1 255.255.255.255 127.0.0.1 127.0.0.1 20

192.168.1.255 255.255.255.255 192.168.1.1 192.168.1.1 20

192.168.2.0 255.255.255.0 192.168.2.1 192.168.2.1 20

192.168.2.1 255.255.255.255 127.0.0.1 127.0.0.1 20

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 178 / 803

3 Routage IP par défaut 3.8 (Windows : : netstat.exe)

192.168.2.255 255.255.255.255 192.168.2.1 192.168.2.1 20

192.168.8.0 255.255.255.0 192.168.8.1 192.168.8.1 20

192.168.8.1 255.255.255.255 127.0.0.1 127.0.0.1 20

192.168.8.255 255.255.255.255 192.168.8.1 192.168.8.1 20

224.0.0.0 240.0.0.0 192.168.1.1 192.168.1.1 20

224.0.0.0 240.0.0.0 192.168.2.1 192.168.2.1 20

224.0.0.0 240.0.0.0 192.168.8.1 192.168.8.1 20

255.255.255.255 255.255.255.255 192.168.1.1 192.168.1.1 1

255.255.255.255 255.255.255.255 192.168.2.1 192.168.2.1 1

255.255.255.255 255.255.255.255 192.168.8.1 192.168.8.1 1

255.255.255.255 255.255.255.255 192.168.8.1 6 1

255.255.255.255 255.255.255.255 192.168.8.1 5 1

===========================================================================

Persistent Routes:

None

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 179 / 803

Page 95: Administration UNIX - Cours Jussieu - 2009-2010

3 Routage IP par défaut 3.9 Test de connectivité : pingChapitre 3 • Routage IP par défaut§3.9 • Test de connectivité : ping

La commande « ping » teste si une machine répond au niveau réseau.

% ping localhostlocalhost is alive

On peut parfois pinger l’adresse de broadcast :

% /usr/sbin/ping -s 134.157.253.127 1PING 134.157.253.127: 1 data bytes

9 bytes from sunars1.formation.jussieu.fr (134.157.253.1): icmp_seq=0.

9 bytes from sunars2.formation.jussieu.fr (134.157.253.2): icmp_seq=0.

9 bytes from sunars4.formation.jussieu.fr (134.157.253.4): icmp_seq=0.

9 bytes from sunars3.formation.jussieu.fr (134.157.253.3): icmp_seq=0.

9 bytes from r-formation.formation.jussieu.fr (134.157.253.126): icmp_seq=0.

9 bytes from sunars1.formation.jussieu.fr (134.157.253.1): icmp_seq=1.

9 bytes from sunars2.formation.jussieu.fr (134.157.253.2): icmp_seq=1.

9 bytes from sunars4.formation.jussieu.fr (134.157.253.4): icmp_seq=1.

9 bytes from sunars3.formation.jussieu.fr (134.157.253.3): icmp_seq=1.

9 bytes from r-formation.formation.jussieu.fr (134.157.253.126): icmp_seq=1.

^C

----134.157.253.127 PING Statistics----

2 packets transmitted, 10 packets received, 5.00 times amplification

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 180 / 803

3 Routage IP par défaut 3.10 Test de connectivité : fping, hpingChapitre 3 • Routage IP par défaut§3.10 • Test de connectivité : fping, hping

Autres utilitaires parents de PING :

FPING : « http://fping.sourceforge.net »HPING : « http://www.hping.org »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 181 / 803

Page 96: Administration UNIX - Cours Jussieu - 2009-2010

3 Routage IP par défaut 3.11 (Windows : : ping.exe)Chapitre 3 • Routage IP par défaut§3.11 • (Windows : : ping.exe)

Même principe sur UNIX :

C:\Documents and Settings\ars>ping 127.0.0.1

Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 182 / 803

3 Routage IP par défaut 3.12 Test de connectivité : tracerouteChapitre 3 • Routage IP par défaut§3.12 • Test de connectivité : traceroute

La commande « traceroute » permet de tester si une machine estjoignable. Elle renvoie les intermédiaires réseau qui route notreacheminement vers la machine distante.Syntaxe : « traceroute machine »

% traceroute ftp.lip6.frtraceroute to nephtys.lip6.fr (195.83.118.1), 30 hops max, 40 byte packets

1 yacht (129.199.96.254) 0 ms 0 ms 0 ms

2 renater (129.199.1.10) 2 ms 1 ms 1 ms

3 195.221.127.61 (195.221.127.61) 3 ms 1 ms 1 ms

4 195.221.126.1 (195.221.126.1) 2 ms 1 ms 1 ms

5 195.221.126.78 (195.221.126.78) 2 ms 1 ms 1 ms

6 jussieu.rap.prd.fr (195.221.126.33) 2 ms 2 ms 2 ms

7 nephtys.lip6.fr (195.83.118.1) 2 ms 2 ms 2 ms

Le nombre d’intermédiaires n’est pas proportionnel à l’éloignementgéographique de la machine destination.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 183 / 803

Page 97: Administration UNIX - Cours Jussieu - 2009-2010

3 Routage IP par défaut 3.13 (Windows : : tracert.exe)Chapitre 3 • Routage IP par défaut§3.13 • (Windows : : tracert.exe)

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 184 / 803

3 Routage IP par défaut 3.14 Machine LINUX routeurChapitre 3 • Routage IP par défaut§3.14 • Machine LINUX routeur

Routeur LINUX = une machine LINUX avec deux cartes réseau

Les paquets réseau doivent être routés d’une interface réseau à une autreinterface réseau.

Activation via « /proc/sys/net/ipv4/ip_forward » :0 : les paquets ne sont pas routés d’une interface à une autre interface1 : les paquets sont routés d’une interface à une autre interface

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 185 / 803

Page 98: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 4

Domain Name Server (DNS)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 186 / 803

4 Domain Name Server (DNS) 4.1 Principes du DNSChapitre 4 • Domain Name Server (DNS)§4.1 • Principes du DNS

Impossibilité pratique de maintenir à jour les fichiers « /etc/hosts ».⇒ remplacement par un mécanisme d’annuaire réparti dont chacun gèresa entrée propre : le Domain Name Server

Particularités de la base de données du DNS :répartiepetiteavec une faible fréquence de changements des donnéeshiérarchiséeaccès en consultation uniquement ; pas de requête de modification

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 187 / 803

Page 99: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.2 Zone DNSChapitre 4 • Domain Name Server (DNS)§4.2 • Zone DNS

zone DNS : reflet de l’aspect réparti et hiérarchisé du DNS

partie contigüe de l’arbreune zone parente délègue une zone fille à un ou plusieurs serveursd’informations (nameservers) sur la zone fille

.

com net fr ...

wanadoo jussieu

formation... www

www ssh

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 188 / 803

4 Domain Name Server (DNS) 4.3 Requête d’interrogation du DNSChapitre 4 • Domain Name Server (DNS)§4.3 • Requête d’interrogation du DNS

Le DNS est bâti selon un modèle client – serveur

Cf logiciel DNSTRACER sur « http://www.mavetju.org »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 189 / 803

Page 100: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.3 Requête d’interrogation du DNS

Le DNS utilise des root nameservers :

Pour assurer un service fiable, une zone est servie par un nameserverprimaire et plusieurs nameservers secondaires de secours qui sesynchronisent entre eux.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 190 / 803

4 Domain Name Server (DNS) 4.3 Requête d’interrogation du DNS

Principe de mémorisation des informations passées recueillies pouraccélérer les réponses aux requêtes.

L’information a une date de péremption (TTL = Time To Live).

Le serveur qui mémorise un record DNS n’a pas autorité dessus.

Chaque enregistrement de la base de données a :une classe ; la plus courante : IN (Internet)un type : A, PTR, NS, SOA, MX, CNAME, . . .

et est donc de la forme :(classe, type, clé, valeur, TTL)

Une requête ressemble alors à :

(classe, type, clé, ?, ?)

(classe, *, clé, ?, ?)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 191 / 803

Page 101: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.4 Implémentation : BIND, namedChapitre 4 • Domain Name Server (DNS)§4.4 • Implémentation : BIND, named

URL : « http://www.isc.org/products/BIND/ »

Démon « named »

Fichier de configuration « /etc/named.conf » (en général).Directory « /etc/namedb » stockant les fichiers de zone (en général).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 192 / 803

4 Domain Name Server (DNS) 4.4 Implémentation : BIND, named

� Exemple 1 :

Pour connaitre la version de « named » :

% dig ns.example.com version.bind chaos txt

; <<>> DiG 8.2 <<>> ns.example.com version.bind chaos txt

;; res options: init recurs defnam dnsrch

;; got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4

;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUERY SECTION:

;; version.bind, type = TXT, class = CHAOS

;; ANSWER SECTION:

version.bind. 0S CHAOS TXT "bind 9"

;; Total query time: 3 msec

;; FROM: client.example.com to SERVER: default -- 192.168.1.1

;; WHEN: Mon Sep 30 00:20:19 2002

;; MSG SIZE sent: 30 rcvd: 49

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 193 / 803

Page 102: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.4 Implémentation : BIND, named

� Exemple 2 :

Pour connaitre la version de « named » :

% dig dmi.ens.fr version.bind chaos txt

; <<>> DiG 9.2.1 <<>> dmi.ens.fr version.bind chaos txt

;; global options: printcmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63986

;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 5, ADDITIONAL: 4

;; QUESTION SECTION:

;dmi.ens.fr. IN A

;; ANSWER SECTION:

dmi.ens.fr. 172800 IN A 129.199.96.11

;; AUTHORITY SECTION:

ens.fr. 172800 IN NS oseille.ens.fr.

ens.fr. 172800 IN NS dmi.ens.fr.

ens.fr. 172800 IN NS ext.lri.fr.

ens.fr. 172800 IN NS ns2.nic.fr.

ens.fr. 172800 IN NS clipper.ens.fr.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 194 / 803

4 Domain Name Server (DNS) 4.4 Implémentation : BIND, named

;; ADDITIONAL SECTION:

ext.lri.fr. 290218 IN A 129.175.15.4

ns2.nic.fr. 285943 IN A 192.93.0.4

clipper.ens.fr. 172800 IN A 129.199.129.1

oseille.ens.fr. 172800 IN A 129.199.98.16

;; Query time: 831 msec

;; SERVER: 127.0.0.1#53(127.0.0.1)

;; WHEN: Mon Sep 30 00:19:28 2002

;; MSG SIZE rcvd: 210

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48476

;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:

;version.bind. CH TXT

;; ANSWER SECTION:

version.bind. 0 CH TXT "9.2.1"

;; Query time: 42 msec

;; SERVER: 127.0.0.1#53(127.0.0.1)

;; WHEN: Mon Sep 30 00:19:28 2002

;; MSG SIZE rcvd: 48

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 195 / 803

Page 103: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.5 F.root-servers.net (vieille version)Chapitre 4 • Domain Name Server (DNS)§4.5 • F.root-servers.net (vieille version)

OBSOLÈTE mais laissé pour se faire une idée

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 196 / 803

4 Domain Name Server (DNS) 4.5 F.root-servers.net (vieille version)

(cf « http://www.isc.org/servicespublic/F-root-server.html »)

The Internet Software Consortium is proud to operate one of 13 root DNSservers as a public service to the Internet. The ISC has operated« F.root-servers.net » for the IANA (http://www.iana.org/)since 1993. F (http://f.root-servers.org) answers more than 272million DNS queries per day, making it one of the busiest DNS servers inthe world. In fact, it is often the busiest root nameserver on the Internet.

F is a virtual server made up of multiple (currently two) HP AlphaServers,donated to us by HP’s Western Research Laboratory(http://www.research.digital.com/wrl/). Each server is a HPES40 AlphaServer with 4 500mhz CPUs and 8Gig of RAM, and runs ISCBIND 8.3.2 as its DNS server.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 197 / 803

Page 104: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.5 F.root-servers.net (vieille version)

The servers are hosted at PAIX.net, Inc. (http://www.paix.net/) inPalo Alto, California and are connected to the Internet via fdx FastEthernet connections which are provided by UUNET(http://www.uu.net/), Teleglobe (http://www.teleglobe.com/),and MFN (http://www.mfn.com/).

For more information on the root DNS system, see : BCP 40 (RFC2870) -Operational guidelines for Root Name Servers(http://www.isi.edu/in-notes/rfc2870.txt).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 198 / 803

4 Domain Name Server (DNS) 4.6 F.root-servers.net (à jour)Chapitre 4 • Domain Name Server (DNS)§4.6 • F.root-servers.net (à jour)

(cf « http://www.isc.org/ops/f-root »)

2 nœuds globaux, plus de trente nœuds locaux répartis dans divers pays.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 199 / 803

Page 105: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.7 Utilitaire rndcChapitre 4 • Domain Name Server (DNS)§4.7 • Utilitaire rndc

Syntaxe : rndc [options] cmd

Il contrôle le fonctionnement de « named » à distance via TCP(« rndc.conf » contient des clefs d’accès).

« status » status de NAMED« dumpdb » dumpe la base et le cache dans

« /var/tmp/named_dump.db »« reload » recharge les zones primaires et se-

condaires« stats » dumpe les statistiques dans

« /var/tmp/named.stats »« trace/notrace » gestion du niveau de trace dans

« /var/tmp/named.run »« start » démarre NAMED« stop » arrête NAMED en sauvant les

mises à jour en cours« halt » arrête NAMED froidement« restart » arrête et redémarre NAMED

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 200 / 803

4 Domain Name Server (DNS) 4.8 Fichier /etc/resolv.confChapitre 4 • Domain Name Server (DNS)§4.8 • Fichier /etc/resolv.conf

Consultation des nameservers indiqués via le fichier« /etc/resolv.conf »

Exemple de fichier « /etc/resolv.conf » :

domain formation.jussieu.fr

search formation.jussieu.fr jussieu.fr

nameserver 134.157.253.1

nameserver 134.157.0.129

Attention :Au plus 3 lignes « nameserver ».Tous les UNIX ne comprennent pas la directive « search ».Un commentaire commence par « ; ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 201 / 803

Page 106: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.9 Interrogation manuelle DNS : nslookupChapitre 4 • Domain Name Server (DNS)§4.9 • Interrogation manuelle DNS : nslookup

Syntaxe : nslookup [options] à-résoudre

% nslookup www.playboy.com

Server: sunars1.formation.jussieu.fr

Address: 134.157.253.1

Non-authoritative answer:

Name: www.playboy.com

Address: 206.251.29.10

La machine est dans le cache du DNS parce qu’elle a déjà été résolue dansun passé récent.

Cet utilitaire tombe en désuétude.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 202 / 803

4 Domain Name Server (DNS) 4.10 Interrogation manuelle DNS : digChapitre 4 • Domain Name Server (DNS)§4.10 • Interrogation manuelle DNS : dig

C’est le remplaçant de « nslookup ». Il est très low level.Syntaxe : dig [options] à-résoudre

Quelques flags utilisés :flag « QR » : Queryflag « AA » : AuthoritativeAnswerflag « TC » : TCPflag « RD » : Recursion Desiredflag « RA » : RecursionAvailableflag « AD » : Authentic Data(DNSSEC)

flag « CD » : Checking Disabled(DNSSEC)

1 1 1 1 1 10 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+| ID |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+|QR| Opcode |AA|TC|RD|RA| Z|AD|CD| RCODE |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+| QDCOUNT |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+| ANCOUNT |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+| NSCOUNT |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+| ARCOUNT |+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 203 / 803

Page 107: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.10 Interrogation manuelle DNS : dig� Exemple 1 : récursivité jusqu’à la racine

% dig +trace www.formation.jussieu.fr

; <<>> DiG 9.2.1 <<>> +trace www.formation.jussieu.fr

;; global options: printcmd

. 3600000 IN NS K.ROOT-SERVERS.NET.

. 3600000 IN NS L.ROOT-SERVERS.NET.

. 3600000 IN NS M.ROOT-SERVERS.NET.

. 3600000 IN NS A.ROOT-SERVERS.NET.

. 3600000 IN NS B.ROOT-SERVERS.NET.

. 3600000 IN NS C.ROOT-SERVERS.NET.

. 3600000 IN NS D.ROOT-SERVERS.NET.

. 3600000 IN NS E.ROOT-SERVERS.NET.

. 3600000 IN NS F.ROOT-SERVERS.NET.

. 3600000 IN NS G.ROOT-SERVERS.NET.

. 3600000 IN NS H.ROOT-SERVERS.NET.

. 3600000 IN NS I.ROOT-SERVERS.NET.

. 3600000 IN NS J.ROOT-SERVERS.NET.

;; Received 244 bytes from 127.0.0.1#53(127.0.0.1) in 5 ms

fr. 172800 IN NS DNS.CS.WISC.EDU.

fr. 172800 IN NS NS1.NIC.fr.

fr. 172800 IN NS NS3.NIC.fr.

fr. 172800 IN NS DNS.INRIA.fr.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 204 / 803

4 Domain Name Server (DNS) 4.10 Interrogation manuelle DNS : dig

fr. 172800 IN NS NS2.NIC.fr.

fr. 172800 IN NS DNS.PRINCETON.EDU.

fr. 172800 IN NS NS-EXT.VIX.COM.

fr. 172800 IN NS NS3.DOMAIN-REGISTRY.NL.

;; Received 373 bytes from 193.0.14.129#53(K.ROOT-SERVERS.NET) in 273 ms

jussieu.fr. 345600 IN NS shiva.jussieu.fr.

jussieu.fr. 345600 IN NS cendrillon.lptl.jussieu.fr.

jussieu.fr. 345600 IN NS soleil.uvsq.fr.

;; Received 166 bytes from 128.105.2.10#53(DNS.CS.WISC.EDU) in 337 ms

www.formation.jussieu.fr. 172800 IN CNAME serveur.formation.jussieu.fr.

serveur.formation.jussieu.fr. 172800 IN A 134.157.46.129

formation.jussieu.fr. 172800 IN NS cendrillon.lptl.jussieu.fr.

formation.jussieu.fr. 172800 IN NS shiva.jussieu.fr.

formation.jussieu.fr. 172800 IN NS soleil.uvsq.fr.

;; Received 204 bytes from 134.157.0.129#53(shiva.jussieu.fr) in 217 ms

On voit bien le mécanisme de consultations des différents nameservers.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 205 / 803

Page 108: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.10 Interrogation manuelle DNS : dig

� Exemple 2 : consultation à la nslookup

% dig www.formation.jussieu.fr

; <<>> DiG 9.2.1 <<>> www.formation.jussieu.fr

;; global options: printcmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62679

;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 3, ADDITIONAL: 3

;; QUESTION SECTION:;www.formation.jussieu.fr. IN A

;; ANSWER SECTION:

www.formation.jussieu.fr. 172790 IN CNAME serveur.formation.jussieu.fr.

serveur.formation.jussieu.fr. 172789 IN A 134.157.46.129

;; AUTHORITY SECTION:

formation.jussieu.fr. 172789 IN NS cendrillon.lptl.jussieu.fr.

formation.jussieu.fr. 172789 IN NS shiva.jussieu.fr.

formation.jussieu.fr. 172789 IN NS soleil.uvsq.fr.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 206 / 803

4 Domain Name Server (DNS) 4.10 Interrogation manuelle DNS : dig

;; ADDITIONAL SECTION:

shiva.jussieu.fr. 74075 IN A 134.157.0.129

soleil.uvsq.fr. 222426 IN A 193.51.24.1

cendrillon.lptl.jussieu.fr. 172790 IN A 134.157.8.24

;; Query time: 5 msec

;; SERVER: 127.0.0.1#53(127.0.0.1);; WHEN: Thu Aug 29 00:22:06 2002

;; MSG SIZE rcvd: 204

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 207 / 803

Page 109: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.10 Interrogation manuelle DNS : dig

� Exemple 3 : réponse en cas d’erreur

% dig cerise

; <<>> DiG 9.2.1 <<>> cerise

;; global options: printcmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 45146

;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:;cerise. IN A

;; AUTHORITY SECTION:

. 10800 IN SOA A.ROOT-SERVERS.NET. NSTLD.VERISIGN-GRS.COM. 2002082801 1800 900 604800 86400

;; Query time: 206 msec

;; SERVER: 127.0.0.1#53(127.0.0.1);; WHEN: Thu Aug 29 00:22:13 2002

;; MSG SIZE rcvd: 98

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 208 / 803

4 Domain Name Server (DNS) 4.10 Interrogation manuelle DNS : dig� Exemple 4 : précision du type du recordPremière fois :

% dig www.crlv.org SOA

; <<>> DiG 8.2 <<>> www.crlv.org SOA

;; res options: init recurs defnam dnsrch

;; got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4

;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUERY SECTION:

;; www.crlv.org, type = SOA, class = IN

;; AUTHORITY SECTION:

crlv.org. 2H IN SOA ns.easynet.fr. hostmaster.easynet.fr. (

2001020101 ; serial

1H ; refresh

30M ; retry

4W ; expiry

2H ) ; minimum

;; Total query time: 14 msec

;; FROM: apollinaire.paris4.sorbonne.fr to SERVER: default -- 195.220.107.3

;; WHEN: Thu Aug 29 15:06:22 2002;; MSG SIZE sent: 30 rcvd: 90

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 209 / 803

Page 110: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.10 Interrogation manuelle DNS : dig

Deuxième fois :

% dig www.crlv.org SOA

; <<>> DiG 8.2 <<>> www.crlv.org SOA

;; res options: init recurs defnam dnsrch

;; got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4

;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUERY SECTION:

;; www.crlv.org, type = SOA, class = IN

;; AUTHORITY SECTION:

crlv.org. 1h55m43s IN SOA ns.easynet.fr. hostmaster.easynet.fr. (

2001020101 ; serial

1H ; refresh

30M ; retry

4W ; expiry

2H ) ; minimum

;; Total query time: 13 msec

;; FROM: apollinaire.paris4.sorbonne.fr to SERVER: default -- 195.220.107.3

;; WHEN: Thu Aug 29 15:10:39 2002;; MSG SIZE sent: 30 rcvd: 98

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 210 / 803

4 Domain Name Server (DNS) 4.11 Record de type PTRChapitre 4 • Domain Name Server (DNS)§4.11 • Record de type PTR

On peut aussi interroger un nameserver pour résoudre des adresses :

% /usr/sbin/nslookup 193.252.79.61

Server: sunars1.formation.jussieu.fr

Address: 134.157.253.1

Name: www.liberation.fr

Address: 193.252.79.61

A rapprocher de :

% /usr/sbin/nslookup -query=ptr 61.79.252.193.in-addr.arpa

Server: sunars1.formation.jussieu.fr

Address: 134.157.253.1

Non-authoritative answer:

61.79.252.193.in-addr.arpa name = www.liberation.fr

Authoritative answers can be found from:

79.252.193.in-addr.arpa nameserver = ns1.fth.net

79.252.193.in-addr.arpa nameserver = ns2.fth.net

ns1.fth.net internet address = 193.252.251.253

ns2.fth.net internet address = 193.252.69.217

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 211 / 803

Page 111: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.11 Record de type PTR

.arpa

in−addr

134

157

253

1

fr

jussieu

formation

sunars1

sunars1.formation.jussieu.fr

134.157.253.1

Assurerla coherence

Une faute courante : oublier de mettre à jour l’entrée relative à l’adresseIP de la machine.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 212 / 803

4 Domain Name Server (DNS) 4.12 Fichier /etc/nsswitch.confChapitre 4 • Domain Name Server (DNS)§4.12 • Fichier /etc/nsswitch.conf

Certains systèmes UNIX permettent de spécifier quelles méthodes derésolution utiliser (DNS, « /etc/hosts », NIS) ainsi que l’ordred’enchaînement des méthodes.Sur Linux et Solaris, cf « /etc/nsswitch.conf » (voir page 566) :

...

hosts: files nisplus nis dns

...

ou

...

hosts: xfn nisplus dns [NOTFOUND=return] files

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 213 / 803

Page 112: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.13 Délégation d’une partie de classe CChapitre 4 • Domain Name Server (DNS)§4.13 • Délégation d’une partie de classe C

� RFC 2317

« http://www.lip6.fr/pub/rfc/rfc/rfc2317.txt.gz »

Avis : Mécanisme astucieux mais un peu compliqué à mettre en œuvre enpratique.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 214 / 803

4 Domain Name Server (DNS) 4.13 Délégation d’une partie de classe C

� WebDNS

Logiciel WebDNS : « http://www-crc.u-strasbg.fr/webdns/ »Principe : générer les données via une vraie base de données avec toutesles possibilités fines associées (par exemple une personne peut avoir ledroit SQL de modifier un et un seul record DNS dans la base SQL)Logiciel non réservé aux sous classes C. En utilisation sur le campus deJussieu par exemple.

Avis : Approche très tendance pour résoudre un problème de fond dans leprincipe du DNS lors de vrais déployements.Avis 2 : Nouvel exemple de couplage à une base de données.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 215 / 803

Page 113: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.13 Délégation d’une partie de classe C

DNS

PostgreSQL

HTTP/HTTPS

PostgreSQL

Serveur DNS (client PostgreSQL)

Serveur Web (client PostgreSQL)

Serveur de données (PostgreSQL)

Internet

Base

données

named.boot

defichiers

dezones

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 216 / 803

4 Domain Name Server (DNS) 4.14 Nom de machine : hostnameChapitre 4 • Domain Name Server (DNS)§4.14 • Nom de machine : hostname

Caractères autorisés : cf RFC 952 et RFC 1123En résumé :

lettres majusculeslettres minusculeschiffrescaractère moins « - »caractère underscore « _ »

« http://www.lip6.fr/pub/rfc/rfc/rfc952.txt.gz »« http://www.lip6.fr/pub/rfc/rfc/rfc1123.txt.gz »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 217 / 803

Page 114: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.15 WHOISChapitre 4 • Domain Name Server (DNS)§4.15 • WHOIS

WHOIS ≡ base de données des informations relatives à l’attribution desplages d’adresses IP et des noms de domaines.

Exemple d’un protocole Internet loupé car les implémentations ne sont pascompatibles entre elles. RFC 954, port TCP 43

Protocole exploitable par la commande « whois ».Syntaxe : « whois [ -h server-whois ] adresse-ou-domaine »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 218 / 803

4 Domain Name Server (DNS) 4.15 WHOIS

Quelques serveurs WHOIS :« rs.internic.net »« whois.nic.fr » ou via un interface WWW :« http://www.afnic.asso.fr/cgi-bin/whois »« whois.ripe.net »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 219 / 803

Page 115: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.16 (Windows : : ipconfig /displaydns, ipconfig /flushdns)Chapitre 4 • Domain Name Server (DNS)§4.16 • (Windows : : ipconfig /displaydns, ipconfig /flushdns)

Une machine WINDOWS utilise un cache interne pour les requêtes DNS.

On peut afficher le cache interne par la commande« ipconfig /displaydns ».

On peut purger le cache interne par la commande« ipconfig /flushdns ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 220 / 803

4 Domain Name Server (DNS) 4.17 Espace de confianceChapitre 4 • Domain Name Server (DNS)§4.17 • Espace de confiance

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 221 / 803

Page 116: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.18 Un peu de documentationChapitre 4 • Domain Name Server (DNS)§4.18 • Un peu de documentation

cours réseau ARSCf « http://www.isc.org/ » et ftp://ftp.isc.org/isc/bind/Cf « http://www.cri.fr/ZoneCheck/ »Cf « http://www.univ-rennes1.fr/DNSRENATER/ »Cf« ftp://ftp.univ-rennes1.fr/pub/reseau/dns/exemple/ »RFC 2317 «Classless IN-ADDR.ARPA delegation»« http://www.uninett.no/navn/domreg.html »« ftp://ftp.jussieu.fr/jussieu/doc/local/dnsmail.ps.Z »« http://www.cri.ensmp.fr/people/keryell/cours »DNS and BIND, 4th Edition, By Paul Albitz & Cricket Liu, 4thEdition April 2001, O’Reilly & Associates, Inc. 622 pages, $44.95

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 222 / 803

4 Domain Name Server (DNS) 4.19 Annexe 1Chapitre 4 • Domain Name Server (DNS)§4.19 • Annexe 1

Ci joint dans la version imprimée de ce cours, la liste des top level domainsDNS.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 223 / 803

Page 117: Administration UNIX - Cours Jussieu - 2009-2010

Generic top level domainshttp ://www.norid.no/domenenavnbaser/domreg.html

Generic top level domains (gTLD)« .aero » Aviation« .asia » Asia« .biz » Business Organizations« .cat » Catalan language and culture« .com » Commercial« .coop » Co-Operative Organizations« .edu » Education« .gov » US Government« .info » Open TLD« .int » International Organizations« .jobs » Jobs« .mil » US Department of Defense« .mobi » Mobile devices« .museum » Museums« .name » Personal« .net » Networks« .org » Organizations« .pro » Credentialed professionals and related entities« .tel » Publishing of contact data« .travel » Travelling

Country code top level domains (ccTLD)

A« .ac » Ascension Island« .ad » Andorra« .ae » United Arab Emirates« .af » Afghanistan« .ag » Antigua and Barbuda« .ai » Anguilla« .al » Albania« .am » Armenia« .an » Netherlands Antilles« .ao » Angola« .aq » Antarctica« .ar » Argentina« .as » American Samoa« .at » Austria« .au » Australia« .aw » Aruba« .ax » Åland Islands« .az » Azerbaijan

B« .ba » Bosnia and Herzegovina« .bb » Barbados« .bd » Bangladesh« .be » Belgium

« .bf » Burkina Faso« .bg » Bulgaria« .bh » Bahrain« .bi » Burundi« .bj » Benin« .bm » Bermuda« .bn » Brunei Darussalam« .bo » Bolivia« .br » Brazil« .bs » Bahamas« .bt » Bhutan« .bv » Bouvet Island« .bw » Botswana« .by » Belarus« .bz » Belize

C« .ca » Canada« .cc » Cocos (Keeling) Islands« .cd » Congo, Democratic republic of the (former

Zaire)« .cf » Central African Republic« .cg » Congo, Republic of« .ch » Switzerland« .ci » Côte d’Ivoire

1

Page 118: Administration UNIX - Cours Jussieu - 2009-2010

« .ck » Cook Islands« .cl » Chile« .cm » Cameroon« .cn » China« .co » Colombia« .cr » Costa Rica« .cs » Czechoslovakia (former ? non-existing)« .cu » Cuba« .cv » Cape Verde« .cx » Christmas Island« .cy » Cyprus« .cz » Czech Republic

D« .de » Germany« .dj » Djibouti« .dk » Denmark« .dm » Dominica« .do » Dominican Republic« .dz » Algeria

E« .ec » Ecuador« .ee » Estonia« .eg » Egypt« .eh » Western Sahara« .er » Eritrea« .es » Spain« .et » Ethiopia« .eu » European Union

F« .fi » Finland« .fj » Fiji« .fk » Falkland Islands« .fm » Micronesia« .fo » Faroe Islands« .fr » France

G« .ga » Gabon« .gb » United Kingdom« .gd » Grenada« .ge » Georgia« .gf » French Guiana« .gg » Guernsey« .gh » Ghana« .gi » Gibraltar« .gl » Greenland« .gm » Gambia« .gn » Guinea« .gp » Guadeloupe« .gq » Equatorial Guinea« .gr » Greece

« .gs » South Georgia and the South Sandwich Is-lands

« .gt » Guatemala« .gu » Guam« .gw » Guinea-Bissau« .gy » Guyana

H« .hk » Hong Kong« .hm » Heard and McDonald Islands« .hn » Honduras« .hr » Croatia« .ht » Haiti« .hu » Hungary

I« .id » Indonesia« .ie » Ireland« .il » Israel« .im » Isle of Man« .in » India« .io » British Indian Ocean Territory« .iq » Iraq« .ir » Iran« .is » Iceland« .it » Italia

J« .je » Jersey« .jm » Jamaica« .jo » Jordan« .jp » Japan

K« .ke » Kenya« .kg » Kyrgyzstan« .kh » Cambodia« .ki » Kiribati« .km » Comoros« .kn » Saint Kitts and Nevis« .kp » Korea, Democratic Peoples Republic of« .kr » Korea, Republic of« .kw » Kuwait« .ky » Cayman Islands« .kz » Kazakhstan

L« .la » Lao People’s Democratic Republic« .lb » Lebanon« .lc » Saint Lucia« .li » Liechtenstein« .lk » Sri Lanka« .lr » Liberia« .ls » Lesotho

2

Page 119: Administration UNIX - Cours Jussieu - 2009-2010

« .lt » Lithuania« .lu » Luxembourg« .lv » Latvia« .ly » Libyan Arab Jamahiriya

M« .ma » Morocco« .mc » Monaco« .md » Moldova« .me » Montenegro« .mg » Madagascar« .mh » Marshall Islands« .mk » Macedonia« .ml » Mali« .mm » Myanmar« .mn » Mongolia« .mo » Macau« .mp » Northern Mariana Islands« .mq » Martinique« .mr » Mauritania« .ms » Montserrat« .mt » Malta« .mu » Mauritius« .mv » Maldives« .mw » Malawi« .mx » Mexico« .my » Malaysia« .mz » Mozambique

N« .na » Namibia« .nc » New Caledonia« .ne » Niger« .nf » Norfolk Island« .ng » Nigeria« .ni » Nicaragua« .nl » The Netherlands« .no » Norway« .np » Nepal« .nr » Nauru« .nu » Niue« .nz » New Zealand

O« .om » Oman

P« .pa » Panama« .pe » Peru« .pf » French Polynesia« .pg » Papua New Guinea« .ph » Philippines« .pk » Pakistan« .pl » Poland

« .pm » St. Pierre and Miquelon« .pn » Pitcairn« .pr » Puerto Rico« .ps » Palestine« .pt » Portugal« .pw » Palau« .py » Paraguay

Q« .qa » Qatar

R« .re » Reunion« .ro » Romania« .rs » Serbia« .ru » Russia« .rw » Rwanda

S« .sa » Saudi Arabia« .sb » Solomon Islands« .sc » Seychelles« .sd » Sudan« .se » Sweden« .sg » Singapore« .sh » St. Helena« .si » Slovenia« .sj » Svalbard and Jan Mayen Islands« .sk » Slovakia« .sl » Sierra Leone« .sm » San Marino« .sn » Senegal« .so » Somalia« .sr » Surinam« .st » Sao Tome and Principe« .su » USSR (former)« .sv » El Salvador« .sy » Syrian Arab Republic« .sz » Swaziland

T« .tc » The Turks and Caicos Islands« .td » Chad« .tf » French Southern Territories« .tg » Togo« .th » Thailand« .tj » Tajikistan« .tk » Tokelau« .tl » Timor-Leste« .tm » Turkmenistan« .tn » Tunisia« .to » Tonga« .tp » East Timor« .tr » Turkey

3

Page 120: Administration UNIX - Cours Jussieu - 2009-2010

« .tt » Trinidad and Tobago« .tv » Tuvalu« .tw » Taiwan« .tz » Tanzania

U« .ua » Ukraine« .ug » Uganda« .uk » United Kingdom« .um » United States Minor Outlying Islands« .us » United States« .uy » Uruguay« .uz » Uzbekistan

V« .va » Holy See (Vatican City State)« .vc » Saint Vincent and the Grenadines« .ve » Venezuela« .vg » Virgin Islands British

« .vi » Virgin Islands U.S« .vn » Vietnam« .vu » Vanuatu

W« .wf » Wallis and Futuna Islands« .ws » Samoa

Y« .ye » Yemen« .yt » Mayotte« .yu » Yugoslavia

Z« .za » South Africa« .zm » Zambia« .zr » Zaire (non-existent, see Congo)« .zw » Zimbabwe

4

Page 121: Administration UNIX - Cours Jussieu - 2009-2010

4 Domain Name Server (DNS) 4.20 Annexe 2Chapitre 4 • Domain Name Server (DNS)§4.20 • Annexe 2

Ci joint dans la version imprimée de ce cours, la RFC 2870 sur lescontraintes pour un serveur de noms de la racine.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 224 / 803

Page 122: Administration UNIX - Cours Jussieu - 2009-2010

Network Working Group R. BushRequest for Comments: 2870 VerioObsoletes: 2010 D. KarrenbergBCP: 40 RIPE NCCCategory: Best Current Practice M. Kosters Network Solutions R. Plzak SAIC June 2000

Root Name Server Operational Requirements

Status of this Memo

This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements. Distribution of this memo is unlimited.

Copyright Notice

Copyright (C) The Internet Society (2000). All Rights Reserved.

Abstract

As the internet becomes increasingly critical to the world’s social and economic infrastructure, attention has rightly focused on the correct, safe, reliable, and secure operation of the internet infrastructure itself. The root domain name servers are seen as a crucial part of that technical infrastructure. The primary focus of this document is to provide guidelines for operation of the root name servers. Other major zone server operators (gTLDs, ccTLDs, major zones) may also find it useful. These guidelines are intended to meet the perceived societal needs without overly prescribing technical details.

1. Background

The resolution of domain names on the internet is critically dependent on the proper, safe, and secure operation of the root domain name servers. Currently, these dozen or so servers are provided and operated by a very competent and trusted group of volunteers. This document does not propose to change that, but merely to provide formal guidelines so that the community understands how and why this is done.

Bush, et al. Best Current Practice [Page 1]^L

Page 123: Administration UNIX - Cours Jussieu - 2009-2010

RFC 2870 Root Name Server Operational Requirements June 2000

1.1 The Internet Corporation for Assigned Names and Numbers (ICANN) has become responsible for the operation of the root servers. The ICANN has appointed a Root Server System Advisory Committee (RSSAC) to give technical and operational advice to the ICANN board. The ICANN and the RSSAC look to the IETF to provide engineering standards.

1.2 The root servers serve the root, aka ".", zone. Although today some of the root servers also serve some TLDs (top level domains) such as gTLDs (COM, NET, ORG, etc.), infrastructural TLDs such as INT and IN−ADDR.ARPA, and some ccTLDs (country code TLDs, e.g. SE for Sweden), this is likely to change (see 2.5).

1.3 The root servers are neither involved with nor dependent upon the ’whois’ data.

1.4 The domain name system has proven to be sufficiently robust that we are confident that the, presumably temporary, loss of most of the root servers should not significantly affect operation of the internet.

1.5 Experience has shown that the internet is quite vulnerable to incorrect data in the root zone or TLDs. Hence authentication, validation, and security of these data are of great concern.

2. The Servers Themselves

The following are requirements for the technical details of the root servers themselves:

2.1 It would be short−sighted of this document to specify particular hardware, operating systems, or name serving software. Variations in these areas would actually add overall robustness.

2.2 Each server MUST run software which correctly implements the IETF standards for the DNS, currently [RFC1035] [RFC2181]. While there are no formal test suites for standards compliance, the maintainers of software used on root servers are expected to take all reasonable actions to conform to the IETF’s then current documented expectations.

2.3 At any time, each server MUST be able to handle a load of requests for root data which is three times the measured peak of such requests on the most loaded server in then current normal conditions. This is usually expressed in requests per second. This is intended to ensure continued operation of root services should two thirds of the servers be taken out of operation, whether by intent, accident, or malice.

Bush, et al. Best Current Practice [Page 2]^L

Page 124: Administration UNIX - Cours Jussieu - 2009-2010

RFC 2870 Root Name Server Operational Requirements June 2000

2.4 Each root server should have sufficient connectivity to the internet to support the bandwidth needs of the above requirement. Connectivity to the internet SHOULD be as diverse as possible.

Root servers SHOULD have mechanisms in place to accept IP connectivity to the root server from any internet provider delivering connectivity at their own cost.

2.5 Servers MUST provide authoritative responses only from the zones they serve. The servers MUST disable recursive lookup, forwarding, or any other function that may allow them to provide cached answers. They also MUST NOT provide secondary service for any zones other than the root and root−servers.net zones. These restrictions help prevent undue load on the root servers and reduce the chance of their caching incorrect data.

2.6 Root servers MUST answer queries from any internet host, i.e. may not block root name resolution from any valid IP address, except in the case of queries causing operational problems, in which case the blocking SHOULD last only as long as the problem, and be as specific as reasonably possible.

2.7 Root servers SHOULD NOT answer AXFR, or other zone transfer, queries from clients other than other root servers. This restriction is intended to, among other things, prevent unnecessary load on the root servers as advice has been heard such as "To avoid having a corruptible cache, make your server a stealth secondary for the root zone." The root servers MAY put the root zone up for ftp or other access on one or more less critical servers.

2.8 Servers MUST generate checksums when sending UDP datagrams and MUST verify checksums when receiving UDP datagrams containing a non−zero checksum.

3. Security Considerations

The servers need both physical and protocol security as well as unambiguous authentication of their responses.

3.1 Physical security MUST be ensured in a manner expected of data centers critical to a major enterprise.

3.1.1 Whether or not the overall site in which a root server is located has access control, the specific area in which the root server is located MUST have positive access control, i.e. the number of individuals permitted access to the area MUST be limited, controlled, and recorded. At a

Bush, et al. Best Current Practice [Page 3]^L

Page 125: Administration UNIX - Cours Jussieu - 2009-2010

RFC 2870 Root Name Server Operational Requirements June 2000

minimum, control measures SHOULD be either mechanical or electronic locks. Physical security MAY be enhanced by the use of intrusion detection and motion sensors, multiple serial access points, security personnel, etc.

3.1.2 Unless there is documentable experience that the local power grid is more reliable than the MTBF of a UPS (i.e. five to ten years), power continuity for at least 48 hours MUST be assured, whether through on−site batteries, on− site power generation, or some combination thereof. This MUST supply the server itself, as well as the infrastructure necessary to connect the server to the internet. There MUST be procedures which ensure that power fallback mechanisms and supplies are tested no less frequently than the specifications and recommendations of the manufacturer.

3.1.3 Fire detection and/or retardation MUST be provided.

3.1.4 Provision MUST be made for rapid return to operation after a system outage. This SHOULD involve backup of systems software and configuration. But SHOULD also involve backup hardware which is pre−configured and ready to take over operation, which MAY require manual procedures.

3.2 Network security should be of the level provided for critical infrastructure of a major commercial enterprise.

3.2.1 The root servers themselves MUST NOT provide services other than root name service e.g. remote internet protocols such as http, telnet, rlogin, ftp, etc. The only login accounts permitted should be for the server administrator(s). "Root" or "privileged user" access MUST NOT be permitted except through an intermediate user account.

Servers MUST have a secure mechanism for remote administrative access and maintenance. Failures happen; given the 24x7 support requirement (per 4.5), there will be times when something breaks badly enough that senior wizards will have to connect remotely. Remote logins MUST be protected by a secure means that is strongly authenticated and encrypted, and sites from which remote login is allowed MUST be protected and hardened.

3.2.2 Root name servers SHOULD NOT trust other hosts, except secondary servers trusting the primary server, for matters of authentication, encryption keys, or other access or

Bush, et al. Best Current Practice [Page 4]^L

Page 126: Administration UNIX - Cours Jussieu - 2009-2010

RFC 2870 Root Name Server Operational Requirements June 2000

security information. If a root operator uses kerberos authentication to manage access to the root server, then the associated kerberos key server MUST be protected with the same prudence as the root server itself. This applies to all related services which are trusted in any manner.

3.2.3 The LAN segment(s) on which a root server is homed MUST NOT also home crackable hosts. I.e. the LAN segments should be switched or routed so there is no possibility of masquerading. Some LAN switches aren’t suitable for security purposes, there have been published attacks on their filtering. While these can often be prevented by careful configuration, extreme prudence is recommended. It is best if the LAN segment simply does not have any other hosts on it.

3.2.4 The LAN segment(s) on which a root server is homed SHOULD be separately firewalled or packet filtered to discourage network access to any port other than those needed for name service.

3.2.5 The root servers SHOULD have their clocks synchronized via NTP [RFC1305] [RFC2030] or similar mechanisms, in as secure manner as possible. For this purpose, servers and their associated firewalls SHOULD allow the root servers to be NTP clients. Root servers MUST NOT act as NTP peers or servers.

3.2.6 All attempts at intrusion or other compromise SHOULD be logged, and all such logs from all root servers SHOULD be analyzed by a cooperative security team communicating with all server operators to look for patterns, serious attempts, etc. Servers SHOULD log in GMT to facilitate log comparison.

3.2.7 Server logging SHOULD be to separate hosts which SHOULD be protected similarly to the root servers themselves.

3.2.8 The server SHOULD be protected from attacks based on source routing. The server MUST NOT rely on address− or name−based authentication.

3.2.9 The network on which the server is homed SHOULD have in−addr.arpa service.

3.3 Protocol authentication and security are required to ensure that data presented by the root servers are those created by those authorized to maintain the root zone data.

Bush, et al. Best Current Practice [Page 5]^L

Page 127: Administration UNIX - Cours Jussieu - 2009-2010

RFC 2870 Root Name Server Operational Requirements June 2000

3.3.1 The root zone MUST be signed by the Internet Assigned Numbers Authority (IANA) in accordance with DNSSEC, see [RFC2535] or its replacements. It is understood that DNSSEC is not yet deployable on some common platforms, but will be deployed when supported.

3.3.2 Root servers MUST be DNSSEC−capable so that queries may be authenticated by clients with security and authentication concerns. It is understood that DNSSEC is not yet deployable on some common platforms, but will be deployed when supported.

3.3.3 Transfer of the root zone between root servers MUST be authenticated and be as secure as reasonably possible. Out of band security validation of updates MUST be supported. Servers MUST use DNSSEC to authenticate root zones received from other servers. It is understood that DNSSEC is not yet deployable on some common platforms, but will be deployed when supported.

3.3.4 A ’hidden primary’ server, which only allows access by the authorized secondary root servers, MAY be used.

3.3.5 Root zone updates SHOULD only progress after a number of heuristic checks designed to detect erroneous updates have been passed. In case the update fails the tests, human intervention MUST be requested.

3.3.6 Root zone updates SHOULD normally be effective no later than 6 hours from notification of the root server operator.

3.3.7 A special procedure for emergency updates SHOULD be defined. Updates initiated by the emergency procedure SHOULD be made no later than 12 hours after notification.

3.3.8 In the advent of a critical network failure, each root server MUST have a method to update the root zone data via a medium which is delivered through an alternative, non− network, path.

3.3.9 Each root MUST keep global statistics on the amount and types of queries received/answered on a daily basis. These statistics must be made available to RSSAC and RSSAC sponsored researchers to help determine how to better deploy these machines more efficiently across the

Bush, et al. Best Current Practice [Page 6]^L

Page 128: Administration UNIX - Cours Jussieu - 2009-2010

RFC 2870 Root Name Server Operational Requirements June 2000

internet. Each root MAY collect data snapshots to help determine data points such as DNS query storms, significant implementation bugs, etc.

4. Communications

Communications and coordination between root server operators and between the operators and the IANA and ICANN are necessary.

4.1 Planned outages and other down times SHOULD be coordinated between root server operators to ensure that a significant number of the root servers are not all down at the same time. Preannouncement of planned outages also keeps other operators from wasting time wondering about any anomalies.

4.2 Root server operators SHOULD coordinate backup timing so that many servers are not off−line being backed up at the same time. Backups SHOULD be frequently transferred off site.

4.3 Root server operators SHOULD exchange log files, particularly as they relate to security, loading, and other significant events. This MAY be through a central log coordination point, or MAY be informal.

4.4 Statistics as they concern usage rates, loading, and resource utilization SHOULD be exchanged between operators, and MUST be reported to the IANA for planning and reporting purposes.

4.5 Root name server administrative personnel MUST be available to provide service 24 hours a day, 7 days per week. On call personnel MAY be used to provide this service outside of normal working hours.

5. Acknowledgements

The authors would like to thank Scott Bradner, Robert Elz, Chris Fletcher, John Klensin, Steve Bellovin, and Vern Paxson for their constructive comments.

Bush, et al. Best Current Practice [Page 7]^L

Page 129: Administration UNIX - Cours Jussieu - 2009-2010

RFC 2870 Root Name Server Operational Requirements June 2000

6. References

[RFC1035] Mockapetris, P., "Domain names − implementation and specification", STD 13, RFC 1035, November 1987.

[RFC1305] Mills, D., "Network Time Protocol (Version 3) Specification, Implementation", RFC 1305, March 1992.

[RFC2030] Mills, D., "Simple Network Time Protocol (SNTP) Version 4 for IPv4, IPv6 and OSI", RFC 2030, October 1996.

[RFC2181] Elz, R. and R. Bush, "Clarifications to the DNS Specification", RFC 2181, July 1997.

[RFC2535] Eastlake, D. and C. Kaufman, "Domain Name System Security Extensions", RFC 2535, March 1999.

Bush, et al. Best Current Practice [Page 8]^L

Page 130: Administration UNIX - Cours Jussieu - 2009-2010

RFC 2870 Root Name Server Operational Requirements June 2000

7. Authors’ Addresses

Randy Bush Verio, Inc. 5147 Crystal Springs Bainbridge Island, WA US−98110

Phone: +1 206 780 0431 EMail: [email protected]

Daniel Karrenberg RIPE Network Coordination Centre (NCC) Singel 258 NL−1016 AB Amsterdam Netherlands

Phone: +31 20 535 4444 EMail: [email protected]

Mark Kosters Network Solutions 505 Huntmar Park Drive Herndon, VA 22070−5100

Phone: +1 703 742 0400 EMail: [email protected]

Raymond Plzak SAIC 1710 Goodridge Drive McLean, Virginia 22102 +1 703 821 6535

EMail: [email protected]

8. Specification of Requirements

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Bush, et al. Best Current Practice [Page 9]^L

Page 131: Administration UNIX - Cours Jussieu - 2009-2010

RFC 2870 Root Name Server Operational Requirements June 2000

9. Full Copyright Statement

Copyright (C) The Internet Society (2000). All Rights Reserved.

This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations, except as needed for the purpose of developing Internet standards in which case the procedures for copyrights defined in the Internet Standards process must be followed, or as required to translate it into languages other than English.

The limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns.

This document and the information contained herein is provided on an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.

Acknowledgement

Funding for the RFC Editor function is currently provided by the Internet Society.

Bush, et al. Best Current Practice [Page 10]

Page 132: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 5

SSH

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 225 / 803

5 SSH 5.1 IntroductionChapitre 5 • SSH§5.1 • Introduction

Voir cours de Frédérique BONGAT.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 226 / 803

Page 133: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 6

Courrier électronique

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 227 / 803

6 Courrier électronique 6.1 Composantes du système du courrier électroniqueChapitre 6 • Courrier électronique§6.1 • Composantes du système du courrier électronique

C’est un système complexe dont la complexité croît sans cesse.

Il a de fortes interactions avec Internet, avec les Intranets.

De nombreuses implémentations sont disponibles (X400, SMTP, MicrosoftExchange, etc.).

Le système est modulaire, son bon fonctionnement reposant sur desdescriptions publiquement disponibles des détails des différents protocoles.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 228 / 803

Page 134: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.1 Composantes du système du courrier électronique

Réseau

MTA

MDA

MUA

Boîteaux lettres

Courriers à destinationd’un utilisateur localDestinataire du

courrier non local

Transmission au facteur local

Distribution personnalisée

Emission d’un courrier

Consultation des courriers

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 229 / 803

6 Courrier électronique 6.1 Composantes du système du courrier électronique

Terminologie :

MTA (Mail Transfer Agent — agent de routage)En fonction de l’adresse de destination, il passe le message à uncertain agent de transport.Plusieurs MTA existent : Sendmail, Postfix

MDA (Mail Delivery Agent — agent de transport)Il reçoit un message, une destination et se charge de l’acheminement.Il est spécialisé dans un type d’acheminement.(synonyme mailer)

MUA (Mail User Agent — agent utilisateur)Il sert à la composition des messages qu’il envoie à l’agent de routage.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 230 / 803

Page 135: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.1 Composantes du système du courrier électronique

• Normes utilisées :

RFC 822, description du format des messagesRFC 821, description du protocole SMTP (Simple Mail TransferProtocol)RFC 974, description de l’interaction d’un MTA avec le DNSRFC 1035RFC 1123

Attention : documents techniques hermétiques à la lecture compliquéeCf « ftp://ftp.lip6.fr/pub/rfc/rfc/ »

• Les problèmes de mail sont à adresser à « postmaster ».Les MTA font l’hypothèse que cette adresse existe.Cette adresse doit être lue par un humain.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 231 / 803

6 Courrier électronique 6.2 SendmailChapitre 6 • Courrier électronique§6.2 • Sendmail

SENDMAIL :Conçu en 1982, par Eric Allman (<[email protected]>)Site officiel « http://www.sendmail.org/ »Principal logiciel pour router les courriers des systèmes UNIX répandusSouple, puissantSait s’adapter aux nouveaux standards (aspects multimedia)Syntaxe difficileOutils annexes simplifiant la configuration : par exemple kit jussieu« ftp://ftp.jussieu.fr/jussieu/sendmail/kit/kit-5.3.4.tar.Z »« ftp://ftp.jussieu.fr/jussieu/sendmail/kit/doc-kit-5.3.4.ps.Z »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 232 / 803

Page 136: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.3 Sendmail plugins : MILTERChapitre 6 • Courrier électronique§6.3 • Sendmail plugins : MILTER

SENDMAIL s’occupe de router les mails.Donc :

hors de question de compliquer le code par un antivirushors de question de compliquer le code par un antispamhors de question de compliquer le code par. . .

Bref, hors de question de compliquer le code par n’importe quoi qui n’apas de rapport avec le routage de mails.

Par contre, possibilité d’interfacer SENDMAIL à des fonctionnalitésexternalisées grâce à l’API « MILTER » fourni par les développeurs deSENDMAIL.

Cf « http://www.milter.org/ » pour de la documentation ou desplugins.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 233 / 803

6 Courrier électronique 6.3 Sendmail plugins : MILTER

MILTER = communication entre SENDMAIL et des programmes externesvia des sockets UNIX.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 234 / 803

Page 137: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.4 PostfixChapitre 6 • Courrier électronique§6.4 • Postfix

« http://www.postfix.org »Futur successeur de SENDMAIL certainement dans quelques années.Une réflexion sur SENDMAIL a conduit à écrire postfix sous une formenon monolithique. Plusieurs démons vont s’occuper chacun d’une tâchebien précise et n’utilisent pour cela que le minimum de privilèges systèmelimitant le risque de piratage :

local "sendmail" maildrop

Internet

RBL

pickup

smtpd

access

cleanup

rewrite

canonical virtual

incoming active

deferred

qmgr

resolve

transport

relocated

smtp

pipe

local

aliases .forward

mailbox

Internet

UUCP, etc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 235 / 803

6 Courrier électronique 6.4 Postfix

Le fichier de configuration est une succession d’affectation de valeurs à desvariables.

Approche radicalement différente de celle de SENDMAIL plus proched’une programmation de la configuration.Approche de postfix identique à celle du kit jussieu pour SENDMAIL (ouvice versa).

Possibilité de modifier on the fly le comportement de postfix.Par exemple à l’établissement d’une connexion PPP ou lors de sa cloture,on peut depuis le script PPP dire à postfix d’échanger les mailsmaintenant avec l’extérieur.

Avec SENDMAIL, il faudrait arrêter SENDMAIL, mettre en place unenouvelle configuration « sendmail.cf », relancer SENDMAIL, ensemblede manœuvres lourdes.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 236 / 803

Page 138: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.5 Postfix pluginsChapitre 6 • Courrier électronique§6.5 • Postfix plugins

Il existe un mécanisme à MILTER de SENDMAIL dans POSTFIX.

Utilisation de sockets UNIX aussi.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 237 / 803

6 Courrier électronique 6.6 Boites aux lettres : foldersChapitre 6 • Courrier électronique§6.6 • Boites aux lettres : folders

Deux formats classiques de folders sous UNIX :

folder MBOX folder MAILDIR

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 238 / 803

Page 139: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.7 Boites aux lettres : folder MBOXChapitre 6 • Courrier électronique§6.7 • Boites aux lettres : folder MBOX

Un fichier stocke tous les mails reçus du MDA et manipulés par les MUA :

Classiquement « /var/mail/$USERNAME ».

⇒ Problèmes de verrouillage du fichier lors des lectures/écritures, demanipulation de grosses boites aux lettres, etc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 239 / 803

6 Courrier électronique 6.7 Boites aux lettres : folder MBOX

Structure d’un mail :

From [email protected] Mon Nov 19 21:27:41 2001Return-Path: <[email protected]>

Received: from localhost (localhost [127.0.0.1])

by apollinaire.paris4.sorbonne.fr (8.11.6/8.11.6) with ESMTP id fAJKRfY03543

for <Thierry.Besancon@localhost>; Mon, 19 Nov 2001 21:27:41 +0100 (MET)

Received: from sorbon.sorbonne.fr [195.220.107.3]

by localhost with POP3 (fetchmail-5.9.4)

for Thierry.Besancon@localhost (single-drop); Mon, 19 Nov 2001 21:27:41+0100 (MET)

Received: from neodata.com ([206.27.153.2])

by sorbon.sorbonne.fr (8.11.0/jtpda-5.3.3) with ESMTP id fAJKQnO06486

for <[email protected]>; Mon, 19 Nov 2001 21:26:50+0100 (MET)

Received: from bennett (bennett.neo.comm.eds.com [192.85.230.134])

by neodata.com (8.10.2+Sun/8.9.1) with ESMTP id fAJKRBK17328;

Mon, 19 Nov 2001 13:27:11 -0700 (MST)

Received: by bennett (8.8.8+Sun/SMI-SVR4)

id NAA14733; Mon, 19 Nov 2001 13:26:57 -0700 (MST)

Date: Mon, 19 Nov 2001 13:26:57 -0700 (MST)

From: [email protected]

X-Gnus-Mail-Source: directory:~/Mail/incoming/

Message-Id: <200111192026.NAA14733@bennett>

To: [email protected]

Subject: NEW ORDER

Suite sur transparent suivant

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 240 / 803

Page 140: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.7 Boites aux lettres : folder MBOX

Structure d’un mail (suite) :

X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/)

X-UIDL: Tjg!!<n*"!6i+"!J@O!!

Status: RO

X-Content-Length: 299

SYS ADMIN appreciates your inquiry and welcomes the opportunity to serve

your needs.

En résumé :une ligne commencant par « From » (attention à l’espace suivant leFrom)autres entêtesune ligne blanche marquant la fin des entêtes et le début du corps dumailcorps du mailune ligne blanche après le corps du mail

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 241 / 803

6 Courrier électronique 6.7 Boites aux lettres : folder MBOX

Structure d’un mail (suite) :

Attention : si le corps du message contient une ligne commencant par« From », la ligne est transformée en « >From ». Pourquoi ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 242 / 803

Page 141: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.7 Boites aux lettres : folder MBOX

Le format folder MBOX est manipulable par plusieurs MUA.Le MUA le plus simple pour cela est la commande « Mail » (ou « mail »ou « mailx »).% Mail"/var/mail/besancon": 4 messages 4 new

>N 1 [email protected] Thu Aug 24 01:45 32/1175 Output from "cron" comman

N 2 [email protected] Fri Aug 25 01:45 32/1175 Output from "cron" comman

N 3 [email protected] Sat Aug 26 01:45 32/1175 Output from "cron" comman

N 4 [email protected] Mon Aug 28 00:27 44/1624 Account details for besan

---> 4

From [email protected] Mon Aug 28 00:27:00 2006

Date: Mon, 28 Aug 2006 00:24:59 +0200 (MEST)

To: [email protected]

Subject: Account details for besancon at drupal

MIME-Version: 1.0

Content-transfer-encoding: 8Bit

From: [email protected]

besancon,

Thank you for registering at drupal. You may now log in to http://drupal.imj.local/informatique/?q=user using the following username and password:

username: besancon

password: urM87U9eFic©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 243 / 803

6 Courrier électronique 6.8 Boites aux lettres : folder MAILDIRChapitre 6 • Courrier électronique§6.8 • Boites aux lettres : folder MAILDIR

Un fichier stocke un seul mail.

⇒ Plus de problème de verrouillage du fichier lors des lectures/écritures.

« http://www.courier-mta.org/mbox-vs-maildir/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 244 / 803

Page 142: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.8 Boites aux lettres : folder MAILDIR

En résumé :une ligne commencant par « From » (attention à l’espace suivant leFrom)autres entêtesune ligne blanche marquant la fin des entêtes et le début du corps dumailcorps du mail

Attention :si le corps du message contient une ligne commencant par « From »,la ligne n’est pas transformée. Pourquoi ?pas de ligne blanche après le corps du mail. Pourquoi ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 245 / 803

6 Courrier électronique 6.8 Boites aux lettres : folder MAILDIR

Comment stocker les mails au format MAILDIR ?

⇒ La structure d’un folder MAILDIR appelé « FOLDER » impliqueplusieurs répertoires :

« FOLDER/new »« FOLDER/cur » (cur pour current)« FOLDER/tmp »

Le MDA place un nouveau mail d’abord par le répertoire « FOLDER/tmp »temporairement le temps de calculer un nom de fichier unique.

Le nouveau mail est ensuite placé dans le répertoire « FOLDER/new » parle MDA.

La lecture d’un mail entraine son déplacement de « FOLDER/new » vers« FOLDER/cur » avec ajout d’un suffixe indiquant les opérations faites parle MUA sur le mail.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 246 / 803

Page 143: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.8 Boites aux lettres : folder MAILDIR

Le nom du fichier stockant un mail doit être unique et en général a leformat « time.pid.host ». Voir :

« http://www.qmail.org/man/man5/maildir.html »« http://cr.yp.to/proto/maildir.html »

Par exemple :1185708514.M707068P58898V0700FF01I06974E18_1.mail..example.com,S=989 :2,S avec :

1185708514 = temps depuis l’origine en secondes ;ctime(1185708514) = Sun Jul 29 13:28:34 2007

M707068 = compteur en microsecondes de « gettimeofday() »P58898 = process ID du MDAV0700FF01 = UNIX device numberI06974E18 = UNIX inode numbermail.example.com = nom de la machine UNIX du MDAS=989 = taille du mail en octets

1185188613.000035.mbox:2,RS ; ici c’est le résultat d’uneconversion par le programme MB2MD

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 247 / 803

6 Courrier électronique 6.8 Boites aux lettres : folder MAILDIR

Après manipulation par le MUA, on ajoute un suffixe « :2,flags » avecflag :

flag « P » (Passed) = mail resent/forwarded/bouncedflag « R » (Replied) = mail réponduflag « S » (Seen) = mail luflag « T » (Trashed) = mail mis à la poubelleflag « D » (Draft) = mail brouillonflag « F » (Flagged) = mail taggé pour usage ultérieur

Par exemple :1185708514.M707068P58898V0700FF01I06974E18_1.mail.

example.com,S=989 :2,S

1185188613.000035.mbox :2,RS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 248 / 803

Page 144: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.8 Boites aux lettres : folder MAILDIR

Possibilité de folders MAILDIR imbriqués. Par exemple :

ce qui donnera sous UNIX lesrépertoires« .system.sa-blacklist/ »,« .system.sa-false-negative/ »,« .system.sa-false-positive/ »,« .system.sa-whitelist/ »(avec les classiques sous-répertoires« cur », « new » et « tmp »)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 249 / 803

6 Courrier électronique 6.8 Boites aux lettres : folder MAILDIR

On peut convertir un folder MBOX vers un folder MAILDIR :« http://batleth.sapeinti-sat.org/projects/mb2md.html »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 250 / 803

Page 145: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.9 Protocole de consultation : POPChapitre 6 • Courrier électronique§6.9 • Protocole de consultation : POP

Serveur de

mails

POP

ClientPOP

Mail folders

SMTP

download des mails

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 251 / 803

6 Courrier électronique 6.9 Protocole de consultation : POP

POP ≡ Post Office Protocol ; RFC ? ? ?

Port POP : 110

Port POP + SSL : 995

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 252 / 803

Page 146: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.10 Protocole de consultation : IMAPChapitre 6 • Courrier électronique§6.10 • Protocole de consultation : IMAP

Serveur de

mails

IMAP

ClientIMAP

Mail folders

SMTP

download des entetes des mails

download des corps des mails sur demande

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 253 / 803

6 Courrier électronique 6.10 Protocole de consultation : IMAP

RFC 2060 (protocole IMAP4rev1), RFC 2086 (ACL, extension de IMAP4),RFC 2087 (quota, extension de IMAP4)

Port IMAP : 143

Port IMAP + SSL : 993

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 254 / 803

Page 147: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.11 Comparaison de session POP et IMAP xxxChapitre 6 • Courrier électronique§6.11 • Comparaison de session POP et IMAP xxx

Comparatif de session POP et IMAP : (extrait de« http://cri.univ-lyon2.fr/doc/ImapMaisCEstTresSimple.html »)

% telnet pop.example.com 110+OK POP3 server ready

USER pdupont

+OK Name is a valid mailbox

PASS XXXXXXXX

+OK Maildrop locked and ready

LIST

+OK scan listing follows

1 169

2 811

3 813

% telnet imap.example.com 143

* OK IMAP4 server ready

. LOGIN pdupont XXXXXXXX

. OK User logged in

. SELECT INBOX

* FLAGS (Answered Flagged Draft Deleted Seen)

* OK [PERMANENTFLAGS (Answered Flagged Draft Deleted Seen *)]

* 3 EXISTS

* 3 RECENT

* OK [UNSEEN 1]

* OK [UIDVALIDITY 901006906]

. OK [READ-WRITE] Completed

. UID FETCH 1:* RFC822.SIZE

* 1 FETCH (UID 1425 RFC822.SIZE 169)

* 2 FETCH (UID 1426 RFC822.SIZE 811)

* 3 FETCH (UID 1427 RFC822.SIZE 813)

. OK Completed

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 255 / 803

6 Courrier électronique 6.11 Comparaison de session POP et IMAP xxx

RETR 1

+OK Message follows

Return-Path: <[email protected]>

From: [email protected]

To: [email protected]

Subject: essai chien chapeau

essai chien chapeau

.

DELE 1

+OK message deleted

QUIT

+OK

Connection closed by foreign host.

. UID FETCH 1425 BODY[]

* 1 FETCH (FLAGS (Recent Seen) UID 1425 BODY[] 169

Return-Path: <[email protected]>

From: [email protected]

To: [email protected]

Subject: essai chien chapeau

essai chien chapeau

. OK Completed

. UID STORE 1425 +FLAGS (Deleted)

* 1 FETCH (FLAGS (Recent Deleted Seen) UID 1425)

. OK Completed

. EXPUNGE

* 1 EXPUNGE

* 2 EXISTS

* 2 RECENT

. OK Completed

. LOGOUT

* BYE LOGOUT received

. OK Completed

Connection closed by foreign host.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 256 / 803

Page 148: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.12 AntivirusChapitre 6 • Courrier électronique§6.12 • Antivirus

Plusieurs antivirus sont disponibles sous UNIX :

CLAMAV (gratuit) ; « http://www.clamav.org »SOPHOS (commercial) ; « http://www.sophos.com »nombreux autres logiciels commerciaux

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 257 / 803

6 Courrier électronique 6.13 AntispamChapitre 6 • Courrier électronique§6.13 • Antispam

Plusieurs antispam sont disponibles sous UNIX :

BOGOFILTER (gratuit) ;« http://bogofilter.sourceforge.net »DSPAM (gratuit) ; « http://dspam.nuclearelephant.com »SPAMASSASSIN (gratuit) ; « http://www.spamassassin.org »AMAVIS (gratuit) ; « http://www.amavis.org »nombreux autres logiciels commerciaux

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 258 / 803

Page 149: Administration UNIX - Cours Jussieu - 2009-2010

6 Courrier électronique 6.13 Antispam

� Humour :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 259 / 803

6 Courrier électronique 6.14 Annexe 1Chapitre 6 • Courrier électronique§6.14 • Annexe 1

Ci joint dans la version imprimée de ce cours, un document sur laconception d’une messagerie.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 260 / 803

Page 150: Administration UNIX - Cours Jussieu - 2009-2010

The following paper was originally published in theProceedings of the USENIX Symposium on Internet Technologies and Systems

Monterey, California, December 1997

For more information about USENIX Association contact:

1. Phone: 510 528-86492. FAX: 510 548-57383. Email: [email protected]. WWW URL: http://www.usenix.org/

A Highly Scalable Electronic Mail Service Using Open Systems

Nick Christenson, Tim Bosserman, David BeckemeyerEarthLink Network, Inc.

Page 151: Administration UNIX - Cours Jussieu - 2009-2010

A Highly Scalable Electronic Mail Service Using Open Systems

Nick Christenson, Tim Bosserman, David Beckemeyer

EarthLink Network, Inc.

Information Technology

Pasadena, CA 91107

[email protected], [email protected], [email protected]

Abstract

Email is one of the most important of the Inter-

net services. As a very large, fast growing, Internet

Service Provider, EarthLink requires a robust and

powerful email architecture that will support rapid

expansion. This paper describes such an architec-

ture, its motivations, its future, and the di�culties

in implementing a service on this scale.

1 Introduction

Electronic mail has a special standing in the ranksof Internet services. Of the direct services an ISPprovides to its subscribers, email is certainly one ofthe most important. As a consequence, it requiresspecial attention to keep email running as well asexpected. Additionally, there are several issues thatare far more problematic for email than for otherservices. Email typically requires more resourcesthan any other service. This is because the stor-age needs, the processing power, and the bandwidthrequirements are extreme. Furthermore, there areproblems regarding authentication and provisioningthat are often not required for other services.Despite its criticality, little work has been made

available publicly on robust, large scale electronicmail systems. The few references we have found,such as [Grubb96], have neither addressed what weconsider to be the key problems, nor have they beenable to scale to the capacity that we require. Thisisn't too surprising. Providing email service for hun-dreds of thousands or millions of users is a problemnobody had to solve before the advent of the na-tional or international Internet or on line serviceprovider. Until now, none of these organizationshave chosen to come forward and publish their ser-vice architecture.Additionally, the architecting of very high per-

formance truly distributed services is still in its in-fancy. The issues of distributed storage and load

balancing have few, if any, available solutions thatare both robust enough and perform satisfactorilyfor our purposes.

The astute reader will certainly notice that thearchitecture we describe here bears a great dealof similarity to what we have already described asour news service architecture [Christ97a]. This, ofcourse, is no accident. We've found a general set ofprinciples which we have adapted to meet the needsof both services, and many of the important issuesdiscussed in that article are equally applicable here.

In the design of any of our service architectures,we have several requirements that must be met be-fore we would consider deployment. For email, the�rst of these is message integrity. It is absolutelyessential that messages, once they are accepted byour system, be delivered to their proper destinationintact. Second, the system must be robust. That is,in as much as is possible, the system should survive

component outages gracefully. Additionally, the en-tire system design should minimize the number ofsingle points of failure. Third, the system must bescalable. When EarthLink began deployment of thecurrent architecture, in January of 1996, we hadabout 25; 000 subscribers. In September of 1997,EarthLink provided email service for over 350; 000subscribers with a 99.9+% service uptime record. Infact, we expect the current system to scale to wellover 1; 000; 000 users without signi�cant alterationof the architecture as presented here. Moreover, oneshould be able to accomplish the scaling of any ser-vice with a minimum of outage time, preferably withnone. In all cases the performance of the servicemust be at least adequate, and the service must bemaintainable. Problems must be easily recogniz-able, and it should be obvious, whenever possible,what is the cause of the outage. Further, its solu-tion should be easy to implement and, in the mean-time, the impact of the outage should be small andlocally con�ned. Finally, we would like the servicearchitecture to be cost{e�ective, not just in terms of

Page 152: Administration UNIX - Cours Jussieu - 2009-2010

equipment acquisition, but, more critically, in termsof maintenance.

2 Architecture Description

There are several logically distinct componentswhich make up the operation of EarthLink's emailservice. The �rst, which we call the \front end" ofour email system (front de�ned as the portion whichreceives data from the Internet) are the systems thatreceive mail for \[email protected]". Thesemachines are also called the SMTP machines. Thesecond component is the POP service, the serversto which subscribers connect to retrieve their mail.These same computers also send the mail originat-ing from our subscribers to the Internet. (At thetime of this writing, EarthLink has not deployedan IMAP service.) The third component is the �leservers, which do nothing except store the mail-boxes, mail queues, and auxiliary �les associatedwith the email service. The fourth component isthe authentication database which holds the user-name/password information, information on wheremailboxes are stored, and data on auxiliary emailservices to which that account may have subscribed.This architecture is demonstrated graphically inFigure 1 included at the end of this paper. All theservers we use in this architecture, except for the�le servers, are running some avor of Unix.

With the exception of our �le servers and the au-thentication database servers, our architecture callsfor all of the servers involved in our email service (aswell as all our other services) to be dataless. That is,each server should store on local disk its own oper-ating system, service software, swap space, tempo-rary �le storage for nonessential data|and nothingelse. This allows us to add or subtract servers fromservice with which the Internet or our subscribersinteract without a�ecting the data stored.

2.1 Front End

Mail Exchange (MX) DNS records for earth-link.net and mail.earthlink.net point, with highpreference, to a series of servers in Round Robin.These servers all run a recent version of the freelydistributable stock sendmail [Allman86] as theirSMTP MTA (Simple Mail Transfer Protocol, MailTransfer Agent; see [Postel82] for details). Writingand maintaining an SMTP MTA is a di�cult andexpensive task. Therefore, we have geared our ar-chitecture to allow us to use sendmail without anysource modi�cation. Since sendmail typically un-

dergoes several signi�cant revisions during each cal-endar year, it's important that we be able to usesendmail in a form as close to the stock distributionas possible, since updating a modi�ed sendmail ev-ery few months to re ect local modi�cations wouldbe about as time consuming as maintaining our ownMTA.

An electronic mail message to be delivered to\[email protected]" follows the DNS MXrecords for earthlink.net. We maintain severalmachines with high precedence MX records usingRound Robin DNS to distribute the load. If any ofthese machines become overloaded or otherwise un-available, we maintain a single machine with a lowerprecedence MX record to act as a spillway. Thisserver does not deliver email directly, but it doeshold it for forwarding to the �rst available front endserver. Our backup MX machine could easily becon�gured to deliver email itself, but we have cho-sen not to do this to protect against the possibilityof transient errors in the mailbox locking process.This way, if the locking scheme becomes overloaded,we have a server that can still accept mail on behalfof the \earthlink.net" domain. It is our intention tominimize at all times the amount of email queuedaround the Internet for delivery to EarthLink.

The key to using the stock sendmail in our ar-chitecture is to insure that the sendmail programitself attempts to do no authentication or lookup ofuser names. This is actually quite simple to do. Onemerely must remove the \w" ag in the entry for thelocal delivery agent in the sendmail.cf �le. Evenif one runs a standard authentication scheme, we'vefound that this modi�cation provides a considerableperformance boost if one has a large, unhashed (i.e.linear lookup) passwd �le, and the service is notcompletely inundated with email intended for non{existent users.

The portion of the mail reception service thatwe did modify heavily was the mail delivery agent.This is the program that receives the mail from theMTA and actually appends it to the user's mail-box. On most systems, this program is /bin/mail.The sendmail distribution provides a delivery agentcalled mail.local which we have rewritten to useour authentication methods and understand how westore mailboxes. This is a small program whichhasn't changed substantially in years, so it is easy tomaintain; hence, it is a better place to add knowl-edge about our email architecture than a movingtarget like sendmail.

In addition to authentication and mailbox loca-tion, the mail delivery agent also knows about mail-box quotas which we impose on our subscribers. If

Page 153: Administration UNIX - Cours Jussieu - 2009-2010

the current mailbox size is over the quota for thatuser, the default being 10 MB, then the message isbounced back to the MTA with reason, \User npc,mailbox full." In addition to preventing resourceabuse on the part of subscribers, this also helps mit-igate possible damaging e�ects of mail bombing bymalicious people on the Internet. We believe that a10 MB quota is quite generous, especially consider-ing over a 28.8 modem using very high quality linespeeds and no network bottlenecks, one could ex-pect to take over an hour to download the contentsof a 10 MB mailbox.

2.2 POP Daemon

What we call the \back end" of our architectureis a set of machines using Round Robin DNS whichact as the POP servers. They are the targets of theA records, but not the MX records, for earthlink.netand mail.earthlink.net. These are the servers towhich the subscribers connect to retrieve and sendemail. If these machines receive email bound [email protected] (from our subscribers, Internetmachines compliant with the SMTP protocol mustfollow the MX records and send this message to afront end machine), these messages are redirectedto our SMTP machines at the front end. The POPservers do no local delivery. They do, however, de-liver directly to the Internet. We've debated thenotion of having the POP servers forward mail onto yet another set of servers for Internet delivery,but have thus far elected against it. The bene�tto doing this would be further compartmentaliza-tion of physical server function by logical operation,which we consider to be inherently good. We'd alsoreduce the likelihood of POP session slowdowns inthe case that a subscriber oods the server with aninordinate amount of mail to be delivered. If thePOP and Internet delivery functions were separate,the POP server would expend very few resources tohand this mail o� to the delivery servers, whereasit would otherwise be required to try to send andpossibly queue this mail itself. On the other hand,we don't observe this being a signi�cant problem.Additionally, if we had a separate Internet deliveryservice within our mail architecture, we'd have todeploy an additional machine to maintain our com-plete N+1 redundancy to every component, at ad-ditional cost. Someday, we probably will make sucha separation, but it does not seem to be justi�ed forthe present volume.

Like the delivery agent, the POP daemon mustalso know about both our modi�ed authenticationsystem and mailbox locations. The base implemen-

tation we started with was Qualcomm's POP dae-mon version 2.2, although like mail.local, we havemodi�ed it substantially. In the near future, we planto completely rewrite the POP daemon tuned for ef-�ciency in our environment implementing many ofthe lessons learned from developments in Web serversoftware.

2.3 Mailbox Storage

On a conventional Unix platform, mailboxes aretypically stored in /var/mail or /var/spool/mail.The passwd �le, used to store valid user namesfor incoming mail and to authenticate POP con-nections, is usually located in /etc, and mailwhich cannot be delivered immediately is stored in/var/spool/mqueue. This is where our mail archi-tecture started out as well, but we made some sig-ni�cant changes as we went along.

As with Usenet news, we use the Network Appli-ance [Hitz95] family of servers as our network �lestorage for essentially the same reasons: Very goodperformance, high reliability of the systems, easymaintenance, and the advantages provided by theWAFL �lesystem [Hitz94].

Due to performance considerations, the spool issplit across several �le servers and each is mountedon the SMTP and POP servers as /var/mail#,where # is the number of the mount point, in singledigits as of this writing.

Currently, we're using version 2 of the NFS pro-tocol. While version 3 does give some signi�cantperformance bene�ts, we give it all back because ofthe implementation of the READDIRPLUS proce-dure [Callag95] which prefetches attribute informa-tion on all �les in that directory, whether we needthem or not. Since we store a large number of �lesin the same directory and are only interested in op-erating on one of them at a time, this is signi�cantoverhead that we don't need. On balance, for ouremail system, the performance di�erence betweenversions 2 and 3 of the NFS protocol is so small asto defy precise measurement. We typically changeit whenever we suspect the current version mightbe responsible for some strange behavior we notice.The NFS version has never turned out to be theproblem, so we usually leave that version in placeuntil we feel the need to change it again in order toeliminate it as a factor in some other problem weface.

Even though the Network Appliance's WAFL�lesystem provides excellent protection against theperformance penalties one normally encounterswhen there are very large numbers of �les in a single

Page 154: Administration UNIX - Cours Jussieu - 2009-2010

directory using most other �le systems, there arestill signi�cant advantages to breaking them up fur-ther. Since we have more �les and require morestorage and throughput than we can realize withany one �le server, we need to split the spool up andprovide some mechanism to locate mailboxes withinthis tree. So, we create a balanced hash for eachmailbox over 319 possible subdirectories (the primebase of the hash) and divide these directories overthe number of �le servers that compose the spool.Thus, a path to a mailbox may look something like/var/mail2/00118/npc. The POP daemon and thelocal delivery agent are the only parts of the mailsystem that need to know about these locations.

Once we have this mechanism for multiple loca-tions of mailboxes in place, we are able to extendthis to allow us to dynamically balance the mail-boxes or expand capacity. In addition to the no-tion of the \proper" location of each mailbox, bothmail.local and popper (the POP daemon) un-derstand the notion of the \old" mailbox location.If the system receives email for a given mailbox,mail.local checks the \proper" location for themailbox, and if it �nds it there, appends the messagein the normal manner. If the mailbox isn't there, itchecks the \old" location for the mailbox. If it isfound there, mail.local locks the mailbox in bothlocations, moves it to the new location and appendsthe message in the normal manner. If the mailboxexists in neither place, it creates a new mailbox inthe \proper" location. The POP daemon also knowsthis information. It looks in the \proper" location�rst, and if it is not there, it consults the \old" lo-cation. In either case, it operates on the mailboxentirely in the place where it was found.

Only mail.local actually moves the mailbox.We felt that it would be better to con�ne the mail-box moving logic in the simpler of the two programs.Because the mailbox can only be in one of the twoplaces and the delivery agent and POP daemon usea common locking system (described below), there'sno danger of confusion as to the mailbox location.

The data on what constitutes the \old" and\proper" mailbox locations are kept in the authen-tication database (explained below), and this infor-mation is returned to the client process when au-thentication information is accessed.

This feature has a major bene�t for our mail sys-tem. This allows us to move large numbers of mail-boxes around without interrupting service. For ex-ample, if we have three �le servers containing mail-boxes and they are either getting to be full or run-ning out of bandwidth capacity, we can create a newmount point, /var/mail4 for instance, mount a new

�le server on the mail servers, create the hash valuesubdirectories that will reside there, and then slide anew mail.local and popper in place (POP daemon�rst!) that know which of the subdirectories fromeach of the �rst three �le servers will now be housedon the fourth. Then, as mailboxes receive new mail,they are moved onto the new �le server. After a fewhours, days, or weeks (depending on how much ofa hurry we're in), we can start a second process ofindividually locking and moving mailboxes indepen-dent of any other activity on the systems. Thus, wehave now expanded our email system without anydowntime.

2.4 Authentication

One thing we quickly realized is that the stan-dard Unix authentication systems were wholly in-adequate for a service of this magnitude. The �rstproblem one runs into is that depending on the spe-ci�c operating system, one is typically con�ned tobetween 30; 000 and 65; 535 distinct user identities.Fortunately, since none of these users have shell ac-cess to these servers (or any access other than POPaccess), we can have a single UID own every one ofthese mailboxes as long as the POP daemon is care-ful not to grant access to other mailboxes withoutre{authenticating.

While this postpones several problems, it isn'tsu�cient by itself to scale as far as we'd like.First, several Unix operating systems behave quitestrangely, not to mention inappropriately, when thepasswd �le exceeds 60; 000 lines. This isn't com-pletely unexpected|after all how many OS ven-dor test suites are likely to include these cases|but some of these problems manifest themselves agreat distance from the passwd �le and, thus, canbe di�cult to track. Just as important, when thepasswd �le gets this large, the linear lookups ofindividual user names become expensive and timeconsuming. Therefore, the �rst thing we did wasmake a hashed passwd{like �le using the BerkeleyNEWDB scheme [Seltze91] that both popper andmail.local would consult for authentication. Thiseliminated the need to carry a large passwd �le andgreatly increased performance of the system. A sep-arate machine working in a tight loop continuallyrebuilt the hashed passwd �le as the text �le wascontinually being modi�ed by the the new accountprovisioning system.

The next logical extension of this was to storethe passwd �le in a SQL database and replacegetpwnam() calls with SQL equivalents. This pro-vides another quantum improvement. First, this

Page 155: Administration UNIX - Cours Jussieu - 2009-2010

eliminates the necessity of continually rebuilding thehash �le from the at �le, with savings in proces-sor and delay times for user account modi�cation.Second, this database may be used by other appli-cations including RADIUS [Rigney97], Usenet news,etc.... Third, it's a logical place to store additionalimportant information about that account. For ex-ample, when a username lookup by mail.local

or a username/password pair is authenticated forpopper, the \old" and \proper" mailbox locationsare returned to the application rather than havingto be stored in at �les on the system or hardcodedinto the respective binary. We also intend to usethis database as a repository for a great deal moreinformation, for example storing variable mailboxquotas and lists of domains from whom to refusemail on a user by user basis, etc....

Obviously, this database is critical to not onlythe operation of our electronic mail system, but toother components of our overall service architectureas well. If the authentication service isn't operating,electronic mail comes to a halt. Because of this, wehave taken special pains to make certain that thisapplication is always on line by using a clusteredsystem with failover using a dual attached storageunit for the database to meet our high availabil-ity requirements. If it becomes necessary, we canstill fail over to the old common hashed passwd �lewith only a marginal loss of functionality and per-formance.

2.5 File Locking

In any distributed system, concurrency issues areof paramount importance. In our email system,these manifest themselves in terms of �le locking.It is so important, we have given the topic its ownsection in this paper to discuss the issues which theimplementor faces.

Yesterday

For data stored on local disk, flock() su�ces toward against two processes attempting to processthe same message or modify the same mailbox atthe same time. Since all of our persistent data isaccessed over NFS, this presents some signi�cantproblems for us.

When using flock() on an NFS mounted �lesystem, these calls get translated to requests viarpc.lockd. Now, lockd isn't the most robust �lelocking mechanism ever devised. It isn't advisableto bank on lockd working entirely as advertised. Inaddition to this, many systems have lockd tables too

small for our purposes. We can routinely requirethousands of outstanding lock requests on a givenNFS mounted �lesystem at any one time, and fewcommercial solutions have lock tables large enoughand/or lock table lookup algorithms fast enough tomeet our needs.

Today

Therefore, wherever possible, we use the �le sys-tem to perform locking. This consists of requestingan open() system call to create a new (lock) �lewith the O EXCL ag of a �le of a predeterminedname, typically mailboxname.lock, in a given loca-tion, which would typically be the mail spool. Inour case, in order to keep the spool directory sizesdown as much as possible and performance as highas possible, we store these �les on their own shared�le system.

This may set o� alarms in the heads of those fa-miliar with NFS. One might well ask, \How can yoube certain that this is atomic on an NFS system?How do other clients know that one has locked agiven �le?" Recent implementations of NFS clientsoftware ignores the attribute cache on open() callswhich attempt to exclusively create a new �le. Note,however, that other open() calls do not ignore theattribute cache. This means that if a process's ex-clusive open() on the lock �le succeeds, that processhas successfully locked that �le. This allows us touse �le locking on the mailboxes, as long as we aremortally certain that all NFS clients operate in ex-

actly the same way. One can �nd both NFS v2 andv3 implementations that behave this way. It cannotbe overstated how important it is to be certain thatall NFS clients behave in this manner.

It is always possible that the process which cre-ates the lock will die without having the opportunityto remove it. For this reason, all processes creatinglocks must touch the lock �les to update their at-tributes periodically so that if these processes die,after a certain amount of time other processes willknow that an existing lock is no longer valid and canbe eliminated. Therefore, we need a function that,again, will bypass the cache and be guaranteed toimmediately update the attributes on the lock �le.

Let us suppose that one process on one NFS clienthas created a lock on the mailbox \npc". Let us alsosuppose that a process on a di�erent NFS client thentried to lock that mailbox immediately afterwardsand discovered the existing lock, as it must. It'salways possible that the �rst process has somehowdied, so it's important to understand how long thesecond process must wait before it can assume that

Page 156: Administration UNIX - Cours Jussieu - 2009-2010

the �rst process no longer exists, at which time itcan delete the lock �le, lock the �le itself, and per-form operations on that mailbox. Again, let us sup-pose that all the NFS clients are set to refresh theirmailbox lock every �ve minutes, and that the NFSattribute cache is set on each client to be three min-utes.

One scenario is for a process on client1 to suc-cessfully lock the mailbox and then have client2 im-mediately attempt to lock the same mailbox andfail. At this point, the information on the lockedmailbox is saved for three minutes, the durationof the attribute cache, after which client2 gets thesame attribute information as before, because �veminutes has not elapsed, therefore client1 has notyet refreshed the lock. At the �ve minute mark,client1 refreshes the lock �le using utime(), sinceit also bypasses the NFS cache and operates syn-chronously on the lock �le, but client2 has not no-ticed because it will be looking at the attributes inits cache until the six minute mark, when its cacheexpires, and it can now gets the updated informa-tion. This is represented graphically in Figure 2.

minutes0 1 2 3 4 5 6

client2 gets same lock infoclient1 refreshes lockclient 2 notices new lock

client1 locks mboxclient2 attempts to get lockAttribute cache on client2 expires

Figure 2

The worst case scenario is presented in Figure 3.Here we have client1 creating a lock on a mailboxand then immediately dying. Just before the lockis scheduled to be updated, client2 attempts to lockthe mailbox and fails. Client2 cannot learn that thelock hasn't been updated until just before the eightminute mark, at which point it has license to removethe lock �le and proceed with its actions.

Unfortunately, this potentially gives us a windowof eight minutes in which real users may not be ableto access their mailboxes under pathological condi-tions. For example, if the subscriber interrupts aPOP session at the wrong moment, the POP dae-mon on the mail server may exit without cleaningup its lock �le. Further, we explain below why wemust delay even longer than this to allow for other

concerns.

If the �le servers ever get saturated with requests,the server can seem to \disappear" to client pro-cesses for many seconds or even minutes. This canhappen as part of normal subscriber growth if onedoes not upgrade the capacity to handle load be-fore it is needed. In these circumstances, problemsusually manifest themselves as a sudden change inperformance response from acceptable to unaccept-able over a very small change in load. The math-ematicians would call this a catastrophic response,where \...gradually changing forces produce suddene�ects." [Zeeman77] If a �le server's load is near,but not at the critical point, it can be pushed overthe edge by a sudden change in the pro�le of nor-mal email use or by a small number of malicious ornegligent individuals.

0 1 2 3 4 5 6 7 8

client2 attempts to get locklock expiresclient2 learns that lock expires

client1 creates lock

Figure 3minutes

client1 dies

It is self{evident that one wants to provide enoughsurplus performance to prevent small changes frombreaking the performance envelope, and certainlywe strive for this, yet it is not always possible. Asan example, consider a two week period in August1996 where the total volume of email EarthLink wascalled upon to handle doubled for reasons that arestill not fully understood. While not routine, theseevents are not uncommon in the ISP business and,because the subscriber has a much greater ability toimpact service, represent a fundamental di�erencebetween providing Internet services and, for exam-ple, providing electric power or dial tone service.

In any case, when one enters into one of thesecatastrophic regimes, one often encounters patho-logic behavior on the part of any or all of the com-ponents of the service. Client requests can cometoo fast for the server(s) to handle; consequentlythe RPC packets can get dropped before they areprocessed. This can result in retransmissions bymultiple clients, and on top of an already saturatedsystem, the problem is compounded.

Page 157: Administration UNIX - Cours Jussieu - 2009-2010

Let us suppose that we have a saturated sys-tem where the client base demand is 105% of theserver's capacity to deliver it over a given periodof time, not counting the load put on the serverbecause of retransmissions. Each of these clientswill now retransmit their requests after a numberof tenths of seconds speci�ed by the timeo valuein the /etc/vfstab or equivalent �le. If this re-quest does not receive a response, the client waitsfor twice timeo and retransmits again. This pro-cess is repeated until the value of the retry vari-able is reached. If retry is exceeded, then the clientprints a message, typically \NFS server raid not re-sponding, still trying," and continues to retry atthe maximum retry value. This maximum value willnever exceed 30 seconds [Stern91]. Under these con-ditions, we cannot achieve a \steady state" condi-tion, the amount of tra�c grows, quite dramatically,without bound until something breaks.

If this condition were to persist for 30 minutes, atthis time as much as 25% of the requests sent to theservers may be over 5 minutes old. Note that thisrepresents a true pathological condition, it's highlyunlikely that a client machine would either be ableto maintain this load given the lack of responsive-ness of the server, or that the client load would beconstant, but we haven't yet developed our math-ematical models su�ciently to account for all theknown variables, so we're being conservative. Giventhese assumptions, if we are adding 2; 000; 000 newemail messages to our spool in a day, a half an hourof operation at this level of saturation with a locktimeout of only 5 minutes, we must expect thereto be on the order of a thousand mailbox corrup-tions due to multiple processes proceeding to mod-ify mailboxes on the assumption that they have ex-clusive access to it. This is because they have en-countered expired lock �les which are actually valid,the owning process just hasn't been able to get theserver to ack it's update of the lock �le. The math-ematics behind this analysis and an in depth ex-amination of the rami�cations of this will be fullyexplored in [Christ97b]. Therefore, it is importantthat our locking mechanism allow for the possibilitythat a client process may not be able to get theirrequest through to the server for several minutes af-ter the normal locking timeout window has closed.We use a lock timeout value of 15 minutes to allowfor this possibility.

With regard to locking, one area of concern wehave is with sendmail. Current versions want to useflock() to lock �les in mail queues. On our emailsystem, the depth of these queues is extreme andthe number of processes that can concurrently be

trying to drain them can be as high as several hun-dred per machine, requiring a large number of out-standing lock requests at any one time, often toomany for either the client lock daemon or the �leserver to accommodate. Because of this, we havetwo choices. Either we can put the mail queueson locally attached disk, violating our stateless ar-chitecture principle and losing the bene�ts of theWAFL �le system in handling directories with largenumbers of �les, or we can modify sendmail to usea di�erent locking mechanism, thus violating ourintention to use an unmodi�ed SMTP MTA. For-tunately, the current sendmail implementation hasvery modular locking code which can be easily re-placed without fundamentally altering the distribu-tion. However, we'd like any folks working on send-mail to consider allowing a preference for variouslocking mechanisms to be #de�ne'd in the sourcecode.

Tomorrow

While the mailbox locking mechanism we've justdescribed has worked satisfactorily, it is not with-out its drawbacks. One drawback is the fact thatlocks may be orphaned, and other clients must waitup to 15 minutes before being able to assume theyare no longer valid. Another drawback is that thesynchronous NFS operations we employ greatly in-crease the load placed on the NFS servers whichhold the lock �les.

Therefore, we are in the process of designing and

building our next generation lock management sys-tem. In accordance with our design parameters,what we really want is a distributed lock systemwith no single points of failure. It has to maintainstate in the case of a crash or hardware failure, andit must be able to handle at least several hundredtransactions per second.

We tried using a SQL database for this purpose,but we were not satis�ed with the performance.A program like a large commercial database suchas this requires too much overhead to be e�cientin this manner. However, we can learn from thedatabase style locking mechanisms and, essentially,strip away those portions of the database systemwhich we don't need to create our own lean andmean network lock server.

We plan to deploy two machines clustered to-gether around a shared RAID system to act as ourlock service. If the primary machine were to su�ersome form of failure, the other would take over witha target transition time of less than �ve seconds. Weintend to deploy the same hardware con�guration

Page 158: Administration UNIX - Cours Jussieu - 2009-2010

that we use for our authentication database. Allthe lock requests get written to the �le system us-ing unbu�ered writes before they are acknowledgedso that in case of machine failure there is no loss ofstate.

The clients open up a socket to the lock daemonon the lock server and request a lock for a givenmailbox, which the daemon either accepts or denies.If it is denied, the client waits for some pseudo{random time and tries again. We project that thissystem will scale well into the millions of mailboxesfor a single set of lock managers. To get this schemeto scale inde�nitely, it's a simple matter of havingthe clients query di�erent lock servers for di�erentranges of mailbox names.

3 Operation

One of our primary design goals was to deploya system that would be cost{e�ective to maintain.This service accomplishes those goals in severalways.

First, by centralizing authentication in a singlesystem, we reduce the problems associated withboth maintaining multiple parallel authenticationsystems and insuring that they are synchronized.This is a considerable overhead savings.

Second, one of the key criteria in selecting theNetwork Appliance as our storage system was itsease of maintenance. Because its operating systemhas been stripped down, eliminating functionalitynot necessary to its operation as a �le server, theserver is less likely to fail and, if it does fail, it iseasier to discover and remedy the problem due tothe greatly reduced number of degrees of freedompresented by the operating system.

Third, because the POP servers themselves aredataless, they require much less maintenance thantheir stateful equivalents. The only �les which dif-fer between these computers are those that containtheir host names and/or IP addresses. This meansthat new servers can be brought online in a veryshort time via cloning an active server. Just as sig-ni�cant, it means that since these machines containno important persistent data (aside from the operat-ing system), there are few reasons for system admin-istration to log on to the system and make changes.This helps eliminate one of the arch{nemeses of dis-tributed computing|\state drift," the tendency forsystems intended to be identical or nearly identicalto become more and more di�erent over time.

At EarthLink, one of the things we do most of-ten is to grow an existing service to accommodate

more subscribers. The e�orts we have made to al-low this to happen easily and with a minimum ofinterruption contribute greatly to lowering the costof operation. We've already explained how we usethe concept of \old" and \proper" mailbox locationsto scale both �le system storage and bandwidth byadding additional �le servers easily and with nodowntime. The network implementation we're us-ing at this time is switched FDDI, which also scaleswell. As we've already mentioned the POP serversare dataless and, therefore, should lack of these re-sources present a problem, in very little time, andagain, with a minimum of e�ort, we can clone anddeploy a new system. This results in our email ser-vice being extremely scalable on short notice.

We attempt to maintain N +1 redundancy in ev-ery possible component of the system. Our datastorage systems use RAID to protect against sin-gle disk failure. We keep extra data storage serversnear{line in case of failure for rapid exchange withthe downed system. We keep extra FDDI cards inthe switch and an extra switch chassis nearby incase these components fail. We also keep one moreSMTP and POP server online than loading metricsindicate is necessary. Thus, if one fails, we can pullit out of Round Robin DNS without impacting ser-vice, aside from the problems caused by the initialcomponent failure. Additionally, we get the bene�tof not having to repair the failed server immediately.Instead, we can take time to ensure that everythingelse is in proper running order, and then we can di-agnose and repair the failed server at our leisure.On top of all this, we use a monitoring system that ags problems with each component of the servicein our Network Operations Center, which is sta�ed24x7x365 and contacts appropriate on{site person-nel.

4 Shortcomings

We consider the architecture presented above tohave considerable merit as one of the better solu-tions available for satisfying high volume mail ser-vice. It is, of course, not without its limitations,some of which we mention here. One of the �rstproblems is with sendmail as an MTA. When EricAllman developed the original sendmail, it was notenvisioned that it would still be in service over �f-teen years later and be pushed, rewritten, and ex-tended to the extent that it has. It is a testament tothe skill of its creator and maintainer that it has per-formed as well as it has for this long. Nonetheless,if one were to code an SMTP MTA today, we doubt

Page 159: Administration UNIX - Cours Jussieu - 2009-2010

anyone would want it to take the form of sendmail.Despite this, we don't see an MTA that would pro-vide enough signi�cant advantages that we wouldwant to migrate to it in the immediate future. Ofcourse, these statements about sendmail could havebeen uttered �ve years ago without alteration. Thebottom line is that we would prefer to run an SMTPMTA that is tighter, more e�cient, and has fewerpotential places for security bugs to creep in, butthere isn't one available that meets our needs atthis time.

Probably the biggest problem with our architec-ture is that due to the nature of NFS, when we addadditional �le servers to address our performanceand storage needs, we end up adding multiple singlepoints of failure. Despite the fact that the NetworkAppliance �le servers have been quite stable and re-cover quickly from problems, we feel that this is noteasily scalable forever. Therefore, it is our opinionthat at some point we need to abandon NFS as ourdistributed systems protocol for something better.

Our ideal protocol would be very high perfor-mance; be completely distributed and, thus, highlyscalable, local failures would cause local, not globaloutages, and would allow for redundant storage thateliminates local single points of failure. Unfortu-nately, given the current state of distributed com-puting, it's hard enough to �nd a system that ad-equately addresses one of these points, and noth-ing seems close to providing good solutions for allof them. Consequently, we are currently in theprocess of designing our own distributed system toaccommodate our next generation architecture re-quirements.

5 Current Data

Today, the system described here is in opera-tion as EarthLink's core electronic mail system.At the time of this writing, this system supportsabout 460,000 mailboxes for over 350,000 users.The system processes, incoming and outgoing, over13,000,000 email messages each week. This meanswe average about 20 incoming messages each sec-ond. We average about 20 new POP connec-tions/second and hold open about 600 concurrentactive POP daemons at peak time, with spikes toover 1000 concurrent outstanding POP connectionsat any one time.

6 Conclusion

In conclusion, we believe we have architecteda mechanism to extend a standard, freely dis-tributable, open systems email system to handlefrom hundreds of thousands to millions of distinctemail accounts with a minimum of modi�cation tothe underlying components. We also believe thatthis system meets, to the best of our ability to de-liver, the required criteria we set out in the Intro-duction.

7 Acknowledgments

The authors of this paper are by no means theonly folks who have put a lot of e�ort into the de-velopment and operation of this system. We wish toespecially thank Jay Cai and Max Chern who did asigni�cant portion of the software development onthis system. Thanks to Steve Dougherty and MarkWagnon, who provided helpful comments, and toJim Larson, who provided valuable input on the pre-cise mathematics of packet retransmissions. Also, agreat deal of thanks go to Trent Baker and his sys-tem administration team who maintain all our ser-vices: Gianni Carlo Contardo, Jason Savoy, MartyGreer, Alwin Sun, Horst Simon, Jewel Clark, TomHsieh, Lori Bar�eld, David Van Sandt, Larry Wang,Hong Zhang, and Kenny Chen. We also wish to ex-tend a special thank{you to Scott Holstad who mademany excellent editorial improvements to early ver-sions of this paper.

References

[Albitz97] P. Albitz, C Liu, DNS and BIND,

2nd Ed., O'Reilly & Associates, Inc., Se-bastopol, CA, 1997, p. 212.

[Allman86] E. Allman, Sendmail: An InternetworkMail Router, BSD UNIX Documentation Set,University of California, Berkeley, CA, 1986.

[Callag95] B. Callaghan, B. Pawlowski, P. Stau{bach, RFC 1813, NFS Version 3 Protocol Spec-

i�cation, June 1995.

[Christ97a] N. Christenson, D. Beckemeyer,T. Baker, A Scalable News Architecture ona Single Spool, ;login: vol. 22 (1997), no. 3,pp. 41{45.

[Christ97b] N. Christenson, J. Larson, Work inprogress.

Page 160: Administration UNIX - Cours Jussieu - 2009-2010

[Grubb96] M. Grubb, How to Get There FromHere: Scaling the Enterprise{Wide MailInfrastructure, Proceedings of the Tenth

USENIX Systems Administration Conference

(LISA '96), Chicago, IL, 1996, pp. 131{138.

[Hitz94] D. Hitz, J. Lau, M. Malcom, File Sys-tem Design for an NFS File Server Appliance,Proceedings of the 1994 Winter USENIX, SanFrancisco, CA, 1994, pp. 235{246.

[Hitz95] D. Hitz, An NFS File Server Appli-ance, http://www.netapp.com/technology/

level3/3001.html.

[Postel82] J. Postel, RFC 821, Simple Mail Trans-

fer Protocol, August 1982.

[Rigney97] C. Rigney, A. Rubens, W. Simpson,S. Willens, RFC 2058, Remote Authentication

Dial In User Service (RADIUS), January 1997.

[Seltze91] M. Seltzer, O. Yigit, A New HashingPackage for UNIX, Proceedings of the 1991

Winter USENIX, Dallas, TX, 1991.

[Stern91] H. Stern, Managing NFS and NIS,O'Reilly & Associates, Inc., Sebastopol, CA,1991, chapter 12.

[Zeeman77] E. Zeeman, Catastrophe Theory, Se-

lected Papers 1972-1977, Addison{Wesley Pub-lishing Company, Inc., Reading, MA, 1977,p. ix.

Page 161: Administration UNIX - Cours Jussieu - 2009-2010

Auth

FileServers

FileServers

Figure 1

INTERNET

SUBSCRIBERS

SMTP

POP & SMTP

NFS

NFSSMTP

SMTP Servers

POP Servers

ServiceAuthentication

Auth

Page 162: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 7

Gestionnaires de services réseau : inetd,tcpd, xinetd

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 261 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.1 Rappel sur les connexions IPChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.1 • Rappel sur les connexions IP

Rappel :Une connexion IP est constituée de plusieurs éléments :

une adresse IP sourceun numéro de port source sur la machine de départune adresse IP de destinationun numéro de port sur la machine de destinationprotocole TCP ou UDP

Attention :Sur UNIX, la fonction C obtenant un port source < 1024 nefonctionne que pour l’UID 0.Sur Windows, la fonction C obtenant un port source < 1024fonctionne quel que soit l’UID

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 262 / 803

Page 163: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.2 Fichier /etc/servicesChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.2 • Fichier /etc/services

Le fichier « /etc/services » mentionne des triplets (numéro de port,protocole, nom du service).

Le fichier « /etc/services » sert à convertir un port numérique en unnom symbolique plus parlant. Voir les fonctions C « getservbyname() »,« getservbyport() », « getservent() ».

ATTENTION : Le fichier « /etc/services »n’indique pas les services réseau activés sur lamachine.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 263 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.2 Fichier /etc/services

On peut obtenir un triplet officiellement pour un programme à soi auprèsde l’IANA « http://www.iana.org/assignments/port-numbers »

En pratique il y a 3 catégories de triplets :Les Well Known Ports sont ceux de 0 à 1023Les Registered Ports sont ceux de 1024 à 49151Les Dynamic and/or Private Ports sont ceux de 49152 à 65535

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 264 / 803

Page 164: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.2 Fichier /etc/services

Extrait d’un fichier « /etc/services » :

...

chargen 19/tcp ttytst source #Character Generator

chargen 19/udp ttytst source #Character Generator

ftp-data 20/tcp #File Transfer [Default Data]

ftp-data 20/udp #File Transfer [Default Data]

ftp 21/tcp #File Transfer [Control]

ftp 21/udp #File Transfer [Control]

ssh 22/tcp #Secure Shell Login

ssh 22/udp #Secure Shell Login

telnet 23/tcp

telnet 23/udp

smtp 25/tcp mail #Simple Mail Transfer

smtp 25/udp mail #Simple Mail Transfer

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 265 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.3 Commandes netstat -a, netstat -anChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.3 • Commandes netstat -a, netstat -an

La commande « netstat -a » affiche la liste des ports ouverts sur unemachine. Les noms affichés proviennent de « /etc/services » :

% netstat -aActive Internet connections (including servers)

Proto Recv-Q Send-Q Local Address Foreign Address (state)

tcp4 0 0 *.ssh *.* LISTEN

tcp46 0 0 *.ssh *.* LISTEN

udp4 0 0 *.syslog *.*udp6 0 0 *.syslog *.*udp4 0 0 *.bootpc *.*Active UNIX domain sockets

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 266 / 803

Page 165: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.3 Commandes netstat -a, netstat -an

La commande « netstat -an » affiche la liste des ports ouverts sur unemachine sans les traduire en noms via « /etc/services ». Ils sontaffichés sous forme numérique :

% netstat -anActive Internet connections (including servers)

Proto Recv-Q Send-Q Local Address Foreign Address (state)

tcp4 0 0 *.22 *.* LISTEN

tcp46 0 0 *.22 *.* LISTEN

udp4 0 0 *.514 *.*udp6 0 0 *.514 *.*udp4 0 0 *.68 *.*Active UNIX domain sockets

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 267 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.4 Gestionnaires de services réseauChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.4 • Gestionnaires de services réseau

Une machine UNIX offre de nombreux services accessibles par le réseau.

Souvent les services réseau contactés durent peu de temps :

inutile de les faire tourner en permanence (consommation deressources)on va les activer uniquement suite à une requête

On utilise alors un « gestionnaire de services » pour écouter les requêtespour certains services réseau et lancer ces services.

Plus particulièrement, le gestionnaire de services assure :

l’attente de connexions réseau sur certains portsle lancement des services contactésle comportement adapté au lancement de ces services

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 268 / 803

Page 166: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.4 Gestionnaires de services réseau

Il existe plusieurs gestionnaires de services :programme INETDprogramme XINETD

Autre programme TCPD :ce n’est pas un gestionnaire de servicesc’est un contrôleur de services

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 269 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.5 Gestionnaire de services réseau : INETDChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.5 • Gestionnaire de services réseau : INETD

Etape 1

réseau

client inetd

host2.example.comhost1.example.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 270 / 803

Page 167: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.5 Gestionnaire de services réseau : INETD

Etape 2

réseau

client

host2.example.comhost1.example.com

exec()

serveurinetd

fork()

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 271 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.5 Gestionnaire de services réseau : INETD

Etape 3

réseau

client

host2.example.comhost1.example.com

serveurinetd

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 272 / 803

Page 168: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.6 INETD : fichier de configuration /etc/inetd.confChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.6 • INETD : fichier de configuration /etc/inetd.conf

Le fichier « /etc/inetd.conf » est spécifique au gestionnaire de services« inetd ».

Son format est le suivant :

# Syntax for socket-based Internet services:

# service_name socket_type proto flags user server_pathname args

Par exemple :

...

ftp stream tcp nowait root /usr/sbin/in.ftpd in.ftpd

telnet stream tcp nowait root /usr/sbin/in.telnetd in.telnetd

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 273 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.6 INETD : fichier de configuration /etc/inetd.conf

La signification des champs est la suivante :

champ 1 : « service_name »C’est le nom symbolique d’un service (cf « /etc/services »).champ 2 : « socket_type »C’est le type du socket réseau. C’est essentiellement « stream »,« dgram ».champ 3 : « proto »C’est le protocole réseau utilisé : « tcp », « udp »champ 4 : « flags »Cela indique si l’on peut répondre à une requête du même type alorsque la première n’est pas terminée. On peut avoir : « wait »,« nowait »champ 5 : « user »Nom de l’utilisateur sous lequel le programme tournera.champ 6 : « server_pathname »C’est le chemin absolu du programme à exécuter.champ 7 : « args »Ce sont les paramètres à donner lors du « execv() ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 274 / 803

Page 169: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.6 INETD : fichier de configuration /etc/inetd.conf

Par exemple :

ftp stream tcp nowait root /usr/sbin/in.ftpd in.ftpd -l

donnera

execv("/usr/sbin/in.ftpd", "in.ftpd", "-l", 0);

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 275 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.7 INETD : reconfiguration via SIGHUPChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.7 • INETD : reconfiguration via SIGHUP

Inetd est lancé par les scripts de démarrage.

Si l’on modifie le fichier « /etc/inetd.conf », la modification est priseen compte en envoyant le signal « SIGHUP » au processus inetd :

# ps -ax | grep inetd173 ? IW 2 0:00 inetd

19544 p2 S 2 0:00 grep inetd

# kill -HUP 173

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 276 / 803

Page 170: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.8 INETD : problèmesChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.8 • INETD : problèmes

INETD fonctionne très bien en pratique.

Il a un seul gros défaut : il ne gère aucun aspect de sécurité.

On aimerait au moins :pouvoir filtrer l’accès à certains servicesavoir des traces d’activation de certains services

Un remède : emploi du logiciel TCP WRAPPERS« http://ftp.porcupine.org/pub/security/tcp_wrappers_7.6.tar.gz »« http://ftp.porcupine.org/pub/security/tcp_wrappers_7.6-ipv6.1.tar.gz »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 277 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.9 Gestionnaire de services réseau : TCP WRAPPERSChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.9 • Gestionnaire de services réseau : TCP WRAPPERS

L’idée de TCP WRAPPERS : on va s’intercaler dans la chaîne de INETD.

réseau

client inetd

host2.example.comhost1.example.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 278 / 803

Page 171: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.9 Gestionnaire de services réseau : TCP WRAPPERS

réseau

client

host2.example.comhost1.example.com

fork()exec()

inetd tcpd

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 279 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.9 Gestionnaire de services réseau : TCP WRAPPERS

réseau

client

host2.example.comhost1.example.com

inetd tcpd

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 280 / 803

Page 172: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.9 Gestionnaire de services réseau : TCP WRAPPERS

réseau

client

host2.example.comhost1.example.com

inetd tcpd serveur

fork()exec()

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 281 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.9 Gestionnaire de services réseau : TCP WRAPPERS

réseau

client

host2.example.comhost1.example.com

inetd tcpd serveur

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 282 / 803

Page 173: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.9 Gestionnaire de services réseau : TCP WRAPPERS

réseau

client

host2.example.comhost1.example.com

inetd serveur

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 283 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.9 Gestionnaire de services réseau : TCP WRAPPERS

La librairie des TCP WRAPPERS est maintenant intégrée àbeaucoup de produits (même sous WINDOWS...).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 284 / 803

Page 174: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.10 TCP WRAPPERS : modifications de /etc/inetd.confChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.10 • TCP WRAPPERS : modifications de /etc/inetd.conf

S’intercaler dans la chaîne de INETD nécessite de modifier le fichier« /etc/inetd.conf »

Par exemple on passe de :

ftp stream tcp nowait root /usr/etc/in.ftpd in.ftpd -l

telnet stream tcp nowait root /usr/etc/in.telnetd in.telnetd

shell stream tcp nowait root /usr/etc/in.rshd in.rshd

login stream tcp nowait root /usr/etc/in.rlogind in.rlogind

à

ftp stream tcp nowait root /chemin/vers/tcpd in.ftpd -l

telnet stream tcp nowait root /chemin/vers/tcpd in.telnetd

shell stream tcp nowait root /chemin/vers/tcpd in.rshd

login stream tcp nowait root /chemin/vers/tcpd in.rlogind

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 285 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.10 TCP WRAPPERS : modifications de /etc/inetd.conf

Rappel sur l’interprétation d’une ligne de « inetd.conf » :

Par exemple :

ftp stream tcp nowait root /chemin/vers/tcpd in.ftpd -l

donnera

execv("/chemin/vers/tcpd", "in.ftpd", "-l", 0);

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 286 / 803

Page 175: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd7.11 TCP WRAPPERS : contrôle d’accès, /etc/hosts.allow, /etc/hosts.denyChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.11 • TCP WRAPPERS : contrôle d’accès, /etc/hosts.allow, /etc/hosts.deny

Le principe du contrôle d’accès des TCP WRAPPERS repose sur lesfichiers « /etc/hosts.allow » et « /etc/hosts.deny » :

1 On vérifie d’abord si la requête TCP est autorisée par le contenu de« /etc/hosts.allow ».Si oui, OK.Si non, on passe à l’étape 2.

2 On vérifie si la requête TCP est interdite par le contenu de« /etc/hosts.deny ».Si oui, la requête est rejetée.Si non, on passe à l’étape 3.

3 On accepte la requête TCP.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 287 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd7.11 TCP WRAPPERS : contrôle d’accès, /etc/hosts.allow, /etc/hosts.deny

Au niveau des fichiers « hosts.allow » et « hosts.deny », on peutappliquer des règles de filtrage par service servi.

Voici un exemple de politique de connexion :

au niveau du fichier « /etc/hosts.allow » :in.telnetd: .fr, 193.95.32.

in.rlogind: .fr, 193.95.32.

in.rshd: .fr

au niveau du fichier « /etc/hosts.deny » :in.telnetd: ALL

in.rlogind: ALL

in.rshd: ALL

En français intelligible, ces fichiers indiquent que les connexions telnet,rlogin, rsh ne sont autorisées que depuis des machines du domaine français« .fr » et depuis un domaine de Tunisie (réseau d’adresse 193.95.32.).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 288 / 803

Page 176: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd7.11 TCP WRAPPERS : contrôle d’accès, /etc/hosts.allow, /etc/hosts.deny

Une seconde syntaxe existe pour TCPD.

Utiliser cette syntaxe !

Syntaxe :

« service : designation-machines : allow »« service : designation-machines : deny »

La désignation des machines peut se faire de diverses façons :noms de machines (« serveur.example.com »)réseaux de noms de machines (« .example.com »)adresses CIDR de réseaux (« 192.168.1.0/255.255.255.0 »)adresses de réseaux (« 192.168.1. »)nom spécial : « ALL »

Nom de service spécial : « ALL »

Tout autoriser : « ALL : ALL : allow »Tout interdire : « ALL : ALL : deny »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 289 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd7.11 TCP WRAPPERS : contrôle d’accès, /etc/hosts.allow, /etc/hosts.deny

ATTENTION :

quand on interdit une machine, il faut l’interdire via son nom FQDN et viason adresse IP (pour le cas où un nameserver serait injoignable on peutainsi bloquer quand même la machine).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 290 / 803

Page 177: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd7.11 TCP WRAPPERS : contrôle d’accès, /etc/hosts.allow, /etc/hosts.deny

ATTENTION :

Ce n’est par parce que l’on active tcpd que l’on arésolu tous les problèmes de sécurité et que l’on esttranquille !

Il ne faut pas oublier que plein d’autres services ne passent paspar l’intermédiaire de inetd.confIl faut surveiller les traces de fonctionnement renvoyées partcpd.Il faut renseigner les fichiers hosts.allow et /etc/hosts.deny.Il faut des démons sans trou de sécurité.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 291 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.12 TCP WRAPPERS : programmation via libwrap.aChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.12 • TCP WRAPPERS : programmation via libwrap.a

Les TCP WRAPPERS offrent aussi leur librairie de programmation :« libwrap.a » et « tcpd.h »

Généralement installée en « /usr/local/lib/libwrap.a » et« /usr/local/include/tcpd.h »

La librairie apporte la fonction C « host_access() »

On linkera avec cette librairie quand c’est nécessaire.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 292 / 803

Page 178: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.13 Gestionnaire de services réseau : XINETDChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.13 • Gestionnaire de services réseau : XINETD

(en anglais extended inetd)Cf « http://www.xinetd.org/ »

Numérotation des versions un peu compliquée. . .

XINETD est une réécriture complète de INETD en incorporant plusieursaspects manquants dans INETD :

contrôle d’accès à la TCP WRAPPERSaccès horaires aux démonstraces syslog des connexions (échouées, abouties)limitation du nombre d’instances de chaque démonbinding sur certaines adresses réseau

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 293 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.14 XINETD : fichier de configuration /etc/xinetd.confChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.14 • XINETD : fichier de configuration /etc/xinetd.conf

XINETD utilise le fichier « /etc/xinetd.conf », incompatible avec« /etc/inetd.conf ».Format du fichier :

defaults

{

attribut operateur valeur(s)

...

}

service toto

{

attribut operateur valeur(s)

...

}

Les opérateurs sont « = », « += » et « -= ».Cf la documentation pour la liste complète des attributs.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 294 / 803

Page 179: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.14 XINETD : fichier de configuration /etc/xinetd.conf

A noter avec certaines versions de « xinetd » la possibilité d’avoir unrépertoire « /etc/xinetd.d » dans lequel on trouve un fichier parservice, portant le nom du service et contenant le réglage du service.

Par exemple « /etc/xinetd.d/ftpd »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 295 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.15 XINETD : réglages par défautChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.15 • XINETD : réglages par défaut

Par exemple :

defaults

{

instances = 15

log_type = FILE /var/log/servicelog

log_on_success = HOST PID USERID DURATION EXIT

log_on_failure = HOST USERID RECORD

only_from =

disabled = shell login exec comsat telnet ftp tftp finger

disabled += time daytime chargen servers services xadmin

}

Ici la ligne « only_from = » interdit par défaut toutes les machines à seconnecter aux services. On autorisera ce qui est nécessaire au niveau dubloc de configuration de chaque service.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 296 / 803

Page 180: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.16 XINETD : configuration d’un serviceChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.16 • XINETD : configuration d’un service

Exemple pour le service « ftp » (cf « /etc/services ») :

service ftp

{

socket-type = stream

wait = no

user = root

server = /usr/sbin/in.ftpd

server_args = -l

instances = 4

access_times = 7:00-12:30 13:30-21:00

nice = 10

only_from = 192.168.1.0/24

}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 297 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.17 XINETD : /etc/xinetd.conf : directive niceChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.17 • XINETD : /etc/xinetd.conf : directive nice

Par exemple :

service ftp

{

socket-type = stream

wait = no

user = root

server = /usr/sbin/in.ftpd

server_args = -l

instances = 4

access_times = 7:00-12:30 13:30-21:00

nice = 10only_from = 192.168.1.0/24

}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 298 / 803

Page 181: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.18 XINETD : /etc/xinetd.conf : directive access_timesChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.18 • XINETD : /etc/xinetd.conf : directive access_times

Par exemple :

service ftp

{

socket-type = stream

wait = no

user = root

server = /usr/sbin/in.ftpd

server_args = -l

instances = 4

access_times = 7:00-12:30 13:30-21:00nice = 10

only_from = 192.168.1.0/24

}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 299 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.19 XINETD : /etc/xinetd.conf : directives bind, idChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.19 • XINETD : /etc/xinetd.conf : directives bind, id

Soit une machine avec 2 interfaces réseau d’adresses « 192.168.1.1 » et« 192.168.2.1 » :

service ftp

{

id = ftp-publicbind = 192.168.1.1socket-type = stream

wait = no

user = root

server = /usr/sbin/in.ftpd

server_args = -l

instances = 4

access_times = 7:00-21:00

nice = 10

only_from = 192.168.1.0/24

}

service ftp

{

id = ftp-privatebind = 192.168.2.1socket-type = stream

wait = no

user = root

server = /usr/sbin/in.ftpd

server_args = -l

instances = 4

access_times = 7:00-21:00

nice = 10

only_from = 192.168.2.0/24

}

La directive « id » servira au niveau de SYSLOG à différencier les tracesde l’un ou l’autre de FTPD.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 300 / 803

Page 182: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.20 XINETD : /etc/xinetd.conf : directive redirectChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.20 • XINETD : /etc/xinetd.conf : directive redirect

Par exemple :

service telnet

{

flags = REUSE

socket-type = stream

wait = no

user = root

server = /usr/sbin/in.telnetd

only_from = 192.168.1.0/24

redirect = 192.168.1.23}

Et un « telnet » vers « 192.168.1.1 » renverra vers le démon« telnetd » de « 192.168.1.23 ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 301 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.21 XINETD : /etc/xinetd.conf : tcpd et directive NAMEINARGSChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.21 • XINETD : /etc/xinetd.conf : tcpd et directive NAMEINARGS

Par exemple :

service ftp

{

flags = NAMEINARGS REUSE

socket-type = stream

wait = no

user = root

server = /usr/sbin/tcpdserver_args = /usr/sbin/in.ftpd -linstances = 4

access_times = 7:00-12:30 13:30-21:00

nice = 10

only_from = 192.168.1.0/24

}

TCP WRAPPERS et XINETD ne sont pas antinomiques.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 302 / 803

Page 183: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.22 XINETD : /etc/xinetd.conf : directive chrootChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.22 • XINETD : /etc/xinetd.conf : directive chroot

Par exemple :

service ftp

{

socket-type = stream

wait = no

user = root

server = /usr/sbin/chrootserver_args = /quelquepart/blockhaus/ftp /usr/sbin/in.ftpd -linstances = 4

access_times = 7:00-12:30 13:30-21:00

nice = 10

only_from = 192.168.1.0/24

}

On est ainsi compartimenté à l’arborescence de« /quelquepart/blockhaus/ftp » dont on ne peut pas sortir. Intérêtpour la sécurité de la machine.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 303 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.23 XINETD : reconfiguration, signauxChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.23 • XINETD : reconfiguration, signaux

Sont supportés les signaux :

signal « SIGHUP » : sur sa réception, « xinetd » se reconfiguresignal « SIGTERM » : sur sa réception, « xinetd » se sabordesignal « SIGUSR1 » : sur sa réception, « xinetd » écrit le fichier« /var/run/xinetd.dump »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 304 / 803

Page 184: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.24 Services internes inutilesChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.24 • Services internes inutiles

Rappel : INETD et XINETD lancent des services réseau sur demande

Exemple avec INETD : extrait de « /etc/inetd.conf » :

ftp stream tcp nowait root /usr/sbin/in.ftpd in.ftpd -l

donnera

execv("/usr/sbin/in.ftpd", "in.ftpd", "-l", 0);

Le service est fourni par un exécutable « externe ».

Mais le service peut être interne et être fourni directement par INETD ouXINETD.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 305 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.24 Services internes inutiles

Règle fondamentale : tous les services internes sont inutiles et doivent êtredésactivés.

Par exemple, pour INETD : désactiver tous les services de type internaldans « /etc/inetd.conf » :

#daytime stream tcp nowait root internal#daytime dgram udp wait root internal#time stream tcp nowait root internal#time dgram udp wait root internal#echo stream tcp nowait root internal#echo dgram udp wait root internal#discard stream tcp nowait root internal#discard dgram udp wait root internal#chargen stream tcp nowait root internal#chargen dgram udp wait root internal

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 306 / 803

Page 185: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.25 R-ServicesChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.25 • R-Services

Plusieurs services lancés par INETD et XINETD sont connus sous le nomde R-services (remote services) :

service RLOGIND : connexion interactive à un système distantservice RSHD : lancement d’une commande sur un système distantservice RCPD : recopie de fichiers locaux vers des fichiers distants ouvice-versa

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 307 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.26 R-service rlogind, R-commande rloginChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.26 • R-service rlogind, R-commande rlogin

(en anglais remote login daemon, remote login)

En général, le R-service a pour chemin : « /usr/sbin/in.rlogind » ou« /usr/sbin/rlogind ».

Syntaxe de la R-commande : rlogin [-l user] nom-de-machine

% rlogin -l besancon serveur.example.comPassword: XXXXXXXX

Last login: Mon Sep 15 09:42:58 from 195.220.212.130

Sun Microsystems Inc. SunOS 5.5 Generic November 1995

server%

A chaque fois que ce sera possible, préférer une connexion en SSH(ici avec « ssh »).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 308 / 803

Page 186: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.26 R-service rlogind, R-commande rlogin

� Contrôles d’accès (1)

Deux fichiers contrôlent les accès :fichier système « /etc/hosts.equiv »fichier personnel « $HOME/.rhosts »

Syntaxe commune aux deux fichiers :format 1 : « hostname »format 2 : « hostname username »

Deux cas de figure lors d’une connexion :une ligne à l’un des deux formats autorise la connexion et laconnexion se fait alors sans demande de mot de passeaucune ligne n’autorise la connexion et il y a alors demande du motde passe de l’utilisateur local

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 309 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.26 R-service rlogind, R-commande rlogin

Possibilité de mettre « + » à la place de n’importe quel champ :signification « n’importe quelle machine »signification « n’importe quel utilisateur »

Voir fonction C « ruserok() ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 310 / 803

Page 187: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.26 R-service rlogind, R-commande rlogin

� Contrôles d’accès (2) : Format « hostname »

Signification : les utilisateurs de la machine « hostname » sont autorisés àse connecter au système sous le même nom sans demande de mot depasse.

Ce format est utilisable dans « /etc/hosts.equiv » et dans les fichierspersonnels « $HOME/.rhosts ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 311 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.26 R-service rlogind, R-commande rlogin

• Par exemple, si le fichier « /etc/hosts.equiv » contient :

cerise.example.com

cela permet à un utilisateur « martin » de se connecter en RLOGINdepuis la machine « cerise.example.com » sous l’identité locale« martin » sans demande de mot de passe.

• Par exemple, si l’utilisateur « jean » a le fichier « $HOME/.rhosts »suivant :

cerise.example.com

cela permet à l’utilisateur « jean » de se connecter en RLOGIN depuis lamachine « cerise.example.com » sous l’identité locale « jean » sansdemande de mot de passe.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 312 / 803

Page 188: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.26 R-service rlogind, R-commande rlogin

� Contrôles d’accès (3) : Format « hostname username »

Signification : l’utilisateur « username » de la machine « hostname » estautorisé à se connecter au système sans demande de mot de passe.

Si ce format est utilisé dans « $HOME/.rhosts », alors cela autorise unutilisateur distant à se connecter sous le nom d’un utilisateur local.

Si ce format est utilisé dans « /etc/hosts.equiv » alors cela autorise unutilisateur distant à se connecter sous le nom de n’importe quel utilisateurlocal.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 313 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.26 R-service rlogind, R-commande rlogin

• Par exemple, si l’utilisateur « jean » a le fichier « $HOME/.rhosts »suivant :

cerise.example.com martin

cela permet à l’utilisateur « martin » de se connecter en RLOGIN depuisla machine « cerise.example.com » sous l’identité locale « jean » sansdemande de mot de passe.

• Par exemple, si le fichier « /etc/hosts.equiv » contient :

cerise.example.com jean

cela permet à l’utilisateur « jean » de se connecter en RLOGIN depuis lamachine « cerise.example.com » sous n’importe quelle identité localesans demande de mot de passe. DANGEREUX.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 314 / 803

Page 189: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.26 R-service rlogind, R-commande rlogin

� Problèmes :

Attention au contenu de « /etc/hosts.equiv ».SunOS 4.x.y fournissait un fichier contenant « + + ».Attention aux connexions root via le réseau.Il faut interdire les connexions root via le réseau parce qu’elles sontanonymes.⇒

Vérifier « /etc/ttys » (ou équivalent « /etc/securettys » . . .) etminimaliser le nombre de terminaux sécurisés.Vérifier « ~root/.rhosts ». C’est une cible privilégiée des pirates quiessayent d’y écrire « + + ».

Il n’y a pas de traces des connexions locales.Au mieux, tcpd informe d’où vient la connexion mais pas de l’identitéprise sur la machine locale.Remède : utiliser le package logiciel logdaemon URL« ftp://ftp.porcupine.org/pub/security/logdaemon-5.8.tar.gz »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 315 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.27 R-service rshd, R-commande rshChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.27 • R-service rshd, R-commande rsh

(en anglais remote shell daemon, remote shell)

En général, le R-service a pour chemin : « /usr/sbin/in.rshd » ou« /usr/sbin/rshd ».

Syntaxe de la R-commande : rsh -l username hostname command

% rsh -l besancon server.example.com dateSun Oct 12 15:20:28 MET DST 2003

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 316 / 803

Page 190: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.27 R-service rshd, R-commande rsh

Si l’on ne précise pas de commande, on lance un shell en interactif.

% rsh server.example.comSun Microsystems Inc. SunOS 5.10 Generic January 2005

You have new mail.

server%

A chaque fois que ce sera possible, préférer une connexion en SSH(ici avec « ssh »).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 317 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.27 R-service rshd, R-commande rsh

� Contrôles d’accès

Les contrôles d’accès se font comme page 309 (chapitre sur RLOGIND)sauf pour un point :

soit la connexion en RSH est explicitement autorisée par les fichiers« /etc/hosts.equiv » ou « $HOME/.rhosts » et la connexion sefait alors sans demande de mot de passesoit la connexion n’est pas explicitement autorisée et elle est alorsrefusée et on ne demande pas de mot de passe.

% rsh -l besancon server.example.com datepermission denied

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 318 / 803

Page 191: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.28 R-service rcpd, R-commande rcpChapitre 7 • Gestionnaires de services réseau : inetd, tcpd, xinetd§7.28 • R-service rcpd, R-commande rcp

(en anglais remote copy daemon, remote copy)

En général, le R-service a pour chemin : « /usr/sbin/in.rcpd » ou« /usr/sbin/rcpd ».

Plusieurs syntaxes de la R-commande :distant vers local : rcp [-r] user@machine:filename path

local vers distant : rcp [-r] path user@machine:filename

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 319 / 803

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.28 R-service rcpd, R-commande rcp

% rcp [email protected]:ananas.txt .% ls -l ananas-rw-r--r-- 1 besancon ars 15 Oct 12 15:18 ananas.txt

% rcp ananas.txt [email protected]:/tmp/cerise.txt% rsh -l besancon server.example.com ls -l /tmp/cerise.txt-rw-r--r-- 1 besancon ars 15 Oct 12 15:22 /tmp/cerise.txt

A chaque fois que ce sera possible, préférer une connexion en SSH(ici avec « scp »).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 320 / 803

Page 192: Administration UNIX - Cours Jussieu - 2009-2010

7 Gestionnaires de services réseau : inetd, tcpd, xinetd 7.28 R-service rcpd, R-commande rcp

� Contrôles d’accès

Les contrôles d’accès se font comme page 309 (chapitre sur RLOGIND)sauf pour un point :

soit la connexion en RCP est explicitement autorisée par les fichiers« /etc/hosts.equiv » ou « $HOME/.rhosts » et la connexion sefait alors sans demande de mot de passesoit la connexion n’est pas explicitement autorisée et elle est alorsrefusée et on ne demande pas de mot de passe.

% rcp ananas.txt [email protected]:/tmp/banane.txtpermission denied

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 321 / 803

Page 193: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 8

Protocoles de transferts de fichiers FTP,TFTP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 322 / 803

8 Protocoles de transferts de fichiers FTP, TFTP 8.1 Protocole FTP, ftp, ftpdChapitre 8 • Protocoles de transferts de fichiers FTP, TFTP§8.1 • Protocole FTP, ftp, ftpd

(en anglais File Transfer Protocol)

Une connexion via FTP nécessite que le service FTP soit activé au niveaude inetd.conf :

ftp stream tcp nowait root /usr/sbin/in.ftpd in.ftpd -l

Au niveau de « /etc/services », on voit 2 ports assignés au protocoleFTP :

ftp-data 20/tcp

ftp 21/tcp

Deux protocoles FTP en fait :FTP actif (mode par défaut sous Windows)FTP passif (mode par défaut sous Linux)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 323 / 803

Page 194: Administration UNIX - Cours Jussieu - 2009-2010

8 Protocoles de transferts de fichiers FTP, TFTP 8.1 Protocole FTP, ftp, ftpd

� FTP actif

FTP control connection

FTP data connection

CLIENTFTP

SERVEURFTP

High port 1 port 21

port 20High port 2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 324 / 803

8 Protocoles de transferts de fichiers FTP, TFTP 8.1 Protocole FTP, ftp, ftpd

Le protocole FTP est «complexe» car c’est un dialogue bidirectionnel :

Un client FTP se connecte sur leport 21 (« ftp » de« /etc/services ») du serveurFTP et ce port 21 sert à envoyerdes commandes au serveur FTP.

Si les commandes nécessitent quedes données soient reçues(commandes « dir », « get » parexemple) ou transmises (« put »par exemple) au serveur, le clientenvoie une commande « PORT »au serveur indiquant un port surlequel le serveur va créer uneconnexion depuis le port 20(« ftp-data » de« /etc/services »).

La connexion FTP-DATA est close

dès que toutes les données sonttransférées.

client serveur

connexion

port 21

PORT 33085

port 21

port 21

DIR

port 33085

port 20data

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 325 / 803

Page 195: Administration UNIX - Cours Jussieu - 2009-2010

8 Protocoles de transferts de fichiers FTP, TFTP 8.1 Protocole FTP, ftp, ftpdExemple :% ftp -v -d localhost

Connected to localhost.

220 cerise FTP server (SunOS 5.8) ready.

Name (localhost:besancon): besancon

---> USER besancon331 Password required for besancon.

Password:

---> PASS XXXXXXXXX230 User besancon logged in.

ftp> lcd /tmp

Local directory now /tmp

ftp> cd /etc

---> CWD /etc250 CWD command successful.

ftp> get motd

---> PORT 127,0,0,1,129,61200 PORT command successful.

---> RETR motd150 ASCII data connection for motd (127.0.0.1,33085) (54 bytes).

226 ASCII Transfer complete.

local: motd remote: motd

55 bytes received in 0.00086 seconds (62.53 Kbytes/s)

ftp> quit

---> QUIT221 Goodbye.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 326 / 803

8 Protocoles de transferts de fichiers FTP, TFTP 8.1 Protocole FTP, ftp, ftpd

� FTP passif

FTP control connection

FTP data connection

CLIENTFTP

SERVEURFTP

High port 1 port 21

High port 3High port 2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 327 / 803

Page 196: Administration UNIX - Cours Jussieu - 2009-2010

8 Protocoles de transferts de fichiers FTP, TFTP 8.1 Protocole FTP, ftp, ftpd

� Règles pour un client FTP protégé par un firewall

Method Source Source Destination Destination Connectionaddress port address port

Allow outgoing control connections to serverControlchannel

FTP clientor network

High FTP server 21 New

FTP server 21 FTP client ornetwork

High Established

Allow the client to establish data channels to remote serverActiveFTP

FTP server 20 FTP client ornetwork

High New

FTP clientor network

High FTP server 20 Established

PassiveFTP

FTP clientor network

High FTP server High New

FTP server High FTP client ornetwork

High Established

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 328 / 803

8 Protocoles de transferts de fichiers FTP, TFTP 8.1 Protocole FTP, ftp, ftpd

� Règles pour un serveur FTP protégé par un firewall

Method Source Source Destination Destination Connectionaddress port address port

Allow incoming control connections to serverControlchannel

FTP clientor network

High FTP server 21 New

FTP server 21 FTP client ornetwork

High Established

Allow the server to establish data channels to remote clientActiveFTP

FTP server 20 FTP client ornetwork

High New

FTP clientor network

High FTP server 20 Established

PassiveFTP

FTP clientor network

High FTP server High New

FTP server High FTP client ornetwork

High Established

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 329 / 803

Page 197: Administration UNIX - Cours Jussieu - 2009-2010

8 Protocoles de transferts de fichiers FTP, TFTP 8.1 Protocole FTP, ftp, ftpd

� Contrôle d’accès

Au niveau contrôle d’accès, les implémentations de base proposent :le fichier « /etc/ftpusers » contient les noms des utilisateurs nonautorisés à utiliser ftp. « root » doit être exclus comme d’habitude.le fichier « /etc/shells » contient les shells des utilisateursautorisés à utiliser ftp.

Moralité : pour interdire un utilisateur à utiliser FTP :indiquer le login de la personne au niveau de « /etc/ftpusers »faire en sorte que le shell de la personne ne soit pas dans« /etc/shells »

Pour configurer un FTP anonyme, se reporter aux deux FAQ :« ftp://ftp.lip6.fr/pub/doc/faqs/ftp-list/faq.gz »« ftp://ftp.lip6.fr/pub/doc/faqs/computer-security/anonymous-ftp-faq.gz »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 330 / 803

8 Protocoles de transferts de fichiers FTP, TFTP 8.1 Protocole FTP, ftp, ftpd

� Implémentations de serveurs FTP

Outre les versions fournies par les constructeurs, il y a plusieurs démons dudomaine public plus performants :

« http://www.wu-ftpd.org/ »« http://www.proftpd.org/ »« http://vsftpd.beasts.org/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 331 / 803

Page 198: Administration UNIX - Cours Jussieu - 2009-2010

8 Protocoles de transferts de fichiers FTP, TFTP 8.2 Protocole TFTP, tftp, tftpdChapitre 8 • Protocoles de transferts de fichiers FTP, TFTP§8.2 • Protocole TFTP, tftp, tftpd

TFTP : Trivial File Transfer Protocol

Une connexion via tftp nécessite que le service tftp soit activé au niveau deinetd.conf :

tftp dgram udp wait root /usr/etc/in.tftpd in.tftpd -s /tftpboot

TFTP, c’est en gros FTP sans pouvoir lister les directories distants et nenécessitant pas de mot de passe pour récupérer ou déposer des fichiers !En fait, celui qui utilise TFTP sait ce qu’il veut récupérer et n’a pas besoinde lister le directory. Par exemple, récupération d’un fichier deconfiguration pour :

terminal Ximprimante HP réseau

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 332 / 803

8 Protocoles de transferts de fichiers FTP, TFTP 8.2 Protocole TFTP, tftp, tftpd

On récupére les fichiers dans la sous arborescence /tftpboot.

Le danger : un démon tftpd mal configuré permet de récupérer tout fichierhors de « /tftpboot ». Le fichier « /etc/passwd » par exemple.

⇒ vérifier les options de lancement.Traditionnellement utiliser l’option « -s » au niveau de« /etc/inetd.conf » :

tftp dgram udp wait root /usr/etc/in.tftpd in.tftpd -s /tftpboot

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 333 / 803

Page 199: Administration UNIX - Cours Jussieu - 2009-2010

8 Protocoles de transferts de fichiers FTP, TFTP 8.2 Protocole TFTP, tftp, tftpd

A noter : il est parfois utile de faire le lien symbolique suivant :

# cd /tftpboot

# ln -s . tftpboot

car des requêtes portent parfois sur des noms du type« /tftpboot/fichier ».

% cd /tftpboot

% ls -l

drwxr-xr-x 2 root wheel 1536 Jan 4 15:02 cisco/

drwxr-sr-x 7 root wheel 512 Nov 10 1997 hds/

drwxr-sr-x 2 root wheel 512 Sep 5 1996 hp/

drwxr-sr-x 4 root wheel 512 Dec 5 1995 ncd/

drwxr-sr-x 2 root wheel 512 Mar 19 1997 plaintree/

drwxr-xr-x 2 root wheel 512 Aug 1 1997 sun/

lrwxrwxrwx 1 root wheel 1 May 8 1998 tftpboot -> .drwxr-sr-x 3 root wheel 512 Feb 9 1994 usr/

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 334 / 803

8 Protocoles de transferts de fichiers FTP, TFTP 8.2 Protocole TFTP, tftp, tftpd

Utilisation de TFTP sur CISCO pour télécharger des configurations ou desfirmware.

Idem sur d’autres matériels réseau : par exemple marque FOUNDRY

mise en place de la configuration du FOUNDRY via TFTP sur unserveur UNIX :copy tftp start 11.22.33.44 router/4802.cfg

reload

sauvegarde de la configuration du FOUNDRY sur UNIX via TFTP :touch /tftpboot/router/downloads/x.y

chown nobody:nobody /tftpboot/router/downloads/x.y

copy run tftp 11.22.33.44 router/downloads/x.y

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 335 / 803

Page 200: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 9

Remote Procedure Call (RPC)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 336 / 803

9 Remote Procedure Call (RPC) 9.1 IntroductionChapitre 9 • Remote Procedure Call (RPC)§9.1 • Introduction

Les Remote Procedure Calls (RPC) sont nés dans les années 1985 - 1990 :

diminution des coûts des matérielsaugmentation des puissances de calculaugmentation des capacités de stockage

Bref, passage à une informatique de systèmes répartis et de systèmesdistribués (utiliser le matériel le plus performant pour une tâche donnée,accroître la disponibilité des systèmes).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 337 / 803

Page 201: Administration UNIX - Cours Jussieu - 2009-2010

9 Remote Procedure Call (RPC) 9.1 Introduction

Principe d’un programme classique :

% prog.exe

int coucou() { return(33); } n = coucou();

exit(0); }

int main(int argc, char *argv[]) { int n;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 338 / 803

9 Remote Procedure Call (RPC) 9.1 Introduction

Principe d’un programme réparti utilisant une Remote Procedure Call(RPC) :

% prog.exe

int coucou() { return(33); } n = coucou();

exit(0); }

int main(int argc, char *argv[]) { int n;

RESEAU

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 339 / 803

Page 202: Administration UNIX - Cours Jussieu - 2009-2010

9 Remote Procedure Call (RPC) 9.2 Protocole External Data Representation (XDR)Chapitre 9 • Remote Procedure Call (RPC)§9.2 • Protocole External Data Representation (XDR)

Rappel sur les processeurs :

processeurs big endian

0x01 0x02 0x03 0x04

@ 0xNNNN

@ 0xNNNN + 1

@ 0xNNNN +2

@ 0xNNNN + 3

0x01020304 =

processeurs little endian

0x04

@ 0xNNNN

@ 0xNNNN + 1

@ 0xNNNN +2

@ 0xNNNN + 3

0x01020304 =

0x03 0x02 0x01

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 340 / 803

9 Remote Procedure Call (RPC) 9.2 Protocole External Data Representation (XDR)

Nécessité de choisir un encodage lors des échanges RPC !

⇒ Encodage big-endian retenuCf fonctions C « ntohs() » (network to host short), « ntohl() »(network to host long), « htons() » (host to network short),« htonl() » (host to network long).

⇒ Encodage des données plus générales (structures, tableaux, etc.) =XDR

Les RPC utilisent massivement XDR.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 341 / 803

Page 203: Administration UNIX - Cours Jussieu - 2009-2010

9 Remote Procedure Call (RPC) 9.3 Modèle Client / Serveur RPCChapitre 9 • Remote Procedure Call (RPC)§9.3 • Modèle Client / Serveur RPC

Les Remote Procedure Calls (RPC) utilisent un modèle client / serveur :Le client est le processus qui appelle une procédure distante.Le serveur est le processus qui réalise la Remote Procedure.

La communication se fait via TCP.

CLIENT

STUB client STUB serveur

PROCEDURE

RPC runtime RPC runtime

processus local processus distant

APIRPC

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 342 / 803

9 Remote Procedure Call (RPC) 9.4 Localisation des procédures RPC : portmapper, rpcbindChapitre 9 • Remote Procedure Call (RPC)§9.4 • Localisation des procédures RPC : portmapper, rpcbind

L’appel à la procédure distante nécessite de localiser la procédure distante(numéro de port TCP) sur la machine distante.

Le processus « portmapper » (autre nom possible : « rpcbind ») joue lerôle de serveurs de noms RPC. Il écoute sur le port TCP 111.

Principe :une procédure distante s’enregistre auprès du portmapperon demande au portmapper où se trouve la procédureon appelle ensuite la procédure

Le processus « portmapper » (autre nom possible : « rpcbind ») doitêtre démarré avant de lancer des processus enregistrant des RPC (voirscripts de démarrage).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 343 / 803

Page 204: Administration UNIX - Cours Jussieu - 2009-2010

9 Remote Procedure Call (RPC) 9.4 Localisation des procédures RPC : portmapper, rpcbind

processusportmapper

procedureananas()

version 2

processus 927

port 3248

ananas(), v2 = port 3248banane(), v2 = port 2147banane(), v3 = port 2148etc.

port 111Ou se trouve ananas() v2 ?

ananas() v2 == port 3248

1

2

3

4

5

processus 958

port 2147port 2148

procedurebanane()

version 2, version 3

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 344 / 803

9 Remote Procedure Call (RPC) 9.5 Liste des procédures RPC : rpcinfoChapitre 9 • Remote Procedure Call (RPC)§9.5 • Liste des procédures RPC : rpcinfo

(en anglais RPC information)Syntaxe : « rpcinfo [-p] [-s] hostname »Par exemple :

% rpcinfo -srpcinfo -s

program version(s) netid(s) service owner

100000 2,3,4 udp,tcp,ticlts,ticotsord,ticots rpcbind superuser

100021 4,3,2,1 tcp,udp nlockmgr 1

100024 1 ticots,ticotsord,ticlts,tcp,udp status superuser

100001 4,3,2 udp,ticlts rstatd superuser

100002 3,2 udp,ticlts,tcp,ticotsord,ticots rusersd superuser

100011 1 udp,ticlts rquotad superuser

100005 3,2,1 ticots,ticotsord,tcp,ticlts,udp mountd superuser

100003 4,3,2 tcp,udp nfs 1

100227 3,2 tcp,udp nfs_acl 1

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 345 / 803

Page 205: Administration UNIX - Cours Jussieu - 2009-2010

9 Remote Procedure Call (RPC) 9.5 Liste des procédures RPC : rpcinfo

% rpcinfo -pprogram vers proto port service

100000 4 tcp 111 rpcbind

100000 3 tcp 111 rpcbind

100000 2 tcp 111 rpcbind

100000 4 udp 111 rpcbind

100000 3 udp 111 rpcbind

100000 2 udp 111 rpcbind

100021 1 udp 4045 nlockmgr100021 2 udp 4045 nlockmgr100021 3 udp 4045 nlockmgr100021 4 udp 4045 nlockmgr100021 1 tcp 4045 nlockmgr100021 2 tcp 4045 nlockmgr100021 3 tcp 4045 nlockmgr100021 4 tcp 4045 nlockmgr

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 346 / 803

9 Remote Procedure Call (RPC) 9.6 Contrôle d’accèsChapitre 9 • Remote Procedure Call (RPC)§9.6 • Contrôle d’accès

Avec LINUX est apparu un contrôle d’accès au niveau de PORTMAP viasa compilation avec la librairie des TCPWRAPPERS.

Les contrôles d’accès se font donc comme page 287 via« /etc/hosts.allow ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 347 / 803

Page 206: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 10

Partage de fichiers NFS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 348 / 803

10 Partage de fichiers NFS 10.1 IntroductionChapitre 10 • Partage de fichiers NFS§10.1 • Introduction

NFS ≡ Network File System ≡ c’est l’accès de façon transparente pourl’utilisateur à des fichiers résidants sur des machines distantes.

Actuellement, NFS version 2 la plus répandue.

NFS version 3 existe et est disponible mais il existe des incompatibilitésd’implémentations entre constructeurs.

NFS version 4 est en étude. Cf « http://www.nfsv4.org » ou« http://www.citi.umich.edu/projects/nfsv4/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 349 / 803

Page 207: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.2 Principes de NFSChapitre 10 • Partage de fichiers NFS§10.2 • Principes de NFS

System calls

VNODE / VFS

NFS File system

RPC / XDR

Server routinesClient routines

Serveur

RPC / XDR

Client

System calls

VNODE / VFS

NFS File system

RPC / XDRRPC / XDR

Reseau

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 350 / 803

10 Partage de fichiers NFS 10.2 Principes de NFS

On a deux aspects dans NFS : client NFS et serveur NFS.

rpc.lockdrpc.statd

% prog# mount

CLIENT NFS SERVEUR NFS

rpc.lockdrpc.statdrpc.mountd nfsd

portmap (rpcbind)

RESEAU

portmap (rpcbind)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 351 / 803

Page 208: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.2 Principes de NFS

Le client NFS fait tourner les démons « biod » (ou « nfsiod »),« rpc.lockd » et « rpc.statd ».

rpc.lockdrpc.statd

% prog# mount

CLIENT NFS

RESEAU

portmap (rpcbind)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 352 / 803

10 Partage de fichiers NFS 10.2 Principes de NFS

Le serveur NFS fait tourner les démons « portmap » (ou « rpcbind »),« mountd » (ou « rpc.mountd »), « nfsd », « rpc.statd » et« rpc.lockd ».

SERVEUR NFS

rpc.lockdrpc.statdrpc.mountd nfsd

portmap (rpcbind)

RESEAU

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 353 / 803

Page 209: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.2 Principes de NFS

� Montage NFS : filehandle

rpc.mountd

RESEAU

# mount server:/home /mnt

1

0 3

2

SERVEUR NFS

CLIENT NFS

autorisationsd’exportation :/etc/exports

kernel

/home

/mnt+

filehandle(= fh0)

/4

calcul dufilehandle

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 354 / 803

10 Partage de fichiers NFS 10.2 Principes de NFS

� Ouverture d’un fichier NFS : utilisations des filehandles

2

kernel

4

RESEAU

% prog.exe

1 3

SERVEUR NFS

CLIENT NFS

open(/mnt/jardin/cerise.txt)

kernel

lookup(jardin, fh0)

lookup(cerise.txt, fh1)

fh1

fh2

5

Serveur NFS / port 2049

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 355 / 803

Page 210: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.2 Principes de NFS

� Lecture/Ecriture d’un fichier NFS : utilisations des filehandles

kernel

RESEAU

% prog.exe

1

SERVEUR NFS

CLIENT NFS

read() / write()

kernel

read(fh2, 0, 1024)

Serveur NFS / port 2049

read(fh2, ... , 1024)

2 ...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 356 / 803

10 Partage de fichiers NFS 10.2 Principes de NFS

� Verrouillage NFS (1) : fonctionnement normal

rpc.lockd

rpc.lockd rpc.statd

RESEAU

rpc.statd

% prog.exe

fcntl() lockf()

1

2

3 33

SERVEUR NFS

CLIENT NFS

/etc/sm

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 357 / 803

Page 211: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.2 Principes de NFS

� Verrouillage NFS (2) : reboot du client NFS

rpc.lockd

rpc.lockd rpc.statd

RESEAU

rpc.statd

1

3 22

SERVEUR NFS

CLIENT NFS

/etc/sm

reboot du client NFS termine

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 358 / 803

10 Partage de fichiers NFS 10.2 Principes de NFS

� Verrouillage NFS (3) : reboot du serveur NFS

rpc.lockd

rpc.lockd rpc.statd

RESEAU

rpc.statd

% prog.exe

reboot du serveur NFS termine

24 ?

3

1

SERVEUR NFS

CLIENT NFS

/etc/sm

perte des verrous NFS

nouvelle demande des verrous NFS ?

4 ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 359 / 803

Page 212: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.2 Principes de NFS

� Suppression de fichier NFS ouvert

exemple.txt

readwrite

.nfsXXXXXXXXXX

rm

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 360 / 803

10 Partage de fichiers NFS 10.3 Lancement de NFSChapitre 10 • Partage de fichiers NFS§10.3 • Lancement de NFS

DIGITAL UNIXOn règle l’aspect NFS par la commande « nfssetup » qui modifiealors le fichier « /etc/rc.config » :...

NFS_CONFIGURED="1"

export NFS_CONFIGURED

NFSSERVING="1"

export NFSSERVING

NONROOTMOUNTS="1"

export NONROOTMOUNTS

NUM_TCPD="8"

export NUM_TCPD

NUM_UDPD="8"

export NUM_UDPD

NUM_NFSIOD="7"

export NUM_NFSIOD

NFSLOCKING="1"

export NFSLOCKING

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 361 / 803

Page 213: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.3 Lancement de NFS

LinuxAu niveau de « /etc/sysconfig/network », on indique via lavariable « NETWORKING » si l’on veut les services réseau (dont NFS).Le script de démarrage « /etc/rc.d/rc3.d/S15nfsfs » suivant lavaleur de NETWORKING lance ou pas un client NFS.Le script de démarrage « /etc/rc.d/rc3.d/S60nfs » suivant lavaleur de NETWORKING et suivant l’existence de« /etc/exports » lance ou pas un serveur NFS.

SolarisLa lecture de « /etc/init.d/nfs.client » renseigne sur la façonde démarrer un client NFS.La lecture de « /etc/init.d/nfs.server » apprend que lamachine démarre un serveur NFS s’il existe le fichier d’exportation« /etc/dfs/dfstab ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 362 / 803

10 Partage de fichiers NFS 10.4 Exportation NFS, /etc/exports, /etc/dfs/dfstabChapitre 10 • Partage de fichiers NFS§10.4 • Exportation NFS, /etc/exports, /etc/dfs/dfstab

Le partage de disques repose sur l’exportation par une machined’arborescences.L’exportation peut être en read-only ou en read-write.L’exportation se fait au niveau du fichier /etc/exports en général.Suivant l’UNIX, la syntaxe n’est pas la même :

DIGITAL UNIX : fichier « /etc/exports » :/var/spool/mail -access=client-nfs.example.com

Linux : fichier « /etc/exports » :/home client-nfs.example.com(rw)

/zip client-nfs.example.com(rw)

Solaris : fichier « /etc/dfs/dfstab » :# pathname resource fstype specific_options description

/export/home - nfs rw=.example.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 363 / 803

Page 214: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.4 Exportation NFS, /etc/exports, /etc/dfs/dfstab

Comment faire prendre connaissance de modifications dans le fichier« /etc/exports » (ou équivalent) ?

Méthode 1 : on ne fait rien ; le fichier « /etc/exports » est consultélors de toute demande de montage de disque.Par exemple DIGITAL UNIX.Méthode 2 : on envoie un signal au programme « mountd » gérant lesmontages :

# kill -HUP ‘cat /var/run/mountd.pid‘

Par exemple Linux, FreeBSD.Méthode 3 : une commande spécialisée existe : share, shareall(unshare, unshareall) sur Solaris# unshareall

# showmount -e

no exported file systems for serveur-nfs.example.com

# shareall

# showmount -e

export list for serveur-nfs.example.com:

/infosystems client-nfs.example.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 364 / 803

10 Partage de fichiers NFS 10.5 Exportation root NFSChapitre 10 • Partage de fichiers NFS§10.5 • Exportation root NFS

Le problème principal est celui de l’équivalence root par NFS : quels droitspossède le root d’une machine cliente NFS sur les fichiers exportés par unserveur NFS ?

Un fichier de droits « rw------- » sur le serveur NFS (où le root peut lelire) peut-il être lu par root sur un client NFS ?

La réponse est fonction du contexte mais cela se paramètre au niveau de« /etc/exports ». Une requête émanant de root sera sauf précisioncontraire convertie au nom de l’utilisateur « nobody » :

% grep nobody /etc/passwdnobody:*:65534:65534:Unprivileged user:/nonexistent:/sbin/nologin

(attention : parfois c’est l’utilisateur « nfsnobody » mais le principe restele même)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 365 / 803

Page 215: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.5 Exportation root NFS

Exemple de la conversion de l’UID lors de la requête (la partition montéeest exportée sans droit root NFS) :

# mount -t nfs serveur-nfs.example.com:/adm/backup/arch /mnt# iduid=0(root) gid=0(wheel) groups=0(wheel),1(daemon),2(kmem)

# cd /mnt# df .Filesystem 1024-blocks Used Available Capacity Mounted on

serveur-nfs.example.com:/adm/backup/arch

1572045 1377401 37440 97% /mnt

# touch test.txt# ls -ltotal 0

-rw------- 1 root daemon 75 Feb 3 15:01 motd

-rw-r--r-- 1 nobody nogroup 0 Feb 3 14:59 test.txt

# cat motdcat: motd: Permission denied

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 366 / 803

10 Partage de fichiers NFS 10.5 Exportation root NFS

� Exportation avec root NFS

Mêmes fichiers que précédemment :exemple sur DIGITAL UNIX :/var/spool/mail -root=client.example.com,access=client.example.com

exemple sur Linux :/var/spool/mail client.example.com(rw,no_root_squash)

exemple sur Solaris :/export/home - nfs rw=.example.com,root=client.example.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 367 / 803

Page 216: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.5 Exportation root NFS

� Exportation sans root NFS

Mêmes fichiers que précédemment :

exemple sur DIGITAL UNIX :/var/spool/mail -access=client.example.com

exemple sur Linux :/var/spool/mail client.example.com(rw,root_squash)

exemple sur Solaris :...

/opt - nfs rw=client.example.com

/usr/local - nfs rw=.example.com

/var/mail - nfs rw=.example.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 368 / 803

10 Partage de fichiers NFS 10.6 Règle de non transitivité NFSChapitre 10 • Partage de fichiers NFS§10.6 • Règle de non transitivité NFS

Il n’y a pas de transitivité NFS.

Si A exporte « /partition » à BSi B monte « /partition » en « /partition2 » et exporte« /partition2 » à Calors C n’a pas accès au contenu du « /partition » initial !

Sinon il n’y aurait aucune sécurité, aucun contrôle possible d’exportation.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 369 / 803

Page 217: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.7 Montage NFS manuelChapitre 10 • Partage de fichiers NFS§10.7 • Montage NFS manuel

Syntaxe usuelle :mount -t nfs serveur:/arborescence /point/montage

# mount -t nfs serveur-nfs.example.com:/export/home /mnt# df /mntFilesystem 1k-blocks Used Available Use% Mounted on

serveur-nfs.example.com:/export/home

1015695 566015 388739 59% /mnt

# umount /mnt

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 370 / 803

10 Partage de fichiers NFS 10.8 Montage NFS automatiqueChapitre 10 • Partage de fichiers NFS§10.8 • Montage NFS automatique

Les montages automatiques se règlent au niveau de /etc/fstab (ouéquivalent) :

...

serveur-nfs.example.com:/export/home /mnt nfs hard,intr 0 0

...

La syntaxe est celle montrée ci dessus sur tous les systèmes UNIX utilisantun fichier « /etc/fstab ».

Une fois le fichier « /etc/fstab » configuré, on peut faire les chosessuivantes :

1 Monter une partition distante bien précise :# mount /users

2 Monter toutes les partitions distantes :# mount -t nfs -v -a

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 371 / 803

Page 218: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.9 Option de montage NFS softChapitre 10 • Partage de fichiers NFS§10.9 • Option de montage NFS soft

Option de montage « soft » : si pour une raison ou pour une autre, lesopérations RPC implantant la requête NFS viennent à échouer, cetterequête NFS échoue elle aussi.

On peut apparenter cette situation à celle d’un disque local tombant enpanne.

Une manifestation de ce problème est qu’il peut apparaître des blocsremplis de caractères NULL dans des fichiers nouvellement écrits à traversNFS sur une partition qui aura montré des problèmes.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 372 / 803

10 Partage de fichiers NFS 10.10 Option de montage NFS hardChapitre 10 • Partage de fichiers NFS§10.10 • Option de montage NFS hard

Option de montage « hard » : si pour une raison ou pour une autre, lesopérations RPC implantant la requête NFS viennent à échouer, cetterequête NFS est soumise à nouveau et cela jusqu’à ce qu’elle aboutisse.

On peut apparenter cette situation à celle d’un disque local très lent.

Pour éviter que dans le cas hard, la requête NFS ne soit transmise advitam eternam, on peut faire le montage en mode hard,intr ce quiautorise son interruption au clavier ou via des envois de signaux.

En pratique, on utilisera toujours les montages hard,intr pour lesmontages des partitions auxquelles on accède en lecture/écriture.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 373 / 803

Page 219: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.11 Vérification des exportations : showmountChapitre 10 • Partage de fichiers NFS§10.11 • Vérification des exportations : showmount

En cas de problème dans le montage NFS d’une partition on peut vérifierd’abord si l’exportation indispensable est déjà assurée.

La commande à utiliser est « showmount -e » :

% showmount -e serveur-nfs.example.comExport list for serveur-nfs.example.com:

/export/home .example.com

/opt client-nfs.example.com

/usr/local .example.com

/var/mail .example.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 374 / 803

10 Partage de fichiers NFS 10.12 Vérification des exportations : rpcinfoChapitre 10 • Partage de fichiers NFS§10.12 • Vérification des exportations : rpcinfo

On peut aussi vérifier à distance si le serveur NFS fait tourner le démonmountd via la commande « rpcinfo ».

% rpcinfo -p serveur-nfs.example.com | grep mount100005 1 udp 32843 mountd

100005 2 udp 32843 mountd

100005 3 udp 32843 mountd

100005 1 tcp 32798 mountd

100005 2 tcp 32798 mountd

100005 3 tcp 32798 mountd

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 375 / 803

Page 220: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.13 Messages d’erreur NFSChapitre 10 • Partage de fichiers NFS§10.13 • Messages d’erreur NFS

Un message d’erreur classique prend la forme :

NFS write error: on host serveur-nfs.example.com remote file

system full

Parfois c’est hermétique comme message :

NFS write error 60 on host nfs-client.example.com fh 716 1 a0000

cdbe 66b10eac a0000 1d00 5fdbece5

Pour le décoder, se reporter à « <sys/errno.h> ».Ici on déduit :

#define ETIMEDOUT 60 /* Connection timed out */

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 376 / 803

10 Partage de fichiers NFS 10.14 AutomounterChapitre 10 • Partage de fichiers NFS§10.14 • Automounter

Les montages rencontrés jusqu’à présent sont permanents.

Un automounter rend les montages temporaires : un montage ne dureguère que le temps nécessaire ; quand il est nécessaire, on monte lapartition distante que l’on démonte quand on n’en a plus besoin.

Il existe 3 automounters :

« automount » fourni par les constructeurs (et d’origine SUN)« amd » ; version logiciel libre dont le développement stagneftp://ftp.cs.columbia.edu/pub/amd

« am-utils », bâti sur la base de « amd »« http://www.cs.columbia.edu/~ezk/am-utils/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 377 / 803

Page 221: Administration UNIX - Cours Jussieu - 2009-2010

10 Partage de fichiers NFS 10.15 Machines disklessChapitre 10 • Partage de fichiers NFS§10.15 • Machines diskless

Une machine diskless est une machine UNIX sans disque dur local.

Principe :1 La machine UNIX est mise sous tension.2 La machine UNIX envoie sur le réseau son adresse ethernet (MAC

address). Par exemple via PXE sur des cartes réseau récentes.3 La machine récupére son adresse IP et on lui indique où télécharger un

noyau et comment. Par exemple renseignements renvoyés par DHCP.4 La machine télécharge le noyau. Par exemple par TFTP.5 Le noyau monte par NFS la partition de « / ».6 Le programme « init » prend la main et réalise les opérations de

montage des partitions indiquées dans « /etc/fstab ». Ici lespartitions seront donc montées par NFS.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 378 / 803

10 Partage de fichiers NFS 10.16 Annexe 1Chapitre 10 • Partage de fichiers NFS§10.16 • Annexe 1

Ci joint dans la version imprimée de ce cours, un document sur le procédéKICKSTART.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 379 / 803

Page 222: Administration UNIX - Cours Jussieu - 2009-2010

65

Red Hat Magazine 2004 N° 3

KickstartUtilisez Fedora Kickstart en réseau pour effectuer une nouvelle installation en peu de temps.

inux est de plus en plus utilisé, non seulement au sein de très grands réseaux, mais également dans certaines situations où il est nécessaire d’installer de nombreux ordinateurs ou bien de procéder à une nouvelle installation en un laps de temps réduit. Par exemple, dans le cas de clusters d’ordinateurs ou d’une réinstallation manuelle de stations de travail dans les réseaux d’entreprises, suite au dysfonctionnement d’un disque dur... Opérations qui demandent beaucoup trop de temps et d’énergie au personnel. Kickstart, disponible dans l’Installer de Fedora, est la solution idéale à ces problèmes, puisqu’il permet d’effectuer automatiquement une installation complète, y compris l’exécution de scripts adaptés pour une configuration ou des besoins spécifiques. Pourquoi Kickstart ? Par rapport aux autres méthodes d’installation, Kickstart offre de nombreux avantages. Il est possible de configurer de façon centralisée des installations types pour des groupes d’ordinateurs, étant donné que les divers composants hardware reconnus par le programme d’installation de Red Hat peuvent être ignorés dans le fichier de configuration. La méthode Kickstart ne requiert, comme modèle d’installation, qu’un seul fichier de description qui utilise une syntaxe spécifique pour indiquer à l’Installer les opérations qu’il doit exécuter. Ce fichier de description introduit le second grand avantage de la méthode Kickstart : aucune image d’installation propre à chaque PC n’est nécessaire, comme dans le cas de presque tous les autres programmes d’installation ou de rétablissement d’installation.

Kickstart, en effet, n’utilise que les supports d’installation de Fedora. En outre, le fichier de description est substantiellement indépendant de la version. Il est, par conséquent, possible d’utiliser le même fichier, avec cependant quelques limites, comme par exemple, le choix des paquetages, pour les installations courantes et futures de Fedora. En pratique, Kickstart installe à chaque fois un système avec les mêmes caractéristiques mais utilise comme base la distribution correspondante et le programme d’installation relatif.

Toutefois, en cas d’installations exécutées normalement de façon automatique, dans le but de réinstaller sur le disque dur d’un serveur ou d’un poste de travail des données très importantes, utilisez Kickstart avec prudence parce qu’une simple erreur dans le fichier de configuration pourrait provoquer la perte de ces données. De ce fait, soyez très vigilant lors de la création du fichier de configuration Kickstart. Types d’installations Pour le stockage des fichiers de description d’installation, Kickstart offre deux méthodes différentes. • La méthode basée sur des disques nécessite un disque de

lancement approprié pour chaque ordinateur installé. Cette méthode prévoit l’utilisation, soit du disque de lancement d’installation (créé sur la base des fichiers des images boot.img) de la distribution Linux utilisée, soit du fichier de description.

• la méthode basée sur le réseau prévoit le chargement du fichier Kickstart à partir d’un serveur approprié. Comme support de lancement, il est possible d’utiliser un disque ou, par exemple, un PXE ou encore un environnement créé pour le lancement à partir de cartes réseau déterminées.

La première méthode est conseillée pour de petites installations, tandis que pour des installations de plus grande ampleur, il est souhaitable d’utiliser la seconde méthode : celle basée sur réseau. Dans ce cas, il n’est pas nécessaire de consacrer trop de temps à la personnalisation du serveur pour Kickstart. Pour démarrer une installation automatique, il faut de toute façon copier les supports d’installation de Red Hat sur le serveur, et ce, indépendamment du type d’installation désirée : basée sur disque ou sur réseau. Dans cet article, l’installation basée sur CD-ROMs ne sera pas abordée, puisqu’elle ne permet pas l’installation automatique sans une intervention minimale de l’utilisateur.

L

Fedora Kickstart

Page 223: Administration UNIX - Cours Jussieu - 2009-2010

66

Fedora Kickstart Red Hat Magazine 2004 N° 3

Copie des supports d’installation sur le serveur Pour copier les supports d’installation sur le serveur, il est avant tout nécessaire que la partition correspondante dispose d’espace suffisant : environ 2 Go. Il faut ensuite créer un nouveau répertoire dans lequel sauvegarder les supports d’installation. Dans l’ exemple suivant est utilisé le répertoire : /kickstart/FC1A. Insérez le premier CD de Fedora dans le lecteur CD-ROM approprié, et tapez ensuite : #mount /mnt/cdrom#cp –af /mnt/cdrom/RedHat /kickstart/FC1A#cp /mnt/cdrom/RELEASE-NOTES* /kickstart/FC1A (n’exécutez cette dernière commande que pour le premier CD-ROM)

#umount /mnt/CD-ROM Répétez l’opération pour les 2ème et 3ème CDs d’installation. De cette façon, les paquetages d’installation et tous les programmes binaires de Fedora sont copiés dans le répertoire kickstart/FC1A.

Partages du serveur

Exportez la base d’installation afin de permettre aux clients de la repérer sur le serveur. Pour exécuter l’exportation, de nombreuses méthodes sont disponibles, toutefois les partages NFS ou HTTP sont les plus communément utilisés. Dans l’exemple suivant, le partage NFS sera utilisé car, dans le cas d’une installation basée sur réseau, Kickstart requiert le fichier de configuration correspondant sur partage NFS. En principe, il est également possible d’exécuter des installations par le biais d’autres supports de base. Par exemple, un ordinateur qui fournit des données partagées sur le Web pourrait être utilisé comme support de base pour d’importantes installations. Pour créer le partage NFS, il faut vérifier que les paquetages RPM nécessaires sont disponibles sur le serveur. Pour cela, tapez la commande rpm ci-dessous : #rpm –q portmap nfs-utils La commande doit renvoyer les noms des deux programmes. Contrôlez que le répertoire complet /kickstart est bien exporté (voir le Listing 1).

/kickstart *(ro,all_squash)

Listing 1 : /etc/exports

Par la suite, il sera possible de sauvegarder les fichiers de configuration de Kickstart dans ce répertoire. Activez le service NFS en tapant : #/etc/init.d/nfs start Si un message d’erreur comme celui-ci apparaît :

Starting NFS quotas: Cannot register service: RPC: Unable to receive... il faudra aussi lancer le mapper des ports via la commande : #/etc/init.d/portmap start Configuration DHCP Pour effectuer une installation à partir d’un serveur disposant des fichiers de configuration, il faut qu’un serveur DHCP soit disponible sur le réseau de l’ordinateur à installer.

Dans l’Encadré 2 est représenté un fichier de configuration un peu plus complexe pour le daemon DHCP, qui se base sur 2 sous-réseaux reliés de façon logique au calculateur. Tous les sous-réseaux dont est responsable le daemon DHCP d’un ordinateur doivent toujours être directement reliés, par exemple au moyen d’une carte réseau, avec l’ordinateur correspondant. Assurez-vous, en outre, qu’un seul serveur DHCP est utilisé par sous-réseau, car l’utilisation de plusieurs serveurs pourraient distribuer les données de configuration de façon arbitraire. Pour installer et activer le daemon DHCP, éventuellement non installé, tapez les commandes suivantes : #up2date dhcp#vim /etc/dhcpd.conf (élaboration du fichier de configuration)#/etc/init.d/dhcp start Si le serveur DHCP est actif, l’installation Kickstart recevra l’adresse IP du serveur DHCP et choisira ensuite le fichier de configuration Kickstart en service. L’option next-server spécifie le serveur NFS qui contient le fichier, tandis que l’option filename assigne au programme d’installation le nom du partage NFS. Kickstart cherchera ensuite dans ce répertoire le fichier de configuration selon le schéma suivant : < Adresse IP >-kickstart Naturellement, il est également possible de créer dans ce répertoire des liens symboliques ainsi que des groupes. Il est, par exemple, possible de créer un fichier Kickstart pour un groupe de stations de travail et l’utiliser seulement pour les adresses IP intéressées.

L’ exemple suivant illustre la création de ce type de fichier Kickstart.

Un répertoire du disque (ext2)

Un partage NFS

Un partage http (Webserver)

Un partage FTP

Les CD-ROMs d’installation de Red Hat (qui n’ autorisent pas l’installation automatique).

Tableau 1 : Supports de base d’installation.

Page 224: Administration UNIX - Cours Jussieu - 2009-2010

Fedora Kickstart

67

Red Hat Magazine 2004 N° 3

Création d’un fichier de configuration avec redhat-config-kickstart La version courante de Fedora comprend l’outil redhat-config-kickstart. Si cet outil n’est pas encore installé sur le système, utilisez up2date pour exécuter une telle opération. Pour le lancer, tapez redhat-config-kickstart. Apparaîtra alors une fenêtre de lancement (Figure 1) qui offre les mêmes options qu’une installation Fedora. L’ outil permet, soit de modifier un fichier de configuration existant, à condition qu’ il ait été créé avec Red Hat Tool, soit d’en créer un nouveau. Explorez les éléments du menu, visibles à gauche.

Encore une fois, faites très attention si des données importantes ont été installées sur l’ordinateur.

L’élément du menu Configuration de base comprend des options très importantes comme, par exemple, celle relative à la Composition vocale ou à l’ établissement du mot de passe principal.

L’option Méthode d’installation permet de choisir diverses bases d’installation et, en outre, d’effectuer une nouvelle installation ou bien mettre à jour une installation déjà existante de Fedora.

Les options du bootloader comprennent les bases pour la configuration de Grub/Lilo. Toutefois à cet endroit, il n’ est pas possible d’exécuter une configuration détaillée comme, par exemple, celle d’un système dual-boot. La section Information sur la partition permet de spécifier le partitionnement.

A cet effet, deux options spécifiques de Kickstart sont disponibles : ondisk qui permet de créer une partition déterminée sur un disque dur spécifique et onpart qui permet, par contre, d’utiliser une partition déjà existante.

Figure 1 : Configuration de base.

# Définitions globales:option domain-name “reseau-essai.redhat.de“;default-lease-time 3600;max-lease-time 7200;ddns-update-style none; # Definition du premier sous-réseau (tous les # paramètres spécifiés dans le sous-réseau, # ne sont valables que pour tel réseau).

subnet 192.168.7.0 netmask 255.255.255.0 { option routers 192.168.7.1; # Passerelle prédéfinie option domain-name-servers 192.168.7.1; # Server DNS option subnet-mask 255.255.255.0; # Données du masque de sous-réseau

next-server 192.168.7.1; # Adresse du serveur NFS avec le fichier # de configuration Kickstart filename “/kickstart/“; # Répertoire qui contient le fichier # Kickstart (Schéma: $[Adresse IP client]). range 192.168.7.200 192.168.7.230; # Adresse assignée par le serveur # (dans ce cas de 192.168.7.200 à 192.168.7.230) # Pour une installation et une # diversification efficaces, les clients à # installer doivent toujours # avoir la même adresse IP, ceci parce # que le fichier Kickstart est sélectionné # en fonction de l’adresse IP.

group { use-host-decl-names on; host workstation1 { # Nom de l’ordinateur hardware ethernet 00:cb:0b:18:10:45; # Adresse MAC de la carte réseau fixed-address 192.168.7.101; # Adresse IP à assigner à l’ordinateur } #? Ici il est possible de spécifier #? d’autres ordinateurs. } # Fin de l’adresseIP de l’ordinateur spécifié

} # Fin du sous-réseau 192.168.7.0 # Il est possible de spécifier d’autres # sous-réseauX en suivant le même schémasubnet 192.168.200.0 netmask 255.255.255.0 { #? Définitions? }

Encadré 2 : /etc/dhcpd.conf

Page 225: Administration UNIX - Cours Jussieu - 2009-2010

68

Fedora Kickstart Red Hat Magazine 2004 N° 3

Puisque Kickstart utilise le programme d’installation de Red Hat et, par conséquent, son système de détection hardware, il n’est pas nécessaire de spécifier les paramètres hardware dans les éléments de menus cités ci-après. Pendant l’installation, les drivers appropriés seront configurés automatiquement. En général, les données d’authentification ne doivent être modifiées que lorsqu’on utilise un système d’authentification de réseau de type NIS ou LDAP. Si, par contre, le système appartient à un réseau local protégé, il est possible de désactiver l’option Configuration Firewall.

En ce qui concerne la Configuration de X, avant d’activer le lancement automatique du système X Window, vérifiez si vous avez sélectionné la configuration appropriée. Bien qu’aujourd’hui il soit possible de résoudre presque tous les problèmes hardware, l’auteur comme le distributeur devraient faire très attention avant de satisfaire des demandes hardware particulières. La configuration XFree, après que l’installation ait été effectuée avec l’outil redhat-config-xfree86, représente le meilleur compromis. L’outil graphique permet de sélectionner les paquetages mais seulement des groupes de paquetages, comme illustré à la Figure 2. Si l’on désire spécifier un réglage particulier, par exemple sélectionner un unique paquetage, il faudra modifier manuellement le fichier de configuration. Cet argument est traité plus en détail dans un autre paragraphe du présent article.

Figure 2 : Sélection des paquetages.

La même configuration sera utilisée pour les scripts %pre et %post. Les scripts permettent d’apporter des modifications définies par l’utilisateur. Il est possible, par exemple, de contrôler les données en réseau, comme envoyer un message avec le texte : « Administrateur, l’ordinateur a été installé » et plus encore, sans poser de limites à la créativité.Après avoir réglé toutes les options désirées, enregistrez

la configuration de Kickstart en cliquant sur Fichier-> Enregistrer fichier. Le fichier, obtenu pour le réseau utilisé ici comme exemple est semblable à celui illustré dans l’Encadré 3. Un fichier de ce type sera présenté plus en détail dans le paragraphe suivant. # Généré par le configurateur Kickstart

lang en_US # Langue du système

langsupport de_DE --default=en_US

# Langues à installer

keyboard de-latin1-nodeadkeys

# Type de clavier

mouse generic3ps/2 # Type de souris

timezone Europe/Berlin # Fuseau horaire

rootpw --iscrypted $1$To1ZVQMJ$SjOFyd7tZ2y.fR.G2oMt// # Password principal

reboot # Redémarrage après l’installation

text # Installation en mode texte

install # Exécute une réinstallation et non # pas une mise à jour

nfs --server=192.168.7.1 --dir=/kickstart/FC1A # Support d’installation

bootloader --location=mbr # Endroit où installer le chargeur de démarrage

zerombr yes # Efface le MBR principal

clearpart --all --initlabel # Elimine toutes # les partitions existantes et la table des # partitions

# Informations sur le partionnement

part /boot --fstype ext3 --size 80 --asprimary

part / --fstype ext3 --size 1 --grow

part swap --size 512

# Options d’authentification

auth --useshadow --enablemd5

# Configuration de l’interface réseau

network --bootproto=static --ip=192.168.7.101 --netmask=255.255.255.0 --gateway=192.168.7.254

--nameserver=192.168.7.1 --device=eth0

Page 226: Administration UNIX - Cours Jussieu - 2009-2010

Fedora Kickstart

69

Red Hat Magazine 2004 N° 3

device ethernet 3c509 -opts “io=0x320, irq=7“ # Carte Ethernet

bootloader -useLilo -linear --location=mbr zerombr yes # Efface le MBR

clearpart --all --initlabel part /boot --fstype ext3 --size 80 --asprimary part / --fstype ext3 --size 1 --grow \ --onpart hda2 --maxsize 2000

part /var/www --fstype ext2 --size 20000

part swap --size 512

auth --useshadow --enablemd5

network --bootproto=dhcp

firewall --disabled

skipx # Ignore la configuration de X

# Sélection des paquets (résoud # automatiquement les dépendances)

%packages --resolvedeps

@ Office/Productivity

@ Administration Tools

@ Printing Support

lynx

httpd

%post # Les scripts CHROOT sont exécutés

# dans l’installation prête)

# Introduction du nom du serveur:

cat > /etc/resolv.conf <<EON search domain1.de domain2.de unterdomain.domain2.de nameserver 192.168.7.2 nameserver 192.168.7.3 EON

# Activation de l’accès aux disques durs DMA

cat > /etc/sysconfig/harddisks <<EOF USE_DMA=1 MULTIPLE_IO=16 EIDE_32BIT=3 LOOKAHEAD=1 EXTRA_PARAMS=-X68 EOF

chkconfig lpd off chkconfig httpd on

mail -s “Fin Install Ordinateur“ \root@mailserver < /dev/null

Encadré 4 : ks-avancé.cfg

firewall --disabled # Désactive les règles du # firewall

# Configuration de Xfree86

xconfig --depth=32 --resolution=1280x1024 --defaultdesktop=KDE

# Selection des paquets (résoud automa- # tiquement les dépendances)

%packages --resolvedeps

@ X Window System

@ KDE Desktop Environment

@ Graphical Internet

@ Office/Productivity

@ Administration Tools

@ Printing Support

Encadré 3 : ks.cfg Création manuelle d’un fichier de configuration Pourquoi créer manuellement un fichier de configuration, opération plutôt compliquée, alors que tout ou presque est disponible dans l’outil Fedora ? Les réponses à cette question sont multiples. Soit parce que le programme d’installation ne reconnaît pas un composant hardware, telle une carte réseau, soit parce que l’utilisateur désire personnaliser le système avec des scripts. Même la sélection d’un simple paquetage de la distribution pour une installation doit être effectuée manuellement. Il est conseillé de se baser sur un fichier créé avec l’outil GUI, de façon à éviter des erreurs de construction ou de mise en place des éléments un par un qui pourraient provoquer des interruptions dans le processus d’installation, ou bien des demandes d’informations manquantes ou erronées dans la description de Kickstart. Dans tous les cas, après quelques tentatives, l’erreur est presque toujours repérée, preuve de l’efficacité de cette méthode d’installation.

Dans l’Encadré 4, un exemple des grandes possibilités de Kickstart est présenté, en utilisant une vieille carte réseau non reconnue et un script post installation. lang de_DE

langsupport de_DE

keyboard de-latin1-nodeadkeys

mouse generic3ps/2

timezone Europe/Berlin

rootpw redhattestpasswort

text

install

nfs --server=192.168.7.1 --dir=/kickstart/FC1A

Page 227: Administration UNIX - Cours Jussieu - 2009-2010

70

Fedora Kickstart Red Hat Magazine 2004 N° 3

Préparation d’un CD-ROM de lancement Dans le cas où les drivers réseau nécessaires pour l’instal-lation ne seraient pas compatibles avec une disquette, nous vous conseillons d’utiliser un CD-ROM de lancement.Mastérisez le fichier image ISO boot.iso, disponible dans le même répertoire de la disquette de démarrage, sur un CD vierge et activez ensuite le lancement à partir du CD-ROM dans le BIOS de l’ordinateur à installer. Il suffit de taper linuxks pour activer le mode Kickstart. Il est conseillé de ne pas modifier le fichier syslinux.cfg pour le lancement automatique, parce qu’ il arrive souvent d’oublier les CD-ROM dans le lecteur et cela conduirait à une nouvelle installation à chaque démarrage. Pour remédier au problème, surtout dans les cas d’ installations importantes, il est utile d’envoyer un message à la fin du processus d’installation qui indique à l’administrateur sur quels ordinateurs l’installation a déjà été effectuée.

Lancement du programme d’installation par l’inter-médiaire de PXE

PXE est sans doute la façon la plus élégante pour exécuter d’importantes installations en réseau. Il est particulièrement indiqué comme protocole pour les nombreuses cartes réseaux installées dans les ordinateurs d’entreprises. PXE est en mesure de charger le programme d’exécution de Fedora, directement à partir du réseau, en évitant par conséquent l’utilisation d’un support de lancement. Il est aussi possible d’inclure des options au lancement qui permettent à l’utilisateur d’effectuer le rétablissement automatique du système. Puisqu’il n’est pas possible dans cet article d’illustrer en détail l’environnement PXE, nous vous renvoyons sur le site http://www.stanford.edu/~alfw/PXE-Kickstart/PXE-Kickstart.html qui contient un article intéressant de Alf Wachsmann avec des instructions détaillées sur l’utilisation de Kickstart. Procédure d’installation Après avoir inséré le support et démarré l’ordinateur, Fedora commence par lancer l’Installer Anaconda. En mode Kickstart avec configuration basée sur réseau, Kickstart tente avant tout d’obtenir sa propre adresse IP au moyen d’une requête DHCP et ensuite de charger le fichier de description correspondant à partir du serveur. Si cette procédure est exécutée correctement, la configuration de base peut être estimée complète. Pendant l’installation, il est possible de tenir sous contrôle l’image normale d’installation sur la console 1 (ALT+F1). D’autres fonctions de l’Installer sont, quoi qu’il en soit, disponibles à partir d’une phase déterminée du processus d’installation. Sur la console 2 (ALT+F2) il sera possible de trouver une console Bash pour la récolte d’informations pour le debugging. La console 3 permet de relever d’éventuels problèmes hardware car c’est souvent ici que sont visibles les modules du kernel. C’est pourquoi, en cas de problèmes

Les informations relatives aux groupes de paquetages utilisés dans le fichier description, comme par exemple @Graphical Internet, sont disponibles dans le fichier : /kickstart/FC1ARed Hat/base/comps Il est important d’observer que l’Installer de Red Hat n’effectue que l’installation de paquetages signés électroniquement Red Hat. Tous les paquetages tiers doivent être installés dans la section %post au moyen de la commande rpm. C’est-à-dire qu’il permet d’obtenir une installation de base toujours stable. Préparation d’une disquette de démarrage Pour créer une disquette de démarrage, insérez le premier CD de Fedora dans le lecteur de CD-ROM approprié et une disquette 1,44 formatée dans le premier lecteur de disquettes de l’ordinateur.

Tapez ensuite les commandes suivantes : #mount /mnt/cdrom #dd if=/mnt/cdrom/images/bootdisk.img \ of=/dev/fd0#umount /mnt/cdrom De cette façon, une image générique pour les installations a été écrite sur disquette.

Une telle disquette pourra par conséquent être utilisée pour les installations standard de Linux avec une base réseau, ou même pour les installations automatiques de Kickstart. Pour lancer automatiquement le mode Kickstart linuxks, montez la disquette qui vient d’ être mentionnée en tapant : #mount /mnt/floppy Suivez la méthode appropriée parmi les deux rapportées ci-dessous :

1. Fichier Kickstart sur disquette (basé sur disquette)En utilisant l’éditeur de texte désiré, modifiez les deux lignes suivantes dans le fichier /mnt/floppy/syslinux.cfg prompt 0default linux ks=floppy 2. Fichier Kickstart en réseau (basé sur réseau)Modifiez les deux lignes suivantes dans prompt 0default linux ks A la fin de cette opération, il sera possible de copier le fichier de configuration de Kickstart de la disquette dans le fichier /mnt/floppy/ks.cfg

Daemontez de nouveau la disquette en tapant : #umount /mnt/floppy

Page 228: Administration UNIX - Cours Jussieu - 2009-2010

Fedora Kickstart

71

Red Hat Magazine 2004 N° 3

durant l’installation, il est utile de les contrôler via cette console. En outre, contrôlez toujours le fichier /var/log/messages dans le serveur approprié. En rappelant la commande : #tail-f /var/log/messages Il sera possible de visualiser « en live » et par conséquent de contrôler les commandes du processus d’installation qui ont été exécutéés correctement et celles qui, inversement, présentent des problèmes.

Par exemple, le manque de réception de signaux DHCP ou NFS venant de l’ordinateur client est attribuable à un problème hardware sur le réseau. Le paquetage sniffer tcpdump permet également, par exemple, de diagnostiquer des problèmes hardware s’il ne relève aucun trafic du client.

Séquence d’ installation Kickstart.

Sources d’ erreur Les partages erronés NFS représentent une source d’erreur bien connue dans les installations automatiques, puisqu’ils ne permettent pas à l’hôte d’accéder aux fichiers de configuration et de distribution de Kickstart. Avec la commande :

#showmount -e <Adresse IP du serveur> Il est toujours possible de visualiser tous les partages NFS du serveur intéressé. Le problème est presque toujours dû à des erreurs d’introduction contenues dans ces partages.

Un autre type d’erreur très fréquemment rencontré dans les installations de Kickstart est une syntaxe incorrecte dans le fichier de description, qui provoque une interruption du processus d’installation ou bien également, dans bien des cas, une erreur d’un script python. Ces erreurs se trouvent presque toujours dans la description de base du système plutôt que dans les scripts %pre ou %post. Par conséquent, la meilleure solution consiste à effectuer une comparaison avec les scripts déjà contrôlés et corrects. Si quelques scripts ont été créés manuellement avec la GUI, il sera possible de résoudre encore plus rapidement les problèmes éventuels grâce à la familiarité acquise. Installation de paquetages séparés Sur des groupes d’ordinateurs installés avec Kickstart, il pourrait être nécessaire d’installer par la suite de nouvelles versions de logiciels. Dans ce but, utilisez l’outil de gestion des paquetages RPM, lesquels peuvent être installés dans le script %post. Les paquetages RPM permettent d’effectuer des personnalisations complexes qu’il sera possible par la suite, de supprimer au moyen des commandes standard, ainsi que d’ajouter quelques utilisateurs ou de créer un profil pour des activités déterminées. L’Encadré 5 illustre un exemple pour un fichier spec qui permet d’ajouter un utilisateur qui pourra être supprimé à n’importe quel moment. Le but de l’exemple est de contrôler à distance un numéro vert. Pour exécuter cette opération, il a été fait référence à un script log dans une archive tar du fichier spec. L’installation des paquetages RPM avec le script -%post de Kickstart permet d’étendre également l’accès à tous les autres ordinateurs. Summary: RemoteSupportUser

Name: remotesupport

Version: 0.1

Release: 1

License: GPL

Group: System Environment/Base

Source0: %{name}-%{version}.tar.gz

Buildroot: %{_tmppath}/%{name}-%{version}-buildroot

Packager: Frederik Bijlsma <[email protected]>

Provides: remotesupportuser

Boot à partir du CD-ROM/Disquette

DHCP: Détermination de la configuration de réseau

NFS: Montage du répertoire /kickstart

Interprétation de la configuration de Kickstart

Partitionnement et formatage du disque dur

%pre-script

Installation et configuration des paquetages

%post-script et redémarrage

Page 229: Administration UNIX - Cours Jussieu - 2009-2010

72

Fedora Kickstart Red Hat Magazine 2004 N° 3

Frederik Bijlsma

est consultant pour Red Hat, Stuttgart

Requires: /bin/mail

BuildArch: noarch %description

NULL %prep%setup -q %build#empty %installrm -rf %{buildroot} mkdir -p %{buildroot}/home/remotesupportuserinstall -m 0755 .logrc %{buildroot}/home/remotesupportuserinstall -m 0755 .bash_profile %{buildroot}/home/remotesupportuser %cleanrm -rf %{buildroot}

%preuserdel remotesupportuser >/dev/null 2>&1userdel `awk -F: ‘$3 == «9993»’ /etc/passwd | awk -F: ‘{ print $1 }’` >/dev/null 2>&1

useradd -c «Remote Support User» -d /home/remotesupportuser -g root -s /bin/bash -u 499 remotesupportuser >/dev/null 2>&1 %postunuserdel remotesupportuser > /dev/null 2> /dev/null %files

%defattr(-,root,root)%attr(0775,remotesupportuser,root) /home/remotesupportuser/scriptlog

%attr(0755,remotesupportuser,root) /home/remotesupportuser/.bash_profile

%attr(0755,remotesupportuser,root) /home/remotesupportuser/.logrc %changelog

Conclusion

Le présent article a décrit une installation Kickstart basée réseau, reposant sur un serveur DHCP fonctionnel et un serveur NFS disposant des fichiers de description Kickstart et des supports d’installation. Puisque beaucoup d’entreprises utilisent déjà ces deux types de serveurs au sein de leurs réseaux, l’utilisation de Kickstart ne devrait pas se révéler trop dispendieuse, excepté les quelques modifications nécessaires à apporter. L’utilisation de Kickstart est recommandée lorsqu’il est nécessaire d’installer simultanément de nombreux ordinateurs comme, par exemple, pour les clusters. Avec un réseau très rapide, il est possible d’installer en l’espace d’une heure de nombreuses machines, automatiquement ou individuellement. Après avoir acquis un peu de pratique, il sera possible d’utiliser Kickstart pour diverses raisons, par exemple pour installer de grands clusters ou pour rétablir le poste de travail de l’ordinateur de la secrétaire, sans devoir payer des techniciens qui généralement réclament une compensation supplémentaire pour ces opérations. En cas de problème avec l’utilisation de Kickstart, consultez la mailing list à l’adresse h t tp : / /www.redha t . com/arch ives /k i cks t a r t - l i s t / . Naturellement, il est également possible de se référer au support technique, mais avec Kickstart vous en aurez rarement besoin.

Encadré 5 : firmeuser.spec

Page 230: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 11

Synchronisation de fichiers

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 380 / 803

11 Synchronisation de fichiers 11.1 IntroductionChapitre 11 • Synchronisation de fichiers§11.1 • Introduction

Contexte : deux ou plusieurs machines qui ne peuvent pas partager defichiers par NFS.Exemples :

un ordinateur portable et une machine de bureaudeux ordinateurs reliés par une liaison intermittente comme uneliaison téléphonique PPPetc.

La synchronisation manuelle est pénible à faire.

Plusieurs logiciels automatisent la synchronisation. Reste à les lancer aubon moment (cf CRON) et à paramétrer ce que l’on doit synchroniser.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 381 / 803

Page 231: Administration UNIX - Cours Jussieu - 2009-2010

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdistChapitre 11 • Synchronisation de fichiers§11.2 • Synchronisation de fichiers UNIX via rdist

RDIST est un programme de distribution de fichiers sur des machinesdistantes, sur la base des dates de modification des fichiers source ou desfichiers distants.

De plus en plus livrée en standard avec les différents UNIX mais luipréférer quand même la version disponible à l’URL« http://www.magnicomp.com/rdist/ » (anciennement :« ftp://ftp.usc.edu/pub/rdist/ »)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 382 / 803

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

La commande « rdist » utilise un fichier de configuration appelé pardéfaut « distfile » ou « Distfile »

Si le fichier ne s’appelle pas « distfile » ou « Distfile », il faututiliser l’option « -f » :

% rdist -f mon-distfile-a-moiremote.example.com: updating host remote.example.com

...

De nombreuses options sont disponibles. Cf la documentation.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 383 / 803

Page 232: Administration UNIX - Cours Jussieu - 2009-2010

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

� Exemple 1

Objectif : mettre à jour du fichier « /tmp/fichier.txt » d’une machinedistante nommée « remote.example.com » à partir du fichier local« /tmp/fichier.txt » :

Solution : fichier « Distfile » contenant :

/tmp/fichier.txt -> remote.example.com

install ;

Utilisation et résultats :

% rdistremote.example.com: updating host remote.example.com

remote.example.com: /tmp/fichier.txt: installing

remote.example.com: updating of remote.example.com finished

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 384 / 803

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

La mise à jour ci dessus est inconditionnelle. Elle ne fait pas decomparaison de date. Pour activer la vérification des dates demodification, il faut utiliser l’option « -y ».

% rdist -yremote.example.com: updating host remote.example.com

remote.example.com: updating of remote.example.com finished

Notez les différence avec les résultats précédents.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 385 / 803

Page 233: Administration UNIX - Cours Jussieu - 2009-2010

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

� Exemple 2 : macros

Objectif : mettre à jour les fichiers « /var/tmp/fichier.txt » et« /var/tmp/fichier2.txt » des machines distantes nommées« remote.example.com », « remote2.example.com » et« remote3.example.com » à partir des fichiers locaux originaux« /tmp/fichier.txt » et « /tmp/fichier2.txt ».

Soit le fichier « Distfile » contenant les lignes suivantes :

FILES = ( /tmp/fichier.txt /tmp/fichier2.txt )

HOSTS = ( remote.example.com remote2.example.com

remote3.example.com )

${FILES} -> ${HOSTS}

install /var/tmp ;

notify besancon ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 386 / 803

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

On constate :on utilise des macros : « FILES », « HOSTS »on met à jour des fichiers distants de paths différents des originauxon envoie un mail une fois la mise à jour faite

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 387 / 803

Page 234: Administration UNIX - Cours Jussieu - 2009-2010

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

Possibilité de ne mettre à jour qu’une machine du lot via l’option « -m » :

% rdist -m remote.example.comremote.example.com: updating host remote.example.com

remote.example.com: /tmp/fichier.txt: installing

remote.example.com: /tmp/fichier2.txt: installing

remote.example.com: notify @remote.example.com ( besancon )

remote.example.com: updating of remote.example.com finished

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 388 / 803

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

Une seconde mise à jour donne :

% touch /tmp/fichier.txt% rdist -yremote.example.com: updating host remote.example.com

remote.example.com: /tmp/fichier.txt: updatingremote.example.com: notify @remote.example.com ( besancon )

remote.example.com: updating of remote.example.com finished

Notez le mot « updating » au lieu de « installing ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 389 / 803

Page 235: Administration UNIX - Cours Jussieu - 2009-2010

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

� Exemple 3 : directive special

Soit le fichier « Distfile » contenant les lignes suivantes :

/tmp/fichier.txt -> remote.example.com

install ;

special "uname -a" ;

Son exécution donne :

% rdistremote.example.com: updating host remote.example.com

remote.example.com: /tmp/fichier.txt: installing

remote.example.com: special "uname -a"remote.example.com: FreeBSD remote.example.com 4.6.1-RC2remote.example.com: updating of remote.example.com finished

On constate qu’une fois la mise à jour des fichiers réalisée, la commandespécifiée par « special » est exécutée sur la machine distante.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 390 / 803

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

� exemple 4 : essai à blanc

L’option « -n » essaye à blanc le scenario de mise à jour mais ne réalisepas la mise à jour en pratique.

Avec le fichier « Distfile » de l’exemple 1, on voit ainsi :

% rdist -nupdating host remote.example.com

install -onochkgroup,nochkowner,younger /tmp/fichier.txt

/tmp/fichier.txt

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 391 / 803

Page 236: Administration UNIX - Cours Jussieu - 2009-2010

11 Synchronisation de fichiers 11.2 Synchronisation de fichiers UNIX via rdist

� Exemple 5 : transport via SSH

On peut utiliser SSH comme protocole de transport avec la machinedistante au lieu de RSH.

Avec le fichier « Distfile » de l’exemple 1, on voit ainsi :

% rdist -P /usr/local/bin/sshremote.example.com: updating host remote.example.com

Enter passphrase for key ’/users/sri/besancon/.ssh/id_dsa’: XXXXXXXXXXremote.example.com: /tmp/fichier.txt: installing

remote.example.com: updating of remote.example.com finished

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 392 / 803

11 Synchronisation de fichiers 11.3 Synchronisation de fichiers UNIX via rsyncChapitre 11 • Synchronisation de fichiers§11.3 • Synchronisation de fichiers UNIX via rsync

(en anglais Remote Synchronisation)

RSYNC est un protocole plus efficace que RDIST. Par exemple, on netransfère que les différences entre fichiers et non pas la totalité du fichier.

Pas encore installé en standard. Se reporter à« http://rsync.samba.org/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 393 / 803

Page 237: Administration UNIX - Cours Jussieu - 2009-2010

11 Synchronisation de fichiers 11.3 Synchronisation de fichiers UNIX via rsync

On utilise la commande de ces diverses façons :

rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST

rsync [OPTION]... [USER@]HOST:SRC DEST

rsync [OPTION]... SRC [SRC]... DEST

rsync [OPTION]... [USER@]HOST::SRC [DEST]

rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST

rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]

Il y a un mode de fonctionnement où un démon « rsyncd » est installé etrépond à des requêtes authentifiées ou non.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 394 / 803

11 Synchronisation de fichiers 11.3 Synchronisation de fichiers UNIX via rsync

� Exemple

Soit l’arborescence « /tmp/exemple » à synchroniser :

% ls -lR /tmp/exemple/tmp/exemple/:

total 64

-rwxr-xr-x 1 besancon adm 211 Aug 26 17:53 fichier1*-rwxr-xr-x 1 besancon adm 211 Aug 26 17:53 fichier2*-rwxr-xr-x 1 besancon adm 211 Aug 26 17:53 fichier3*drwxr-xr-x 2 besancon adm 182 Aug 26 17:54 repertoire1/

/tmp/exemple/repertoire1:

total 16

-rwxr-xr-x 1 besancon adm 211 Aug 26 17:53 fichier4*

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 395 / 803

Page 238: Administration UNIX - Cours Jussieu - 2009-2010

11 Synchronisation de fichiers 11.3 Synchronisation de fichiers UNIX via rsync

La synchronisation avec une autre machine appelée« remote.example.com » par la commande suivante :

% rsync \

--stats \

--rsh=/usr/local/bin/ssh \

--rsync-path=/usr/local/bin/rsync \

--archive \

--compress \

--verbose \

--cvs-exclude \

\

/tmp/exemple \

[email protected]:/tmp

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 396 / 803

11 Synchronisation de fichiers 11.3 Synchronisation de fichiers UNIX via rsync

La commande précédente affiche :

building file list ... done

exemple/

exemple/fichier1

exemple/fichier2

exemple/fichier3

exemple/repertoire1/

exemple/repertoire1/fichier4

Number of files: 6Number of files transferred: 4Total file size: 844 bytes

Total transferred file size: 844 bytes

Literal data: 844 bytes

Matched data: 0 bytes

File list size: 161

Total bytes written: 825

Total bytes read: 84

wrote 825 bytes read 84 bytes 606.00 bytes/sec

total size is 844 speedup is 0.93

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 397 / 803

Page 239: Administration UNIX - Cours Jussieu - 2009-2010

11 Synchronisation de fichiers 11.4 Synchronisation de fichiers WINDOWS via FullSync.exeChapitre 11 • Synchronisation de fichiers§11.4 • Synchronisation de fichiers WINDOWS via FullSync.exe

Programme FULLSYNC pour Windows.« http://fullsync.sourceforge.net/ »Synchronisation de fichiers entre disques locauxSynchronisation de fichiers entre disques locaux et réseau via FTP,SFTP, SMBSynchronisation unidirectionnelle sans effacement sur la destinationSynchronisation unidirectionnelle exacteSynchronisation bidirectionnelleProgrammation à la CRON

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 398 / 803

11 Synchronisation de fichiers 11.4 Synchronisation de fichiers WINDOWS via FullSync.exe

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 399 / 803

Page 240: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 12

SAMBA

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 400 / 803

12 SAMBA 12.1 IntroductionChapitre 12 • SAMBA§12.1 • Introduction

Voir cours de Franck RUPIN.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 401 / 803

Page 241: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 13

Systèmes d’impression

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 402 / 803

13 Systèmes d’impression 13.1 Langage d’impression PostscriptChapitre 13 • Systèmes d’impression§13.1 • Langage d’impression Postscript

Langage créé par la société Adobe (« http://www.adobe.com »)

Dessin vectoriel.

Le nom d’un fichier Postscript se finit en général par le suffixe « .ps » ou« .eps ».

Système de coordonnées au sein d’une page PostscriptFormat américain (dit letter) : 612 x 795Format européen (dit a4) : 595 x 842

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 403 / 803

Page 242: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.1 Langage d’impression Postscript

Langage de description de page, fonctionnant avec une stack (pile).

Par exemple 1 + 6− 5 peut se coder :forme 1 6 5 sub add

forme 1 6 add 5 sub

forme 1 6 5 neg add add

etc.ce qui donne avec la première forme :

1

6

5

1

2

sub

1

add

Un document à imprimer = un programme à exécuter

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 404 / 803

13 Systèmes d’impression 13.1 Langage d’impression Postscript

Le contenu d’un fichier Postscript commence par les 2 premiers caractères« %! ».

Les fichiers Postscript destinés à être inclus dans d’autres documents sontdits Encapsulated Postscript (ou EPSF) et commencent par une ligne dugenre :

%!PS-Adobe-2.0 EPSF-1.2

suivie d’autres lignes de commentaires actifs :%%Creator:Adobe Illustrator(TM) 1.0b2-

%%Title:golfer art+

%%CreationDate:1/6/87 9:32 AM

%%DocumentFonts:Helvetica-Bold

%%BoundingBox:7 31 577 726

dont « %%BoundingBox: » qui détermine les dimensions du dessin.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 405 / 803

Page 243: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.1 Langage d’impression Postscript

Par exemple, le code suivant :

%!

/Times-Roman findfont 40 scalefont setfont

60 500 moveto

(TEST DE L’IMPRIMANTE) show

175 300 moveto

(T.BESANCON) show

showpage

donne, une fois imprimé, la pagesuivante :

TEST DE L’IMPRIMANTE

T.BESANCON

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 406 / 803

13 Systèmes d’impression 13.1 Langage d’impression Postscript

Les dessins en Postscript peuvent être complexes :

Poids de ce dessin vectoriel (par tête) : 78606 octets, ce qui est faible parrapport à du bitmap

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 407 / 803

Page 244: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.1 Langage d’impression Postscript

Un document à imprimer = un programme à exécuter

La partie logicielle qui exécute le fichier Postscript est un interpréteurPostscript.

L’interpréteur Postscript le plus connu est ghostscript.

Cf « http://www.ghostscript.com »

Initialement disponible sur UNIX, il est maintenant disponible sur Windowset sur Macintosh sous une forme avec interface graphique :

« ftp://ftp.lip6.fr/pub/gnu/ghostview/ » (GUI UNIX)« http://wwwthep.physik.uni-mainz.de/~plass/gv/ » (GUIpour UNIX)« http://www.cs.wisc.edu/~ghost/gsview/ » (GUI pourWindows)« http://www.cs.wisc.edu/~ghost/macos/ » (GUI pourMacintosh)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 408 / 803

13 Systèmes d’impression 13.1 Langage d’impression Postscript

L’intérêt de ghostscript est :visualiser des fichiers Postscript comme les documentationsconvertir des fichiers Postscript en d’autres formats :

FAXPDFPCL pour imprimante PCetc.

Mais la principale utilisation de ghostscript doit être certainementmaintenant sur Linux où il sert à convertir du Postscript en langage PCLqui est compris par les imprimantes PC.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 409 / 803

Page 245: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.1 Langage d’impression Postscript

Quelques utilisations intéressantes :

calculer la BoundingBox d’une figure Postscript :gs -sDEVICE=bbox fichier.ps

afficher au format A4 :gs -sPAPERSIZE=a4 fichier.ps

convertir du Postscript en PDF au format A4 :ps2pdf13 -sPAPERSIZE=a4 fichier.ps

(ps2pdf13 est un shell script construit autour de gs avec les bonnesoptions)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 410 / 803

13 Systèmes d’impression 13.1 Langage d’impression Postscript

Comment imprimer un fichier texte sur une imprimante Postscript ?

Réponse : après l’avoir converti en Postscript

Quelques outils :outil a2ps, cf « http://www.gnu.org/software/a2ps/ »outil gnu enscript, cf« http://www.gnu.org/software/enscript/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 411 / 803

Page 246: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.1 Langage d’impression Postscript

Comment imprimer plusieurs pages côte à côte (format dit N up) ?

Réponse : convertir en fichier Postscript « normal » le fichier original puisregrouper les pages sur la même page via un autre code Postscript

Quelques outils :outil a2ps, cf « http://www.gnu.org/software/a2ps/ »outil mpage, cf « http://www.mesa.nl/pub/mpage/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 412 / 803

13 Systèmes d’impression 13.2 Langage d’impression PCLChapitre 13 • Systèmes d’impression§13.2 • Langage d’impression PCL

PCL ≡ Printer Command Language

Langage de description de la page à imprimer.

Développé par HP pour ses imprimantes.

6 versions de PCL : PCL 1 (années 1980), PCL 2 (années 1980), PCL 3(1984), PCL 4 (1985), PCL 5 (HP Laserjet III), PCL 6 (HP Lasetjet 4000)

Les commandes PCL sont des séquences d’escape. Par exemple EcE&l3A

(passe en papier letter).

Pour convertir du Postscript en PCL, faire :

gs -q -sSAFER -sDEVICE=deskjet -sOoutputFile=fichier.pcl -dNOPAUSE fichier.ps

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 413 / 803

Page 247: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.3 Langage d’impression PJLChapitre 13 • Systèmes d’impression§13.3 • Langage d’impression PJL

PJL ≡ Printer Job Language

Language de contrôle de l’impression des jobs.

Par exemple :sélection du bac d’entrée ou de sortie de papierimpression recto versotaille du papierfichier PCL ou fichier Postscriptetc.

Exemple de commande : ESC%-12345X@PJL DEFAULTS DENSITY=5

Le logiciel ifhp associé à LPRng sait tirer pleinement parti du langagePJL.Cf « http://www.lprng.org »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 414 / 803

13 Systèmes d’impression 13.4 L’imprimante vintageChapitre 13 • Systèmes d’impression§13.4 • L’imprimante vintage

L’imprimante « vintage » :imprimante matricielle etc. avec ruban à encrepapier listing avec bande d’entrainement sectionnableconnexion par voie série à 9600 bauds, gestion du flux XON/XOFF

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 415 / 803

Page 248: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.4 L’imprimante vintage

caractères normaux .’’.’ ’. . ’’ ".’.:I:.’.. ’. .’.:.:....:II: .’.’.. . .’:.’::.:I:.:II:’.’.’.’..’. .’.’.’.’::.:.:.:I:’.’.’.’. . ’ ..’.’.’.:.:I::.:II:.’..’.’.. . ..’.’’:.:.::.:.::II::.’.’.’.’.. . ..’.’.’.:.::. .:::II:.:’.’.’.’.’. . .’:.’’.’:’.’.’.:.:I.’.’.’.’.’.. ’.. .. ’:. ’.’:’. ..:.::.::.:.’..’ ’:.’.’.. .. .:.:.’:’. .:’:I:.:.. .’.’. ’: .’.. ’ .. ’..:.:’. .:.II:.:.. . .:.’. ’.. ’. . .. .. :.:.’. .:.:I:.:. . . ..:..:. :..’:. . ’. .:. :.:. .:.:I:.:. . . ..:I::. :: :: .. .. .. :’.’.:. .:.:I:’. ..:.:I:. :: ::. . ’. ’..:. .:.. .:II:’ ..:IIIM. ::. ’:. . .:.::’.:::..:.AII:. .::’.. :I .::.:’:. . :..:’.:II:.:I: ..:’ . .::PBI’X:: ..:.. ’:. . . .. :’:III:. :.:A’PPF:. . .P.IP::’:: :I:..’::. . .. . .:.:II: A.’.’:.PB:’ . . ..’..’ .:.:.::. ’:... . .. . .: .:IIIM:. ’ ’.’ . ... . .:. :.:.. :... . . .I.::I:IIA. .. ... ..::.’.’.’.: .. . . .:II.’.’:IA:. .. ..:. . .:.: .’’.’ .. . . ..::I:.’.’::A:. . .:’−. .−.:.. .:.::AA..:..:.’ .. . ’:II:I:. ’:A:. ..:’ :. . : ..:::AMI: ..:..’.’. .’:III.::I ’II:.:...::::::::−. .:::AMV:: .::’’ .. ..":IIMI::. . −I:..’::....::−. . .:AII:: :.:’ . . . . IIMMI:..’.’.’V::. −::::− ...:AIIV:’.:.’ .. . . . :IIMI:. .:.:.V:. ’ ’ . ...:MI:’ .:: :. . ..’ . . ’:IMII:: ::.IA.. .. .A ...:::’ .:. . :. ...’I:I:.: ..AMMA. . .’..AMIV::’ . . : .. :. ’.::::II:.I:.MIMMIMMMMMIMMIMV:’..:: .I.’:. .. ’. . . .. ’’:::I:’.::IMMMMMMMMMMMMIMI. ’.’.:IMI.. ’ ’ ’. ’:... . ’’" .::’.MMMI:MMMMMMMIMI. :IIMMII:. I I I . :.:.. . ..::.’ .IV".:I:IIIMIMMIM. .:IMI::’.’: ’.. . . . .:.:: .. ::’.’ ’..’:.::I:I:IMMMIA.’.II.:...:’ .’ ... . ’.. ’..::::’ ...::’.IIMII:: .:.:..:..:III:.’::’ .’ . .. . . ’::.:’ .’’ .. :IIMI:.:.. ..: . .:I:"’ ...:.:. .. .. .. .:.:::I:. . . . .IMII:.:’ .. ..".::.:II:.:. .: ... . .. .. . .::.:......−::II:.:’ . ...... . .. .:II:.:: ... .. .. ..:.::.I . . . .. .:. .... ...:.. . . ..:.::. :.. . .. .’.::I:. . .. ..:.... . ..... .. . ..::. .. .I:. ..’ . .’’:.: I. . .. ..:.. . . .. ..... .:. .:.. .:I.’.’’.. . .:::I:. . . .. .:. . .. .. . ... .:.’.’I’ . ... . .:::I:. . . .. .:. . .. .. . ... .:.:.:. ’’.’’ ’.’::’I. . .. ....:. . .. . .. ..’ .’.:..:.. ’ :. . . .. .. .:.... . . .... ... . .:.:.:.. ’. :. . . . .. .:.... . . ........ .:.:.::. . . :. . . . . . .. .::..: . ..:.. . ::.:.:.. . . :.. . . . . . .. ..:.: .. .. .: .. ’:::.::.:. . . ’:.. . . . . .. .. ...::’ .. .. . .:. . V:I:::::.. . .. ’::. . . .. .. ... .:.:: .. . . .. .. . VI:I:::::.. .:. :.. . . .. ..:.. ..I:... . . . .. ... . VII:I:I:::. . :::, ’:.. . . . .. ..:..:.:I:.:. . . .. . .:. . VMIII:I::..’ :::’ ::.. . . .. ..:..:.MI:. . . . .... . :MMIMIII:I:: :: ’:. . . .. .. ..:.:.:MI:. . . .. ..... . MMMMIMII’I: . :.. . . . .. .:.:.:.MI:. . . .. ... . IMMMMIMMIMI. :.. . . . .. ..:..IM:. . . .. .. ... . ’MMMMMMMMMI ’:.. . . .. ..:.:.:MI.. . . .. . :::::. MIM:"""’ :. . . . .. ..::.:.VII. . . .. .:::’::. MIM :.. . . .. .:.:.:.VI. . . . ...::I"A:. MMV :. . . . .. ..:.:.VI. . . ....::I::’.MV: :. . . . . .. .:..II:. . . . ....’:::’ AV.’ :.. . . .. ... .:..VI:. . . .. .:. ..: .AV’. ’:.. . . .. ..:.:.:MAI:.:...:.:.:.:.AII:. I:. . .. ... .:.:.VMMII:..:.:..:A:’.:.. IA.. . . .. ..:.:.:VMMMMIMIMMIMI:’.::. ’MAI. . . .. ..:.:.:MMMIMIMMMIMI:..:. MIA: . . . .. ...:.VMMMIMIIMI::.:... MIMI:. . .. ... .::.MMMIIMIIMI:::.. MII:.:. . .. ... .::VMMIMI:I::.:.. AI:..:.. . . .. ..:.VMIII:I::.:. . AI:. ..:.. . . .. ..’ VMIII:I:... . AI:. . .:.. . . . ... VMIII::... . .A:. . :.. . . .. .:.. VMII::.. . A:. . . ::. .. .. . .:.. "VMI::.. . .:.. . . :.. .:..... .::.. VMI:.. ... . . . . . :.:. ..:. . .::.. VI:.. . .. .. . . . . ...:... . .. . .:::. V:.. . ’.. .. . . .. ..:::.... .:. . ..::.. V.. . . . .. . . . . .. ..:::A. ..:. . . .::.. :.. . .. .. .. . . . ... ..::IA.. .. . . ..::. :.. . .. .. ... . . .. .... .:.::IA. . .. . ..:.::. :. . . . . .. . . . .. ..:..:.::IIA. . . .. .:.::. :. . .. . . . . . .. ... ..:.::I:OMA. . . . ..:.::. . . .: .. . . . . ... .:.. .:I:IIMMA. . . .. .::I:. . .::. . . . .. ..:. .::.:IIMIIMMMA. . .. ..:I:. . . A::.. . . ...:..:.::I:IMIMIMMMMA. . . ..::I:. . :MI:.. . . .. .:.:.::I:IMIMIIMIMMMA. . .. .::I:. .. AI:.. .. . . .. .:.:.::II:IMIIIMIMIMMMA. . . ..::I:. .. :MI:.. . . . . .. .::.:I:IMIMIIIMIMIIMMMA.. . .. .::I:. .. AI:.:.. . . . ... .::.::I:IMIIMIMIMIMIMIMMA. . . ..::I:. . MI:. .. . . . . .. .:..::IIMIMIMIIIIMMIIMMMMA. . . .:::I:. . . MI:.. . . . . .. ..:.::I:IIMMIIMIMIMIMMMMV" .. . ..:::II: . . MI::.. . . . .. .:..:::IIMIMIIMIMIIMMMM" . .. . ..::III: . . II::.:.. . . . .. ......:..IMMMIMMMMMM2.. . . . . ’... .:.:IMI:.. II:I::.. . . . . .....::.:IMMMMMMMM:.. . . . . .:..:::IIMII.. MI::.:. . . . . . ...:.::.::.MMMMM::.:.... . . .. . :.. ..:IMMI:: MII::.:.. . . . .. .:..:.’. ’MMMI::.::.:.. . . . .. ’:...:II:III III::.:... . . . ...:.:... . MII:I::.:.. . . .. . . :.:::...:: VII::.:.. . . . .. ...:.... VMI:I::.:.. . . ... .. .::.:..:.: VII::.:.. . . ..:.::.. : :MMII:I::.:.. . . .. .. .’::’:... III:I::.. .. . . .. .:.:.. . :VNIMI:I::.:... . . .. .. .’:. ..

Lundi 25 Juin 2007 00:42:23 woman1.txt Page 1

caractères gras par réécriture d’un caractèreune seconde fois sur lui-même :A = « A backspace A »

= « A^HA »idem pour caractères soulignés

A = « A backspace underscore »= « A^H_ »

peu ou pas de polices de caractèrespeu ou pas de possibilités de tailles variéesde caractèresdocuments au format texte uniquementpas de graphiques ou de dessin (sauf ASCII art)etc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 416 / 803

13 Systèmes d’impression 13.4 L’imprimante vintage

Résumé des caractéristiques des impressions sur ce type d’imprimantes :

connexion non réseau par voie série (plus tard par voie parallèle)

⇒ imprimer = « cat rapport.txt > /dev/tty0a »

Dans cette logique, un logiciel d’impression est avant tout capable de gérerdes voies séries.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 417 / 803

Page 249: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.5 L’imprimante moderneChapitre 13 • Systèmes d’impression§13.5 • L’imprimante moderne

L’imprimante moderne : photocopieur, imprimante réseau, scanner, fax

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 418 / 803

13 Systèmes d’impression 13.5 L’imprimante moderne

Caractéristiques :

Photocopieur :codes d’accèsquotas de photocopiesrelevé des compteursserveur web intégré : protection des accès, certificats HTTPS, etc.

Imprimante réseau :configuration réseau minimale (adresse IP, netmask, routeur, . . .)configuration réseau avancée : ACL pour contrôler les accèsd’impression, d’email, de partage de fichiersdisque dur local (pour stocker des polices supplémentaires, des logos,des documents fréquemment imprimés, etc.)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 419 / 803

Page 250: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.5 L’imprimante moderne

Caractéristiques (suite) :

Scanner (vers formats TIFF ou PDF) avec envoi des fichiersnumérisés par email ou récupération par FTP des fichiers numérisés :

logiciels spécifiques sur le poste de travail de l’utilisateur, driversTWAIN, etc.attention aux logiciels ne travaillant que sur un seul subnet ethernet !configuration des paramètres de messagerie électroniqueconfiguration d’un annuaire LDAP d’entreprise ou des contacts del’entrepriseconfiguration de partages réseau pour accéder aux fichiers scannésstockés sur le photocopieur, configuration des ACL réseau pour FTP,. . .

Système d’exploitationbugs (exemple gestion LDAP sur photocopieur CANON couleur)disque dur + problèmes de disques durslicences logicielles (codes d’activation, dongles, etc.)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 420 / 803

13 Systèmes d’impression 13.5 L’imprimante moderne

Résumé des caractéristiques des impressions sur ce type d’imprimantes :

connexion réseau par TCP/IPprotocoles réseau implémentés dans l’imprimante

⇒ imprimer = « dialogue selon des protocoles avec un hôte TCP/IPqui prend en charge un fichier au jargon spécifique à imprimerphysiquement »

Dans cette logique, un logiciel d’impression est avant tout capable dedialoguer en réseau selon des protocoles spéciaux.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 421 / 803

Page 251: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.6 Scenarios d’impressions possiblesChapitre 13 • Systèmes d’impression§13.6 • Scenarios d’impressions possibles

Pleins de scenarios sont possibles dans le monde de l’impression :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 422 / 803

13 Systèmes d’impression 13.6 Scenarios d’impressions possibles

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 423 / 803

Page 252: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.6 Scenarios d’impressions possibles

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 424 / 803

13 Systèmes d’impression 13.6 Scenarios d’impressions possibles

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 425 / 803

Page 253: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.6 Scenarios d’impressions possibles

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 426 / 803

13 Systèmes d’impression 13.7 Mécanismes et protocoles d’impressionChapitre 13 • Systèmes d’impression§13.7 • Mécanismes et protocoles d’impression

Dans un environnement réel, les mécanismes d’impression permettent auxutilisateurs de s’affranchir :

de la connaissance des noms techniques des périphériques ;du risque d’impressions mélangées lorsque deux utilisateurs essayentd’imprimer en même temps ;des détails matériels tels que l’absence momentanée de papier ;de la nécessité d’attendre que l’impression en cours se termine ;etc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 427 / 803

Page 254: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.7 Mécanismes et protocoles d’impression

Pour résoudre tous ces problèmes, il a été conçu des spouleurs (spoolers).Le principe en est simple :

Les utilisateurs déposent leurs fichiers dans un répertoire convenu, àl’aide de la « commande d’impression ». C’est la requête d’impression.Un démon système surveille ce répertoire (file d’attente), en extraitun fichier, l’imprime, puis extrait le suivant, l’imprime, etc.Des commandes permettent aux utilisateurs de savoir ce qu’il y a dansla file d’attente et éventuellement de détruire une de leurs requêtes.Des commandes permettent à l’administrateur de gérer cemécanisme :

création d’une nouvelle file d’attente pour une nouvelle imprimante ;autorisation ou interdiction des dépôts dans des files d’attente ;autorisation ou interdiction des impressions ;redirection des travaux d’impression d’une imprimante à une autreimprimante ;etc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 428 / 803

13 Systèmes d’impression 13.8 Situation logicielle en 2007Chapitre 13 • Systèmes d’impression§13.8 • Situation logicielle en 2007

Plusieurs logiciels :mécanisme LP (SOLARIS)→ obsolètemécanisme LPR→ obsolètemécanisme LPRng (LINUX, UNIX)« http://www.lprng.com »→ a tendance à devenir obsolètemécanisme CUPS (LINUX, UNIX, Windows 2000/XP/2003,MacOSX)basé sur IPP (Internet Printing Protocol)« http://www.cups.org »→ a la côte

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 429 / 803

Page 255: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.8 Situation logicielle en 2007

Principes globaux de tous ces mécanismes :machines clientes d’un serveur d’impression

le serveur d’impression a des queues d’impression pour les diversesimprimantes

fonctionalités de gestion des queues plus ou moins élaborées selon leprotocole :

LP < LPR < LPRng < CUPS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 430 / 803

13 Systèmes d’impression 13.9 Protocole d’impression LPChapitre 13 • Systèmes d’impression§13.9 • Protocole d’impression LP

� commandes du système d’impression LP

Commande Autorisation Descriptionaccept administrateur accepte les requêtescancel utilisateur supprime une requêtedisable utilisateur désactive une imprimanteenable utilisateur active une imprimantelp utilisateur place une requête dans une filelpadmin administrateur configurationlpmove administrateur change la destination d’une requêtelpsched administrateur le démon proprement ditlpshut administrateur arrête le démonlpstat utilisateur liste la file d’attentereject administrateur refuse les requêtes

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 431 / 803

Page 256: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.9 Protocole d’impression LP

Les interactions entre les différents composants du système LP sontrésumées dans la figure suivante :

imprimante 1

lp

lpsched

flle d’attentefile d’attente

accept/reject

enable/disable

lpmove

lpstat

imprimante 3imprimante 2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 432 / 803

13 Systèmes d’impression 13.9 Protocole d’impression LP

� Destinations - Files d’attente

Les requêtes sont dirigées vers des destinations. Une destinationcorrespond à un file d’attente. Chaque file d’attente peut être associée à :

une imprimante isolée (cas le plus fréquent). C’est le cas del’imprimante 1 dans l’exemple ;un groupe d’imprimantes : c’est ce qu’on nomme une classe. Lesrequêtes sont alors envoyées indifféremment sur n’importe laquelle desimprimantes de la classe. C’est le cas des imprimantes 2 et 3 dansl’exemple.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 433 / 803

Page 257: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.9 Protocole d’impression LP

Il y a trois moyens de spécifier une destination, classés par ordre depriorité :

1 avec l’option « -d » ;2 avec la variable d’environnement « LPDEST » ;3 en ne nommant aucune destination : la destination par défaut est

alors choisie.

Lorsque l’utilisateur tape la commande « lp », la requête est mémoriséedans la file d’attente correspondant à la destination spécifiée. Lamémorisation est autorisée si le robinet contrôlant l’accès à la file estouvert. L’administrateur agit sur ce robinet avec les commandes« accept » et « reject ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 434 / 803

13 Systèmes d’impression 13.9 Protocole d’impression LP

La commande « lpstat » permet de visualiser le contenu des filesd’attentes.

La commande « cancel » permet de retirer une requête de sa filed’attente.

Les requêtes dans les files d’attente sont ensuite traitées par le démon« lpsched ». Celui-ci surveille l’état de toutes files d’attente et lesimprimantes. Lorsqu’une imprimante a fini d’imprimer, « lpsched »choisit la requête suivante dans la file, et l’envoie sur l’imprimante.

L’impression est autorisée si le robinet contrôlant l’accès à une imprimanteest ouvert. L’administrateur, ou les utilisateurs, peuvent contrôler cerobinet avec les commandes « enable » et « disable ».

Lorsqu’une destination est indisponible, l’administrateur peut rerouter unerequête ou l’ensemble des requêtes situées dans une file d’attente dans uneautre. Il faut pour cela que le démon soit arrêté.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 435 / 803

Page 258: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.9 Protocole d’impression LP

L’arrêt du démon « lpsched » est effectué par « lpshut ». De manièregénérale, toute modification sur le système d’impression doit se fairelorsque le démon est à l’arrêt. L’arrêt est brutal : les requêtes en coursd’impression sont purement et simplement stoppées. Le redémarrage dudémon provoquera à nouveau leur impression depuis le début.

Enfin, la commande « lpadmin » est la boîte à outils de l’administrateur.Elle permet de contrôler tous les constituants du système (hors robinets).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 436 / 803

13 Systèmes d’impression 13.9 Protocole d’impression LP

La commande « lp » permet de demander l’impression d’un ou deplusieurs fichiers :

lp [-d destination] [-m] [-n nombre] [-o options]

[-s] [-t titre] [-w] fichiers

Les options sont :

Option Signification-d spécifie une imprimante-m envoie un courrier lorsque l’impression est finie-n demande l’impression de plusieurs copies-o passe des options au script d’impression-s n’affiche pas l’identificateur dans la file d’attente-t imprime un titre sur la page d’en-tête-w envoie un message lorsque l’impression est finie

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 437 / 803

Page 259: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.9 Protocole d’impression LP

� Scripts d’impression

Lorsque « lpsched » lance une impression, il appelle en réalité un scriptshell appelé le script d’interface. Ce script, nommé du nom del’imprimante, a pour fonction d’imprimer la bannière et le fichier. Il reçoiten paramètres :

1 l’identificateur de la requête dans la file d’attente ;2 le nom de l’utilisateur qui a formulé la requête ;3 le titre qu’il a éventuellement indiqué ;4 le nombre de copies à imprimer ;5 les options éventuellement spécifiées par l’option « -o » de la

commande « lp » ;6 et enfin une liste de fichiers dans la file d’attente.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 438 / 803

13 Systèmes d’impression 13.9 Protocole d’impression LP

La sortie standard de ce script est redirigée sur le fichier spécialcorrespondant à l’imprimante, et la sortie d’erreur est éventuellementtransmise par courrier à l’utilisateur.

Dans le cas le plus simple, ce script génère une bannière et ne fait qu’un« cat » du fichier sur la sortie standard pour effectuer l’impression. Maisdes scripts plus évolués permettent de reconnaître automatiquement letype du fichier et l’imprimer en conséquence (PostScript, texte, etc.). Lesoptions peuvent permettre de changer de fonte, de bac papier, de taille depage, etc.

L’utilisation de tels scripts rend ce système d’impression particulièrementsouple. Si beaucoup de scripts modèles sont fournis par le constructeur, lapossibilité de les modifier et de les adapter est très importante pour utiliserpleinement les imprimantes.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 439 / 803

Page 260: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.9 Protocole d’impression LP

� Ajout d’une imprimante

Lors de l’ajout d’une imprimante, il faut :

avoir le bon cable (parallèle, série ou autre) ;créer le fichier spécial correspondant à l’interface ;rendre « lp » propriétaire du fichier spécial ;changer les droits du fichier spécial pour que personne ne puisse yaccéder autrement que par « lp » ;récapituler les paramètres de connexion (caractéristiques de laliaison) ;identifier le type de l’imprimante et choisir en conséquence un scriptmodèle s’en approchant. Les scripts modèle sont en principe dans lerépertoire : « /usr/spool/lp/model ».choisir un nom pour l’imprimante ;vérifier que le démon « lpsched » ne tourne pas et l’arrêteréventuellement avec « lpshut ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 440 / 803

13 Systèmes d’impression 13.9 Protocole d’impression LP

Une fois cela fait, la commande « lpadmin » peut être appelée pour créerl’imprimante :

# lpadmin -pnom-de-l’imprimante -mscript -vfichier-spécial

avec :l’option « -p » spécifie le nom de l’imprimante ;l’option « -m » spécifie le nom du script modèle qui sera utilisécomme script d’interface. Le script modèle doit obligatoirementrésider dans le répertoire des scripts modèles ;l’option « -v » spécifie le fichier spécial dans « /dev ».

Cette commande place le script modèle dans le répertoire des scriptsd’interface (répertoire « /usr/spool/lp/interface »).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 441 / 803

Page 261: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.9 Protocole d’impression LP

Une fois ce script installé, il est possible, par le biais de la commande« stty », de modifier les paramètres de connexion s’il s’agit d’une liaisonsérie. Par exemple :

# lpadmin -pps -mpostscript -v/dev/ps

Une fois l’imprimante créée, elle peut éventuellement devenir l’imprimantepar défaut. Pour cela, il faut exécuter :

# lpadmin -dnom-de-l’imprimante

Il faut maintenant libérer l’accès aux files d’attente et à l’imprimante. Pourcela, il faut utiliser les commandes :

# accept nom-de-l’imprimante# enable nom-de-l’imprimante

Après avoir redémarré le démon avec la commande « lpsched », vouspouvez à présent utiliser votre imprimante.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 442 / 803

13 Systèmes d’impression 13.9 Protocole d’impression LP

� Suppression d’une imprimante

Le retrait d’une imprimante est effectué par la commande :

# lpadmin -xnom-de-l’imprimante

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 443 / 803

Page 262: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.9 Protocole d’impression LP

� Gestion des classes

Une imprimante peut être directement créée dans une classe, ou peut êtreajoutée a posteriori dans une classe. Pour cela, l’option « -c » doit êtrespécifiée :

création d’une imprimante dans une classe :# lpadmin -pnom-de-l’imprimante -mscript -vfichier-spécial -cnom-de-la-classe

intégration d’une imprimante existante dans une classe :# lpadmin -pnom-de-l’imprimante -cnom-de-la-classe

Pour supprimer une classe, il suffit d’utiliser l’option « -x » comme poursupprimer une imprimante.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 444 / 803

13 Systèmes d’impression 13.10 Protocole d’impression LPDChapitre 13 • Systèmes d’impression§13.10 • Protocole d’impression LPD

� Commandes du système d’impression

Commande Autorisation Descriptionlpr utilisateur place une requête dans la filelprm utilisateur supprime une requêtelpq utilisateur liste la file d’attentelpc administrateur boîte à outilslpd administrateur le démon proprement dit

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 445 / 803

Page 263: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.10 Protocole d’impression LPD

Les interactions entre les différents composants du système d’impressionBerkeley sont résumées dans la figure suivante :

file d’attente

imprimante 1 imprimante 3

lpc enablelpc disable

lpr

lpd

file d’attente

lpq

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 446 / 803

13 Systèmes d’impression 13.10 Protocole d’impression LPD

Les requêtes sont destinées à des file d’attente. Il y a une file d’attente parimprimante, et il n’y a donc pas de possibilité de grouper des imprimantescomme dans le spouleur AT&T.

Il y a trois moyens de spécifier une file d’attente, classés par ordre depriorité :

1 avec l’option « -P » ;2 avec la variable d’environnement « PRINTER » ;3 en ne nommant aucune destination : la destination par défaut est

alors choisie.

Lorsque l’utilisateur tape la commande « lpr », la requête est mémoriséedans la file d’attente correspondant à l’imprimante spécifiée. Lamémorisation est autorisée si le robinet contrôlant l’accès à la file estouvert.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 447 / 803

Page 264: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.10 Protocole d’impression LPD

L’administrateur agit sur ce robinet avec la commande « lpc »(sous-commande « disable »).

La commande « lpq » permet de visualiser le contenu des files d’attentes.La commande « lprm » permet de retirer une requête de sa file d’attente.

Les requêtes dans la file d’attente sont ensuite traitées par le démon« lpd ». Celui-ci surveille les requêtes distantes et l’état des files et desimprimantes. Lorsqu’une imprimante a fini d’imprimer, « lpr » choisit larequête suivante dans la file, et l’envoie sur l’imprimante.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 448 / 803

13 Systèmes d’impression 13.10 Protocole d’impression LPD

Le fonctionnement du démon est très différent de celui de LP :

lpr

lpdfile d’attente lpd

imprimante 1

requêtes réseau

lpd

file d’attente

imprimante 2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 449 / 803

Page 265: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.10 Protocole d’impression LPD

Le démon « lpd » est normalement inactif, à l’écoute des requêtes venantdes programmes « lpr » locaux ou des démons « lpd » d’autres machines.

Lorsqu’un utilisateur lance la commande « lpr », « lpr » place la requêtedans la file d’attente, puis se connecte au démon « lpd » en luidemandant de surveiller la file d’attente spécifiée. Sur cette requête,« lpd » génère un sous-processus pour imprimer toutes les requêtes de lafile d’attente. Ce sous-processus ne s’arrête que lorsqu’il n’y a plus aucunerequête en attente dans la file spécifiée.

Il y a donc un sous-démon par file d’attente non vide.

Si la file d’attente n’est pas vide, mais qu’aucun démon n’est présent, onatteint le même effet que la commande « disable » avec le spouleurAT&T.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 450 / 803

13 Systèmes d’impression 13.10 Protocole d’impression LPD

La commande « lpc » est la boîte à outils de l’administrateur. Elle permetde contrôler tous les robinets du système. C’est une commande interactivequi dispose de sous-commandes. On peut également appeler directementune sous-commande (par exemple : « lpc up all »). Les différentessous-commandes sont :

Commande Effets sur...File Démon Autres

abort – arrêté démons interditsclean nettoyée – –disable désactivée – ⇒ lpr interditdown désactivée arrêté ⇒ lpr interditenable activée – ⇒ lpr autoriséexit – – termine lpc

quit – – termine lpc

restart – redémarré –start – démarré démons autorisésstatus – – affiche l’état du systèmestop – arrêté démons interditstopq – – place un processus en tête de fileup activée démarré ⇒ lpr autorisé

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 451 / 803

Page 266: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.10 Protocole d’impression LPD

� Fichier /etc/printcap

Le fichier centralisant toutes les définitions d’imprimantes est« /etc/printcap ». Ce fichier contient des champs « code=valeur ».

Par exemple :

lp|ps|postscript|PostScript:\

:lp=/dev/ps:sd=/usr/spool/lpd/ps:\

:lf=/usr/spool/lpd/ps/ps-log:\

:mx#0:sf:sb:\

:if=/usr/local/lib/psif:

L’imprimante par défaut s’appelle toujours « lp ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 452 / 803

13 Systèmes d’impression 13.10 Protocole d’impression LPD

Les options sont, dans cet exemple :

lp=/dev/ps

nom du fichier spécial ;sd=/usr/spool/lpd/ps

nom du répertoire contenant la file d’attente ;lf=/usr/spool/lpd/ps/ps-log

nom du fichier contenant les erreurs ;mx#0

pas de limitation de taille des fichiers imprimés ;sf, sbpas de bannière, pas de page de fin ;if=/usr/local/lib/psif

filtre d’impression pour les fichiers texte ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 453 / 803

Page 267: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.10 Protocole d’impression LPD

� Ajout d’une imprimante

Lors de l’ajout d’une imprimante, il faut :

avoir le bon cable (parallèle, série ou autre) ;créer le fichier spécial correspondant à l’interface ;changer les droits du fichier spécial pour que personne ne puisse yaccéder autrement que par lpr ;récapituler les paramètres de connexion ;choisir un nom pour l’imprimante ;

L’ensemble des paramètres (y compris les paramètres de connexion, s’ils’agit d’une liaison série) doivent être placés dans le fichier« /etc/printcap ».Le répertoire correspondant à la file d’attente doit être créé manuellement.Son nom doit correspondre au nom installé dans « /etc/printcap ». Lepropriétaire et le groupe doivent être « daemon ». Les droits doivent êtrelecture, écriture et exécution pour le propriétaire et le groupe, lecture etexécution pour les autres.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 454 / 803

13 Systèmes d’impression 13.10 Protocole d’impression LPD

� Impression à distance

La commande « lpr » permet également d’imprimer des fichiers sur desimprimantes distantes. Pour mettre en place une impression à distance, ilfaut placer les informations suivantes dans le fichier « /etc/printcap »sur la machine cliente :

#

# l’imprimante qui est sur cendrillon

#

lp|ps|postscript|PostScript:\

:rm=cendrillon:\

:rp=ps:\

:sd=/usr/spool/lpd/ps:

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 455 / 803

Page 268: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.10 Protocole d’impression LPD

Les options sont :

rm=cendrillon

Nom de la machine distante ;rp=ps

Nom de l’imprimante sur la machine distante ;sd=/usr/spool/lpd/ps

il faut un répertoire local, car la machine distante peut ne pas êtredisponible au moment où l’utilisateur local lance la commande« lpr ».

La machine distante, quant à elle, doit autoriser les requêtes d’impression.Ceci se fait en mettant le nom de la machine cliente dans un des fichiers :

« /etc/hosts.equiv »« /etc/hosts.lpd »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 456 / 803

13 Systèmes d’impression 13.10 Protocole d’impression LPD

� Protocole d’impression LPD par la pratique

Contexte : une imprimante réseau supportant directement le protocoleLPD. L’imprimante a le nom DNS « hp.example.com ». L’imprimantesera connue du système d’impression sous le nom de queue « hp ».

La définition de la queue d’impression LPD se fera dans le fichier« /etc/printcap » de la façon suivante :

hp:\

:lp=:\

:mx#0:\

:rp=raw:\

:rm=hp.example.com:\

:lf=/var/spool/lpd/hp/log:\

:sd=/var/spool/lpd/hp:

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 457 / 803

Page 269: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.11 Protocole d’impression LPRngChapitre 13 • Systèmes d’impression§13.11 • Protocole d’impression LPRng

LPRng = LPR New Generation

Amélioration de LPD.

Voir annexe.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 458 / 803

13 Systèmes d’impression 13.11 Protocole d’impression LPRng

� Protocole d’impression LPRNG par la pratique

Contexte : une imprimante réseau supportant directement le protocoleLPD. L’imprimante a le nom DNS « hp.example.com ». L’imprimantesera connue du système d’impression sous le nom de queue « hp ».

La définition de la queue d’impression LPRNG se fera dans le fichier« /etc/printcap » de la façon suivante :

hp:

:cm=Laserjet HP4050

:[email protected]

:sh

:mc=0

:mx=0

:ifhp=model=hp4050

:filter=/usr/libexec/filters/ifhp

:sd=/var/spool/lpd/%P

:lf=/var/spool/lpd/%P/log

:af=/var/spool/lpd/%P/acct

:server

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 459 / 803

Page 270: Administration UNIX - Cours Jussieu - 2009-2010

13 Systèmes d’impression 13.12 Protocole d’impression IPP / CUPSChapitre 13 • Systèmes d’impression§13.12 • Protocole d’impression IPP / CUPS

CUPS = Common Unix Printing System

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 460 / 803

Page 271: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 14

Monitoring de systèmes

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 461 / 803

14 Monitoring de systèmes 14.1 Logiciels de dessin de réseauxChapitre 14 • Monitoring de systèmes§14.1 • Logiciels de dessin de réseaux

Plusieurs logiciels disponibles mais incompatibles :

VISIO, disponible dans Microsoft Office sous Windows :« http://www.microsoft.com/ »

DIA, disponible sur UNIX ou Windows :« http://www.gnome.org/projects/dia/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 462 / 803

Page 272: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.1 Logiciels de dessin de réseaux

Bibliothèque de symboles CISCO dans DIA :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 463 / 803

14 Monitoring de systèmes 14.2 Logiciels de tracés de courbesChapitre 14 • Monitoring de systèmes§14.2 • Logiciels de tracés de courbes

Objectif : visualiser certains aspects système :paginationdébits réseauutilisation de jetons logicielstempératures de salles machinesetc.

Avec quel(s) outil(s) tracer les mesures réalisées ?GNUPLOTMRTGRRDTOOLetc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 464 / 803

Page 273: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.3 GNUPLOTChapitre 14 • Monitoring de systèmes§14.3 • GNUPLOT

Site « http://www.gnuplot.info »Aussi disponible sur Windows.Exemple (tracé d’une donnée en fonction du temps) :

0

50

100

150

200

250

300

350

400

450

500

200411/20

200411/21

200411/22

200411/23

200411/24

200411/25

200411/26

200411/27

200411/28

200411/29

"data" using 1:2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 465 / 803

14 Monitoring de systèmes 14.3 GNUPLOT

Gnuplot utilise un langage scriptable pour dessiner les courbes.

Exemple de données : Script :

20041120 300

20041121 320

20041122 350

20041123 295

20041124 200

20041125 230

20041126 250

20041127 300

20041128 320

20041129 330

set terminal png

set output "data.png"

set timefmt "%Y%m%d"

set xdata time

set format x "%Y\n%m/%d"

set yrange [0:500]

plot "data" using 1:2 with linespoints

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 466 / 803

Page 274: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.3 GNUPLOT

Image « data.png » obtenue par« gnuplot consommation.gnuplot » :

0

50

100

150

200

250

300

350

400

450

500

200411/20

200411/21

200411/22

200411/23

200411/24

200411/25

200411/26

200411/27

200411/28

200411/29

"data" using 1:2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 467 / 803

14 Monitoring de systèmes 14.4 MRTGChapitre 14 • Monitoring de systèmes§14.4 • MRTG

Site « http://oss.oetiker.ch/mrtg/ »

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 468 / 803

Page 275: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.4 MRTG

� Exemples

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 469 / 803

14 Monitoring de systèmes 14.5 RRDTOOLChapitre 14 • Monitoring de systèmes§14.5 • RRDTOOL

Site « http://oss.oetiker.ch/rrdtool/ »

Attention : version 2.x buggée ⇒ rester sur 1.x

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 470 / 803

Page 276: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.5 RRDTOOL

� Exemples

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 471 / 803

14 Monitoring de systèmes 14.5 RRDTOOL

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 472 / 803

Page 277: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.5 RRDTOOL

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 473 / 803

14 Monitoring de systèmes 14.5 RRDTOOL

� Principe

Fichier de données d’extension « .rrd ».RRD signifie Round Robin Database

N slotsUne fois les N slots remplis, on vire la valeur la plus vieille et on décale

DONNEES 26

DONNEES 25

DONNEES 24

DONNEES 23

DONNEES 22

DONNEES 26

DONNEES 25

DONNEES 24

DONNEES 23

DONNEES 22

DONNEES 27

DONNEES 27

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 474 / 803

Page 278: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.5 RRDTOOL

Possibilité de « consolider » des données. Par exemple :échantillonnage toutes les 5 minutesconsolidation : 1 donnée par heureconsolidation : 1 donnée par jourconsolidatoin : 1 donnée par semaine

Objectif des consolidations : obtenir des graphes sur différentes périodes detemps sans avoir à mémoriser toutes les données échantillonnées de façonà avoir un fichier de données de taille qui reste raisonnable :

graphe des N dernières heuresgraphe des N derniers joursgraphe des N dernières semainesgraphe des N derniers mois

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 475 / 803

14 Monitoring de systèmes 14.5 RRDTOOL

Initialisation du fichier « .rrd » :

A completer...

Ajout de données :

A completer...

Graphe des données :

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 476 / 803

Page 279: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.6 Logiciels de surveillanceChapitre 14 • Monitoring de systèmes§14.6 • Logiciels de surveillance

Plusieurs solutions :produits maisonlogiciels clef en mainframework permettant des adaptations maisonetc.

Dans la dernière catégorie :NAGIOSCACTIBig Brother, Big SisterHP OpenViewBMC Patroletc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 477 / 803

14 Monitoring de systèmes 14.7 NAGIOSChapitre 14 • Monitoring de systèmes§14.7 • NAGIOS

Site « http://www.nagios.org »

Principe : la « console » NAGIOS surveille des clients via des « agentslogiciels » NAGIOS :

Console

host 1 host 2

Console

host 1 host 2

Consoleindirecte

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 478 / 803

Page 280: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.7 NAGIOS

La console NAGIOS peut avoir une interface web (serveur web APACHE +scripts CGI) mais non obligatoire.

Interface web simple.

Le gros du travail :définir le réseau :

liste des définitions des machinesliste des définitions des services à surveiller sur les machines

installer les agents NAGIOS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 479 / 803

14 Monitoring de systèmes 14.7 NAGIOS

� Exemples

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 480 / 803

Page 281: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.7 NAGIOS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 481 / 803

14 Monitoring de systèmes 14.7 NAGIOS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 482 / 803

Page 282: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.7 NAGIOS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 483 / 803

14 Monitoring de systèmes 14.7 NAGIOS

� Objets NAGIOS

hosthostgroupserviceservicegroupcontactcontactgrouptimeperiodcommandservicedependency (dépendance entre services)servicescalationhostdependency (dépendance entre machines)hostescalationhostextinfo (extended host information : icône, URL)serviceextinfo (extended service information : icône, URL)

Il est possible d’avoir des squelettes pour faciliter les définitions des objetsen regroupant dans un squelette des caractéristiques communes.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 484 / 803

Page 283: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.7 NAGIOS

� Définition d’un template

Cas d’un objet host :

define host{

name generic-host ; Name of templateregister 0 ; DON’T REGISTER

; IT IS JUST A TEMPLATE

notifications_enabled 1 ; Host notifications are enabled

event_handler_enabled 1 ; Host event handler is enabled

flap_detection_enabled 1 ; Flap detection is enabled

failure_prediction_enabled 1 ; Failure prediction is enabled

process_perf_data 1 ; Process performance data

retain_status_information 1 ; Retain status information across program restarts

retain_nonstatus_information 1 ; Retain non-status information across program restarts

notification_period 24x7 ; Send host notifications at any time

}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 485 / 803

14 Monitoring de systèmes 14.7 NAGIOS

Possibilité de template imbriqué :

define host {

name server ; Name of templateuse generic-host ; Inherits from generic-hostregister 0 ; DON’T REGISTER

; IT IS JUST A TEMPLATE

check_period 24x7 ; By default, Linux hosts are checked round the clock

max_check_attempts 10 ; Check each Linux host 10 times (max)

check_command check-host-alive ; Default command to check Linux hosts

notification_period workhours

notification_interval 120 ; Resend notification every 2 hours

notification_options d,u,r ; Only send notifications for specific host states

contact_groups admins ; Notifications get sent to the admins by default

}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 486 / 803

Page 284: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.7 NAGIOS

� Définition d’un host (machine)

define host{

use server

host_name mail.example.com

alias smtp.example.com

address mail.example.com

}

Etats d’un host :« OK »« DOWN »« UNREACHABLE »« RECOVERING »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 487 / 803

14 Monitoring de systèmes 14.7 NAGIOS

� Définition d’un service

define service {

use local-servicehost_name mail.example.com

service_description SSH

check_command check_ssh

}

define service {

use local-servicehost_name mail.example.com

service_description CAMCONTROL

check_command check_nrpe!check_camcontrol_da0

}

Etats d’un service :« OK »« WARNING »« CRITICAL »« UNKNOWN »« RECOVERING »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 488 / 803

Page 285: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.7 NAGIOS

� Définition d’une commande

Un service NAGIOS fait appel à une commande NAGIOS.Commande NAGIOS = plugin NAGIOS = agent NAGIOSNombreuses commandes fournies.

define command {

command_name check_ssh

command_line $USER1$/check_ssh -H $HOSTADDRESS$

}

define command {

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

Facile d’ajouter ses commandes :

define command {

command_name check-netapp-globalstatusmsg

command_line $USER1$/check_snmp -H $HOSTADDRESS$ -C public -o

.1.3.6.1.4.1.789.1.2.2.25.0

}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 489 / 803

14 Monitoring de systèmes 14.7 NAGIOS

Plusieurs protocoles de communication entre NAGIOS et ses plugins.

check_xyz(plugin)

check_by_ssh(plugin)

check_nrpe(plugin)

externalcommand

file

service sshd(daemon)

nrpe(daemon)

snmpd(daemon)

send_nsca(client)

check_snmp(plugin)

NSCA(daemon)

check_xyz(plugin)

check_xyz(plugin)

result ofservice check

client client client client client

NAGIOS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 490 / 803

Page 286: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.7 NAGIOS

NRPE :NAGIOS Remote Plugin Executorport TCP 5666monitoring actif : NAGIOS est à l’initiative des tests

NSCA :NAGIOS Service Check Acceptormonitoring passif ; NAGIOS reçoit des résultats de tests dont il n’estpas l’initiateur

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 491 / 803

14 Monitoring de systèmes 14.7 NAGIOS

Il est facile d’écrire un plugin :

#!/bin/sh

if [ ... ]

then

# condition OK

echo "OK - blabla"

exit 0

fi

if [ ... ]

then

# condition WARNING

echo "WARNING - blabla"

exit 1

fi

if [ ... ]

then

# condition ERROR

echo "CRITICAL - blabla"

exit 1

fi

if [ ... ]

then

# condition UNKNOWN

echo "UNKNOWN - blabla"

exit 3

fi

N’importe quel langage de programmation peut convenir.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 492 / 803

Page 287: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.7 NAGIOS

� Définition d’un contact

define contact{

contact_name nagios-adminalias Nagios Admin

service_notification_period 24x7

host_notification_period 24x7

service_notification_options w,u,c,r

host_notification_options d,r

service_notification_commands notify-by-email

host_notification_commands host-notify-by-email

email [email protected]}

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 493 / 803

14 Monitoring de systèmes 14.7 NAGIOS

� Notification via email

From [email protected] Fri Aug 3 12:10:16 2007

Date: Fri, 3 Aug 2007 12:10:02 +0200 (CEST)

From: [email protected]

To: [email protected]

Subject: ::NAGIOS:: ** PROBLEM alert - mail.example.com/CAMCONTROL is CRITICAL **

***** Nagios 2.6 *****

Notification Type: PROBLEM

Service: CAMCONTROLHost: mail.example.com

Address: mail.example.com

State: CRITICAL

Date/Time: Fri Aug 3 12:10:02 CEST 2007

Additional Info:

CAMCONTROL ALERT - 2007-08-03 12:09:28 da0 [COMPAQ RAID 1 VOLUME reco]

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 494 / 803

Page 288: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.7 NAGIOS

� Notification via email (suite)

From [email protected] Fri Aug 3 12:24:47 2007

Date: Fri, 3 Aug 2007 12:25:02 +0200 (CEST)

From: [email protected]

To: [email protected]

Subject: ::NAGIOS:: ** RECOVERY alert - mail.example.com/CAMCONTROL is OK **

***** Nagios 2.6 *****

Notification Type: RECOVERY

Service: CAMCONTROLHost: mail.example.com

Address: mail.example.com

State: OK

Date/Time: Fri Aug 3 12:25:02 CEST 2007

Additional Info:

CAMCONTROL OK - 2007-08-03 12:24:28 da0 [COMPAQ RAID 1 VOLUME OK]

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 495 / 803

14 Monitoring de systèmes 14.8 NAGIOS + OREONChapitre 14 • Monitoring de systèmes§14.8 • NAGIOS + OREON

L’interface de NAGIOS n’est pas très pratique.

Possibilité d’offrir une autre interface web : OREON

Site « http://www.oreon.org »

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 496 / 803

Page 289: Administration UNIX - Cours Jussieu - 2009-2010

14 Monitoring de systèmes 14.9 CACTIChapitre 14 • Monitoring de systèmes§14.9 • CACTI

Site « http://www.cacti.net »

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 497 / 803

14 Monitoring de systèmes 14.9 CACTI

� Exemples

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 498 / 803

Page 290: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 15

Mécanisme d’authentification réseau :/etc/passwd

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 499 / 803

15 Mécanisme d’authentification réseau : /etc/passwd 15.1 IntroductionChapitre 15 • Mécanisme d’authentification réseau : /etc/passwd§15.1 • Introduction

Voir dans le volume 2 la partie sur « /etc/passwd » et « /etc/shadow ».

Problématique : comment gérer un réseau de machines qui n’utiliserontque les fichiers « /etc/passwd » et « /etc/shadow » ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 500 / 803

Page 291: Administration UNIX - Cours Jussieu - 2009-2010

15 Mécanisme d’authentification réseau : /etc/passwd 15.2 Principe d’une solutionChapitre 15 • Mécanisme d’authentification réseau : /etc/passwd§15.2 • Principe d’une solution

Une solution :recopier depuis une machine A sur les autres machines les fichiers« /etc/passwd » et « /etc/shadow »recopie sur les autres machines via SCP (voir SSH)recopie périodique via CRONTABn’autoriser les changements de mot de passe que sur la machine A

Quels sont les inconvénients de cette méthode ?

Quels sont les avantages de cette méthode ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 501 / 803

Page 292: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 16

Mécanisme d’authentification réseau : NIS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 502 / 803

16 Mécanisme d’authentification réseau : NIS 16.1 IntroductionChapitre 16 • Mécanisme d’authentification réseau : NIS§16.1 • Introduction

NIS ≡ Network Information Service

Créé par SUN en 1985Anciennement Yellow Pages ⇒ certaines commandes ont un nom en« yp. . . »Version NIS+ vers 1992, radicalement différente (cf annexe)

C’est un protocole réseau d’accès à des informations centralisées sur un ouplusieurs serveurs redondants.

Utilisation la plus courante : partager la base des comptes UNIX.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 503 / 803

Page 293: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.2 Architecture de NISChapitre 16 • Mécanisme d’authentification réseau : NIS§16.2 • Architecture de NIS

Architecture construite en mode client / serveur :

Client 1 Client 2 Client 3 Client 4

DATA

DATA

DATA

DATA

DATA

DATA

DATA

DATA

Maitre

Esclave 1 Esclave 2

Mise a jour push / pull

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 504 / 803

16 Mécanisme d’authentification réseau : NIS 16.2 Architecture de NIS

Caractéristiques :

Communications réseau via RPC (Remote Procedure Call)Propagation des données (maps) du serveur maitre aux serveursesclaves en mode pull ou en mode push.Propagation des maps complètesSeul le serveur maitre peut modifier les donnéesLes serveurs esclaves diffusent les données sans pouvoir les modifier

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 505 / 803

Page 294: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.3 Données NIS : maps NIS, DBM, ypcat, ypmatchChapitre 16 • Mécanisme d’authentification réseau : NIS§16.3 • Données NIS : maps NIS, DBM, ypcat, ypmatch

Les données manipulées par NIS : mapsLes maps contiennent des couples (clef, valeur).

Il n’y a que le serveur NIS maître qui peut changer le contenu d’une map.

Une map est au format DBM (cf « man dbm ») ; une map se compose de3 fichiers :

le fichier sourcele fichier de suffixe « .pag »le fichier de suffixe « .dir »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 506 / 803

16 Mécanisme d’authentification réseau : NIS 16.3 Données NIS : maps NIS, DBM, ypcat, ypmatch

La commande « makedbm » permet de convertir le fichier source en les 2fichiers constituant le DBM.

% cat democlef1 banane

clef2 arbre

% makedbm demo demo% ls -l demo-rw-r--r-- 1 besancon adm 23 Aug 15 11:56 demo

-rw------- 1 besancon adm 0 Aug 15 11:57 demo.dir

-rw------- 1 besancon adm 1024 Aug 15 11:57 demo.pag

Dans le système NIS, les maps sont stockées sur le serveur maitre dans« /var/yp/nom-du-domaine-NIS » :

% cd /var/yp/nom-de-domaine-NIS% ls -l passwd*-rw------- 1 root other 4096 Nov 23 07:26 passwd.byname.dir

-rw------- 1 root other 8192 Nov 23 07:26 passwd.byname.pag

-rw------- 1 root other 4096 Nov 23 07:26 passwd.byuid.dir

-rw------- 1 root other 8192 Nov 23 07:26 passwd.byuid.pag

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 507 / 803

Page 295: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.3 Données NIS : maps NIS, DBM, ypcat, ypmatch

Les maps sont construites automatiquement à partir de tous les fichierssources des maps :

/etc/hosts

/etc/passwd

makedbm

passwd.byname

passwd.byuid

hosts.byname

hosts.byuid

NISMASTER

Le fichier « /var/yp/Makefile » automatise toutes les créations demaps et leur propagation aux serveurs esclaves (mode push).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 508 / 803

16 Mécanisme d’authentification réseau : NIS 16.3 Données NIS : maps NIS, DBM, ypcat, ypmatch

Extrait de « /var/yp/Makefile » :

...

hosts.time: $(DIR)/hosts

@($(MULTI) $(B) -l $(DIR)/hosts);

@($(STDHOSTS) $(DIR)/hosts $(CHKPIPE))| \

(awk ’BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$1, $$0 }’ $(CHKPIPE)) | \

$(MAKEDBM) $(B) - $(YPDBDIR)/$(DOM)/hosts.byaddr;

@touch hosts.time;

@echo "updated hosts";

@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOM) hosts.byname; fi

@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOM) hosts.byaddr; fi

@if [ ! $(NOPUSH) ]; then echo "pushed hosts"; fi

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 509 / 803

Page 296: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.3 Données NIS : maps NIS, DBM, ypcat, ypmatch

La construction d’une map se résume alors à (par exemple suite à unemodification de /etc/hosts) :

# vi /etc/hosts# cd /var/yp# make hostsupdated hosts

pushed hosts

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 510 / 803

16 Mécanisme d’authentification réseau : NIS 16.3 Données NIS : maps NIS, DBM, ypcat, ypmatch

La librairie DBM permet de créer des enregistrements de taille maximale1024 octets :

% man dbm

SunOS/BSD Compatibility Library Functions dbm(3B)

NAME

dbm, dbminit, dbmclose, fetch, store, delete, firstkey,

nextkey - data base subroutines

...

The sum of the sizes of a key/content pair must not exceed

the internal block size (currently 1024 bytes). Moreover

all key/content pairs that hash together must fit on a sin-

gle block. store will return an error in the event that a

disk block fills with inseparable data.

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 511 / 803

Page 297: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.3 Données NIS : maps NIS, DBM, ypcat, ypmatch

Quelques noms de maps :

passwd.byname, passwd.byuid, group.byname, group.bygid, publickey.byname,hosts.byaddr, hosts.byname, mail.byaddr, mail.aliases, services.byname,services.byservicename, rpc.bynumber, rpc.byname, protocols.bynumber,protocols.byname, networks.byaddr, networks.byname, netmasks.bymask,netmasks.byaddr, ethers.byname, ethers.byaddr, bootparams, auto.master,auto.home, auto.direct, auto.src

dont les plus utiles sont :

map « passwd »map « group »map « hosts »map « netgroup »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 512 / 803

16 Mécanisme d’authentification réseau : NIS 16.3 Données NIS : maps NIS, DBM, ypcat, ypmatch

La commande « ypcat » permet de consulter une map NIS depuisn’importe quel client.

Syntaxe : « ypcat map-NIS »

La commande « ypmatch » permet de consulter la valeur d’une ouplusieurs clefs dans une certaine map NIS depuis n’importe quel client.

Syntaxe : « ypmatch clef1 clef2... map-NIS »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 513 / 803

Page 298: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.4 Client NIS, domainname, ypbind, ypwhich, ypsetChapitre 16 • Mécanisme d’authentification réseau : NIS§16.4 • Client NIS, domainname, ypbind, ypwhich, ypset

Un client NIS doit se connecter à un serveur NIS. C’est l’action de binding.Le binding nécessite :

de fournir un nom de domaine NIS, le domainname ;une machine se déclare comme membre du groupe servi par lesserveurs NISde préciser la méthode de localisation du serveur NIS : broadcast ouexplicite

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 514 / 803

16 Mécanisme d’authentification réseau : NIS 16.4 Client NIS, domainname, ypbind, ypwhich, ypset

� Nom de domaine

La commande activant le nom de domaine est domainname.

Pour consulter le nom de domaine :« domainname »

Pour configurer manuellement le nom de domaine :« domainname nom-du-domaine-NIS »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 515 / 803

Page 299: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.4 Client NIS, domainname, ypbind, ypwhich, ypset

Configuration du domainname automatique au démarrage :Sur Solaris : renseigner le fichier « /etc/defaultdomain »Sur Linux : renseigner le variable « NISDOMAIN » du fichier« /etc/sysconfig/network »NETWORKING=yes

FORWARD_IPV4=false

HOSTNAME=pcars6.formation.jussieu.fr

DOMAINNAME=formation.jussieu.fr

GATEWAY=134.157.253.126

GATEWAYDEV=eth0

NISDOMAIN=real.world

ATTENTION : sur LINUX, ne pas confondre avec la variable« DOMAINNAME »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 516 / 803

16 Mécanisme d’authentification réseau : NIS 16.4 Client NIS, domainname, ypbind, ypwhich, ypset

� Réalisation du binding

Un client NIS fait tourner le démon « ypbind » qui se connecte à unserveur NIS que l’on trouve selon 2 méthodes possibles :

découverte par broadcast ; c’est le mode par défaut.Sur Solaris, « /usr/lib/netsvc/yp/ypbind -broadcast »En pratique il y a une map « ypservers » qui contient les noms desserveurs.Cf « /var/yp/binding/nom-de-domaine-NIS/ypservers »demande de connexion expliciteSur Solaris faire :# ypbind -ypsetme

# ypset nom-du-serveur-NIS-voulu

La commande « ypwhich » affiche le nom du serveur NIS utilisé.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 517 / 803

Page 300: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.4 Client NIS, domainname, ypbind, ypwhich, ypset

On peut controler un peu quels sont les clients qui se bindent aux servers.Pour cela, remplir sur les serveurs esclaves et sur le serveur maitre lefichier « /var/yp/securenets ». Il liste les machines autorisées, sousforme adresses et netmasks.

Par exemple :

159.169.0.0 255.255.0.0

129.187.135.0 255.255.255.0

Signification : seules les machines des réseaux « 159.169.0.0/16 » et« 129.187.135.0/24 » sont autorisées à se binder.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 518 / 803

16 Mécanisme d’authentification réseau : NIS 16.4 Client NIS, domainname, ypbind, ypwhich, ypset

� Consultation des maps

Un client NIS doit indiquer quels maps il utilisera. La plus courante est lamap « passwd » dont on indique l’utilisation par l’ajout d’une ligne en finde fichier « /etc/passwd » :

+::65534:65534:::

Signification de cette ligne supplémentaire (à vérifier sur chaque systèmecar il existe des différences) :

Tout champ renseigné de cette ligne + remplace le même champde la map inconditionnellement sauf pour UID et GID.Pour UID et GID, les valeurs mentionnées s’activeront si ceschamps sont absents de la map (c’est-à-dire quand la map estvérolée ce qui indique un problème de fichier source vérolé).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 519 / 803

Page 301: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.4 Client NIS, domainname, ypbind, ypwhich, ypset

Exemple :

+:*LK*:65534:65534:::/usr/local/bin/tcsh

Signification :le passwd chiffré des utilisateurs de la map passwd est « *LK* »l’UID sera 65534 si l’entrée de la map ne précise pas d’UIDle GID sera 65534 si l’entrée de la map ne précise pas de GIDle shell de login est mis automatiquement à« /usr/local/bin/tcsh »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 520 / 803

16 Mécanisme d’authentification réseau : NIS 16.5 Slave server NIS, ypserv, ypxfrChapitre 16 • Mécanisme d’authentification réseau : NIS§16.5 • Slave server NIS, ypserv, ypxfr

Un serveur NIS esclave fait tourner plusieurs démons :

ypservypbind

Le démon « ypserv » est là pour répondre aux requêtes des client NIS quise sont bindés sur lui.

Le démon « ypbind » n’est là que pour faire du serveur esclave un clientNIS aussi (mais ce n’est pas obligatoire).Il n’est pas garanti que le serveur esclave soit client NIS de lui même. Ilpeut se binder sur un autre serveur NIS du même domaine.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 521 / 803

Page 302: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.5 Slave server NIS, ypserv, ypxfr

Un serveur esclave peut être down au moment où le serveur maitre fait unpush des maps.⇒ besoin pour le serveur esclave de se resynchroniser avec le serveurmaitre ;pull des maps de la part du serveur esclave

Cela se fait au moyen de shell scripts lancés périodiquement via la crontab :

30 * * * * /usr/lib/netsvc/yp/ypxfr_1perhour

31 1,13 * * * /usr/lib/netsvc/yp/ypxfr_2perday

32 1 * * * /usr/lib/netsvc/yp/ypxfr_1perday

Ces scripts récupérent plus ou moins de maps suivant la fréquence de leurlancement.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 522 / 803

16 Mécanisme d’authentification réseau : NIS 16.5 Slave server NIS, ypserv, ypxfr

Exemple de l’un de ces shell scripts, « ypxfr_1perhour » :

#! /bin/sh

# ypxfr_1perhour.sh - Do hourly NIS map check/updates

PATH=/bin:/usr/bin:/usr/lib/netsvc/yp:$PATH

export PATH

ypxfr passwd.byname

ypxfr passwd.byuid

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 523 / 803

Page 303: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.6 Master server NIS, ypxfrd, rpc.yppasswdd, yppasswdChapitre 16 • Mécanisme d’authentification réseau : NIS§16.6 • Master server NIS, ypxfrd, rpc.yppasswdd, yppasswd

Un serveur NIS maître fait tourner plusieurs démons :

ypservypbindypxfrdrpc.yppasswdd

Même rôle pour « ypserv » que pour un serveur esclave.Même rôle pour « ypbind » que pour un serveur esclave.

Le démon « ypxfrd » assure les transferts de maps demandés par lesserveurs esclaves (mode pull). (en UNIX, on rencontre souvent le mot xfr pour

transfert)

Le démon « rpc.yppasswdd » assure le changement des mots de passe.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 524 / 803

16 Mécanisme d’authentification réseau : NIS 16.6 Master server NIS, ypxfrd, rpc.yppasswdd, yppasswd

Avec NIS, un client NIS ne peut pas modifier le contenu d’une map.Pour changer un mot de passe, on va émuler le changement du mot depasse sur le serveur maitre dans son fichier source (« /etc/passwd »)puis la reconstruction de la map passwd et sa transmission en totalité auxserveurs esclaves.

Ce processus se réalise en utilisant la commande « yppasswd » quidemande les mots de passe à l’utilisateur puis appelle « rpc.yppasswdd »sur le serveur maitre qui simule la session interactive composée descommandes :

# passwd# cd /var/yp# make passwd

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 525 / 803

Page 304: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.6 Master server NIS, ypxfrd, rpc.yppasswdd, yppasswd

Sur un client NIS Linux :

% yppasswdChanging NIS account information for besancon on linux.unixiens.org.

Please enter old password: ********Changing NIS password for besancon on linux.unixiens.org.

Please enter new password: ********Please retype new password: ********

The NIS password has been changed on linux.unixiens.org.

Sur un serveur maitre NIS Solaris :

% yppasswdEnter login(NIS) password: ********New password: ********Re-enter new password: ********NIS passwd/attributes changed on linux.unixiens.org

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 526 / 803

16 Mécanisme d’authentification réseau : NIS 16.7 NetgroupsChapitre 16 • Mécanisme d’authentification réseau : NIS§16.7 • Netgroups

« /etc/netgroups »

Le système NIS permet de définir des groupes d’autorisation d’accès : lesnetgroups. Ces groupes sont diffusés via la map netgroup.

Un netgroup est un nom symbolique associé à un ensemble de triplets (jen’ai jamais vu le troisième champ avoir une quelconque utilité enpratique) :

nom-de-netgroup \

(machine, utilisateur, nom-de-domaine-NIS) \

(machine, utilisateur, nom-de-domaine-NIS) \

...

On définit en pratique des netgroups concernant des machines et desnetgroups concernant des utilisateurs. On autorisera ainsi ou pas desgroupes d’utilisateurs ou de machines à accéder à certaines ressources.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 527 / 803

Page 305: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.7 Netgroups

Exemple de netgroup de machines :

nains \

(atchoum.example.com,,mine-de-diamants) \

(dormeur.example.com,,mine-de-diamants) \

(joyeux.example.com,,mine-de-diamants) \

(grincheux.example.com,,mine-de-diamants) \

(prof.example.com,,mine-de-diamants) \

(timide.example.com,,mine-de-diamants) \

(simplet.example.com,,mine-de-diamants)

Exemple de netgroup d’utilisateurs :

etudiants \

(,jean,) \

(,pierre,) \

(,valerie,)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 528 / 803

16 Mécanisme d’authentification réseau : NIS 16.7 Netgroups

Exemple d’utilisation d’un netgroup d’utilisateurs au niveau de« /etc/passwd » :

field:PASSWORD HERE:0:1:Field Service:/usr/field:/bin/csh

operator:PASSWORD HERE:5:28:Operator:/opr:/opr/opser

sys:PASSWORD HERE:2:3:Mr Kernel:/usr/sys:

bin:PASSWORD HERE:3:4:Mr Binary:/bin:

pot:*:16:16:MenuPot:/users/staffs/pot:

-@etudiants:

+@net_administrateurs::0:0:::

+@net_utilisateurs::65534:65534:::/bin/noshell

Signification :On rejette les lignes de la map « passwd » dont le login est indiquédans le netgroup « etudiants »On accepte les lignes de la map « passwd » dont le login est indiquédans le netgroup « net_administrateurs »On accepte les lignes de la map « passwd » dont le login est indiquédans le netgroup « net_utilisateurs »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 529 / 803

Page 306: Administration UNIX - Cours Jussieu - 2009-2010

16 Mécanisme d’authentification réseau : NIS 16.7 Netgroups

Exemple d’utilisation d’un netgroup de machines au niveau de l’exportationde disques via NFS (fichier « /etc/exports, cf chapitre sur NFS) :

/usr/openwin -access=nains

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 530 / 803

16 Mécanisme d’authentification réseau : NIS 16.8 Installation de NISChapitre 16 • Mécanisme d’authentification réseau : NIS§16.8 • Installation de NIS

� Master server

Lancer « ypinit -m »

� Slave servers

Lancer « ypinit -s serveur-maitre »Ajouter dans la crontab les appels aux scripts « ypxfr_* »

� Client NIS

Spécifier le domainname

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 531 / 803

Page 307: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 17

Mécanisme d’authentification réseau :NIS+

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 532 / 803

17 Mécanisme d’authentification réseau : NIS+ 17.1 Introduction / ConclusionChapitre 17 • Mécanisme d’authentification réseau : NIS+§17.1 • Introduction / Conclusion

Cf annexe pour un document sur NIS+.

Nous n’évoquerons ici que les défauts de NIS ayant conduit à l’apparitionde son successeur, NIS+.

Le système NIS+ n’a pas connu de succès et il est maintenantofficiellement abandonné au profit de LDAP par son principal défenseur,SUN.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 533 / 803

Page 308: Administration UNIX - Cours Jussieu - 2009-2010

17 Mécanisme d’authentification réseau : NIS+ 17.1 Introduction / Conclusion

Principaux reproches à NIS :

pas d’authentification du client aux serveurs NIS ; connaitre ledomainname suffit à se binder

les maps sont transmises en totalité même en cas de faiblemodification de leurs contenus

inadaption du principe du domaine NIS dans le cas de structures WAN

mode broadcast

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 534 / 803

17 Mécanisme d’authentification réseau : NIS+ 17.2 Annexe 1Chapitre 17 • Mécanisme d’authentification réseau : NIS+§17.2 • Annexe 1

Ci joint dans la version imprimée de ce cours, un document sur NIS+.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 535 / 803

Page 309: Administration UNIX - Cours Jussieu - 2009-2010

A White Paper

Solaris ONCNetwork Information Service Plus (NIS+)

Page 310: Administration UNIX - Cours Jussieu - 2009-2010

1991 by Sun Microsystems, Inc.—Printed in USA.2550 Garcia Avenue, Mountain View, California 94043-1100

All rights reserved. No part of this work covered by copyright may be reproduced in anyform or by any means—graphic, electronic or mechanical, including photocopying,recording, taping, or storage in an information retrieval system— without prior writtenpermission of the copyright owner.

Portions of this paper were previously published in the proceedings of Sun User Group,United Kingdom (SUG UK), 1991.

The OPEN LOOK and the Sun Graphical User Interfaces were developed by SunMicrosystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts ofXerox in researching and developing the concept of visual or graphical user interfaces forthe computer industry. Sun holds a non-exclusive license from Xerox to the XeroxGraphical User Interface, which license also covers Sun’s licensees.

RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the government issubject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Dataand Computer Software clause at DFARS 252.227-7013 (October 1988) and FAR 52.227-19(June 1987).

The product described in this manual may be protected by one or more U.S. patents,foreign patents, and/or pending applications.

TRADEMARKS

Sun Microsystems, the Sun Logo, NFS, NeWS and SunLink are registered trademarks, andSun, SunSoft, the SunSoft Logo, Solaris, SunOS, AnswerBook, Catalyst, CDWare, Copilot,DeskSet, Link Manager, Online: DiskSuite, ONC, OpenWindows, SHIELD, SunView,ToolTalk and XView are trademarks of Sun Microsystems, Inc., licensed to SunSoft, Inc., aSun Microsystems company. SPARC is a registered trademark of SPARC International,Inc. SPARCstation is a trademark of SPARC International, Inc., licensed exclusively to SunMicrosystems, Inc. Products bearing SPARC trademarks are based upon an architecturedeveloped by Sun Microsystems, Inc. UNIX and OPEN LOOK are registered trademarksof UNIX System Laboratories, Inc. X Window System is a product of the MassachusettsInstitute of Technology.

All other products referred to in this document are identified by the trademarks of thecompanies who market those products.

ii SunSoft

Page 311: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) iii

Table of Contents

Executive Summary 1

Introduction 1

NIS+ Overview 2

NIS+ Features 5

Who Benefits? 6

NIS+ Architecture 7

Implementation of NIS+ Service 15

Glossary of Terms 20

Page 312: Administration UNIX - Cours Jussieu - 2009-2010

iv SunSoft

Page 313: Administration UNIX - Cours Jussieu - 2009-2010

11

Network Information Service Plus (NIS+)

Chuck McManis, Saqib Jang

Executive Summary

The enormous growth in network computing over the past few years presentssignificant challenges for distributed system administrators, end users, andapplication developers. Distributed networks have become larger, typicallyconsisting of interconnected subnetworks spanning multiple sites.Management of these networks, with tasks such as addition, relocation, andremoval of network resources, including hosts, applications, and printers, hastaken on added complexity. The growth in size of distributed systems presentscomplex requirements for applications and end users to transparently accessresources across a network.

To a large extent, such challenges can be addressed through the deployment ofa robust, high-performance, network-accessible repository of distributedsystem resources commonly called an enterprise naming service.

This paper provides an architectural overview of SunSoft’s™ NetworkInformation Service Plus (NIS+), an enterprise naming service forheterogeneous distributed systems.

Introduction

NIS+ replaces ONC™ Network Information Service (NIS) and is designed toaddress the management and resource location requirements for heterogeneousdistributed systems of the 90s. It is a repository of user-friendly names andattributes of network resources such as hosts, applications, users, andmailboxes. Clients of NIS+, both applications and users, can efficiently look upinformation on network resources and access these resources in a location-independent way. NIS+ also plays a critical role in the efficient operation andadministration of distributed systems by acting as a central point for addition,removal, or relocation of resources.

Page 314: Administration UNIX - Cours Jussieu - 2009-2010

2 SunSoft2 SunSoft

The NIS+ naming service was designed to address the following goals:

• To prevent unauthorized access to network resources and act as the platformfor distributed system security.

• To scale effectively from very small to very large networks, consisting oftens of thousands of systems.

• To provide the ability to easily administer from very small to largenetworks, spanning multiple sites.

• To provide for autonomous administration of subnetworks.• To provide highly consistent information.

NIS+ Overview

NIS+ works with the ONC distributed computing platform, which is anintegral part of the Solaris™ environment. Solaris 2.0 is comprised ofSunOS™ 5.0, enhanced ONC, NIS+, OpenWindows™ V3, DeskSet™ V3, andOPEN LOOK®. A network computing standard that enables Solaris-basedsystems to connect to any other proprietary or standard system, ONC permitsusers to access information throughout the network and make use of all thecomputing power in the user organization, regardless of location. ONC issupported on all major hardware platforms, from PCs to mainframes. With aninstalled base of over 1.3 million systems, ONC is unrivalled as the industrystandard for distributed computing in heterogeneous networks.

NIS+ is a client/server application built atop the ONC Transport-IndependentRemote Procedure Call (TI-RPC) interface. RPC applications are also clients ofthe NIS+ name service. Since the RPC client and server components of anapplication may be located on arbitrary machines in a large network, RPCclients use the name service to locate and bind to RPC servers in a flexible andhigh-performance way.

NIS+ Enhancements

NIS+ includes enhancements which fall into three general categories: thestructure of the global namespace1, the structure of data within maps, and theauthentication and authorization models associated with the namespace andthe data that it contains.

1. Refer to Glossary of Terms at the end of this paper for definition of namespace and other terms.

Page 315: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 3Network Information Service Plus (NIS+) 3

First, NIS+ includes support for hierarchical domain names, which is a bettermodel for a namespace of many smaller domains. This model has been verysuccessfully used by the Domain Name System that is currently deployed onthe Internet and brings other benefits to the system as well. The mostimportant benefit is that hierarchical domains provide a structure upon whichto hang a distributed authority mechanism. Other advantages of hierarchicalnames are that given some basic information, there are well-knownmechanisms for locating nodes within a tree, and a mechanism for generatingglobally unique names that can be based on using the domain name as part ofthe name.

Secondly, NIS+ includes a new database model, which consists of two parts.The first part is a record containing the schema for the database that is storedin the namespace. The second part is the database itself, which is managed bythe same server that serves the portion of the namespace where the schemarecord was found. To keep the databases simple and the representation of theschema manageable, only two properties of the database were chosen to bepart of the schema. These properties are the number of columns in a database,and an indication for each column as to whether or not it should be used asone of the indexes for the database records. Additionally, for columns thatwere determined to be searchable, a flag is present to specify whether or notthe case of the characters should be considered when searching the databasewith this index. Using this model, NIS dbm databases are described as two-column databases, with the first column searchable and case sensitive. Figure 1shows a graphical representation of how these hierarchical domains anddatabases, called tables, are related in a global namespace.

Page 316: Administration UNIX - Cours Jussieu - 2009-2010

4 SunSoft4 SunSoft

Figure 1 Graphical Representation of the New NIS+ Namespace

Thirdly, there are two classes of changes that have been made to the NISauthentication and authorization model. One is the ability to authenticateaccess to the service and thus discriminate between accesses that are allowed tomembers of the community versus other network entities. The other is anauthorization model to allow specific rights to be granted or denied based onthis authentication. Authentication is provided by mechanisms available to allusers of ONC RPC. This allows the server to ensure the identity of principalsmaking requests and clients to ensure the identity of the server answering therequest. A second change is the need for the information to have anauthorization model associated with it. This is accomplished by using anauthorization model similar to the UNIX® file system model. This modelspecifies that each item in the namespace has a set of access rights associatedwith it, and that these rights are granted to three broad classes of principals:the owner of the item, a group owner of the item, and all other principals.The specific access rights are different than the traditional read, write, andexecute rights that the file system grants owing to the nature of information

ReplicaServer

MasterServer

ReplicaServer

ReplicaServer

Table

Table

Number of Columns : nSearchable Column : 0,1Case Sensitive Columns : 0

Col 0 Col 1 Col 2 Col n...

Page 317: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 5Network Information Service Plus (NIS+) 5

services. Also, it is useful to include a class of clients which are notauthenticated, the “nobody” principal. The authentication and authorizationmechanisms incur a finite performance penalty when they are in effect. Byallowing the client to specify access rights to unauthenticated principals, weallow them to choose better performance at the cost of weaker security. Finally,access rights to individual rows and columns within the database are alsoprovided. This provides a desirable property, that we can maintain the privacyof particular fields in a record, such as the encrypted password, while stillgiving unrestricted access to the other fields of database records.

NIS+ Features

The highlights of the NIS+ naming service’s capabilities are:

• Support of hierarchical namespace enables simplified distributedmanagement. The namespace can be divided into domains with eachdomain managed on an autonomous basis.

• Comprehensive and flexible security mechanisms prevent unauthorizedaccess to network resources. Authentication facilities allow verification of aclient’s identity, while authorization is provided to ensure the client hasrights to perform desired name service operation.

• Partitioning of name service information provides improved scalability. Theunit of partitioning is the directory which contains object information foreach namespace domain.

• Replication, on a per-directory basis, allows high availability/reliability.Each domain has a master directory to which all updates are applied and anumber of slave replicated directories. Fast consistency between directoryreplicas enables support of rapidly changing network environments.

• Complete and consistent suite of administrative, namespace andinformation base functions with programmatic interfaces enables simplifiedaccess to and management of (subject to security constraints) name service.Administrative operations can be performed remotely and flexibly.Namespace and information base operations allow applications and usersto efficiently access and modify information on network objects.

• Compatibility to allow NIS-based applications and environments to migratesmoothly to NIS+.

Page 318: Administration UNIX - Cours Jussieu - 2009-2010

6 SunSoft6 SunSoft

Who Benefits?

System Administrators

NIS+ is a powerful tool for simplified administration of heterogeneousdistributed systems. As the size of such systems grows and the requirementsfor decentralized administration emerge, a multidomain hierarchicalnamespace can be created. Assignment of names and modification ofinformation on network resources within each domain can be decentralized.Further, the hierarchy can correspond to organizational (with each domainrepresenting a functional group, for example, Engineering or Marketing) orlogical hierarchies, allowing administrators to use intuitive schemes fororganizing their namespace.

Comprehensive security schemes benefit administrators by ensuring that thename service is protected from unauthorized access. This is critical since thename service functions as the primary means for administrators to add,remove, or modify network resources. The security functionality is flexible asadministrative groups can ensure that name service information under theircontrol is protected from access and modification by principals outside of thatorganization.

Partitioning allows administrators to continue using NIS+ as the platform fordistributed management as networks grow in size. As multiple domains arecreated, the overall namespace can have unbounded growth, yet the size of anindividual directory remains within bounds. Replication of individualdirectories, on a master/slave basis, allows coping with computer andcommunication link failures. In addition, NIS+ provides for fast transfer ofupdates from master to slave servers, allowing authorized administrators torapidly add, remove, or relocate network resources.

NIS+ also includes a set of functions for flexible and easy administration of thename service itself. This includes functions for starting and stopping NIS+servers, replicating and partitioning operations, and setting security levels.NIS+ functions support a corresponding Application Programming Interface(API) designed to allow NIS+ to be the platform for next-generationadministrative applications from SunSoft and Independent Software Vendors(ISVs).

Page 319: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 7Network Information Service Plus (NIS+) 7

Application Developers

Application developers can use the NIS+ API in a number of ways. First,applications can use the API to lookup information on network resources. TheSunOS 5.0 system uses NIS+ as the repository for storage of information onhosts, passwords, and users for administrative purposes. Applications can usethe NIS+ API to access this information in a high-performance fashion. Second,NIS+ can be used as a secure repository of network-accessible application-specific data. Improved consistency and the read/write capability within NIS+API enable the service to be used to store and modify application-specificinformation. For example, the OpenWindows V3 Calendar Manager usesNIS+ to store group schedule information that authorized group members canaccess and modify to schedule meetings.

Finally, new administrative applications can be developed that run atop theAPI and take advantage of its simplicity and consistency in providing access tonetwork resources. NIS+ will serve as the platform for future administrativeapplications from SunSoft. NIS+ also provides full compatibility with the NIS(i.e., yp_xxx) programming interface to allow ease of application migration.

End Users

NIS+ also provides significant advantages for end users. The securityfunctionality within NIS+ enables users to trust network communications andto protect sensitive information from unauthorized access. Users’ productivityincreases as applications transparently locate resources by accessing the centraldata storage facility with NIS+. The simplicity and completeness of the NIS+interface enables users to take on a greater proportion of administrative tasks,which is particularly advantageous where administration resources can’t keeppace with constantly growing distributed systems.

NIS+ Architecture

NIS+ provides two types of services to clients. The first is a name service thatmaps names, such as domain names, to their respective servers. The second isa directory service where the desired information itself is returned, rather than apointer to it, such as the UNIX password record.

Page 320: Administration UNIX - Cours Jussieu - 2009-2010

8 SunSoft8 SunSoft

NIS+ Naming Model

The naming model used by NIS+ is a graph structured as a singly rooted tree.Within this graph each vertex represents one NIS+ object, each of which mayhave several children associated with it but only one parent. There are sixtypes of NIS+ objects defined: directory, table, group, link, entry, and private.Directory objects identify a database of NIS+ objects. Objects within thatdatabase are represented as children of the directory object. A directory objectand all of its children is an NIS+ domain. An NIS+ directory that is a child ofanother NIS+ directory is a subdomain, and all domains below the rootdirectory are the NIS+ namespace.

An NIS+ object name consists of several labels, each separated from the next bya dot (“.”) character. The rightmost label is closest to the root of the namespace.Labels that contain the dot character are quoted. These names are showngraphically in Figure 2. Names that end with the dot character are said to befully qualified, whereas names which do not are said to be partially qualified.Names that identify objects in the namespace are called NIS+ regular names.

Figure 2 Construction of a Multipart NIS+ Name

mumble

baz

bar

foo

fred

bob.smith

“bob.smith”.fred.mumble.

foo.bar.baz.mumble.

Page 321: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 9Network Information Service Plus (NIS+) 9

NIS+ Database Model

Table objects in the NIS+ namespace identify databases called tables. Thesedatabases are called tables because the model used is that of a columnar table.The object contains the schema for the database it identifies. This schemaspecifies the number of columns in the table and identifies which columns canbe searched with an NIS+ query.

Rows within an NIS+ table are identified by a compound name syntax calledindexed names. These names contain a search criterion and a regular name.The regular name portion identifies the NIS+ table to search. The search criterionidentifies the rows of interest by specifying what value one or more searchablecolumns must contain to satisfy the search. The search criterion consists of anopen bracket “[” followed by zero or more attributes of the form column_name =

column_value followed by a close bracket character “]”. Attributes in the searchcriterion are separated by commas, and the search criterion and the name of thetable to apply it to are also separated by commas. An example of thesecompound names is shown in Figure 3. In the first example, the name[manager=susan],employees.widget.com. selects only the fourth rowwhich satisfies this search. In the second example, the name[manager=george],employees.widget.com. selects the first three rows whichall satisfy the search criterion. Finally the name [manager=george,

name=bob],employees.widget.com. would return only the first row, becauseonly that row satisfies the complete criterion. The null search criterion, [ ], selectsall of the rows.

Figure 3 Indexed Names Selecting Entries From a Table

bob

Table name: employees.widget.com

mary

jane

sam

george

george

george

susan

engineering

engineering

engineering

sales

electronics

electronics

electronics

electronics

name manager department division

[manager=susan], employees.widget.com.

[manager=george],employees.widget.com

{}

Page 322: Administration UNIX - Cours Jussieu - 2009-2010

10 SunSoft10 SunSoft

The set of names that NIS+ will accept can be defined by the grammar shownin Figure 4. This grammar defines the terminal characters dot (.), comma (,),open bracket ([), close bracket (]), and equals (=). Generally, it is inadvisable toput terminal characters in the strings that make up the NIS+ names. However,should that be necessary, a quoting mechanism based on the double quote (“)character is provided. All characters between two double quote characters arenot scanned. The double quote may itself be quoted by placing two doublequote characters adjacent to each other. These two characters are treated as asingle instance of the double quote character.

Figure 4 NIS+ Name Grammar

In addition to the schema, the table object holds other properties associatedwith the database. These include the tables “type,” a concatenation path, and aseparator character that clients printing entries from the table use to separatethe data from each column in the output. All of these properties are showngraphically in Figure 5.

NAME ::= <REGULAR NAME> | <INDEXED_NAME>

REGULAR_NAME ::= . | <STRING> . | <STRING> . <REGULAR_NAME>

INDEXED_NAME ::= <SEARCH_CRITERION> , <REGULAR_NAME>

SEARCH_CRITERION ::= [ <ATTRIBUTE-LIST> ]

ATTRIBUTE_LIST ::= <ATTRIBUTE> | <ATTRIBUTE> , <ATTRIBUTE -LIST>

ATTRIBUTE ::= <STRING> = <STRING>

STRING ::= see note

Note: ISO Latin 1 character set, the initial character in the string may not be either ‘@’ or ‘-’;embedded terminal characters must be protected by double quotes.

Page 323: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 11Network Information Service Plus (NIS+) 11

Figure 5 Graphical Representation of an NIS+ Table

The type property is a string that the server uses to prevent adding to a tableentries that are not compatible with the other entries in the table. This string iscompared to the type string of the entry being added and, if they do not match,the update is rejected. The server also compares the number of columns in theentry being added to the number of columns in the table, as well as their type(binary or text) to minimize mistakes that could corrupt the database.

The concatenation path, or search path, is a string containing the list of tablesto search if the search criterion in the indexed name doesn’t match any entriesin the table. This search path allows all of the tables identified within it toappear to the client as one large table. When entries from several tables in thepath all match the same search criteria, the first ones found are the onesreturned to the client.

In addition to the column data, each row in a table contains some specificinformation about itself in the column labelled Entry Data. This entry dataconsists of the name of the owner for this row, a group owner, a time-to-livevalue for the row, and a set of access rights for this row. The entry data is

Row 0

Row 1

...

Row m

EntryData

Column1

Column2

Columnn

...

Table: foe.bar. Type: “foo records” Path:foo.bar. :fie.bar.

Row 0

Row 1

...

Row m

EntryData

Column1

Column2

Columnn

...

Table: fie.bar. Type: “foo records” Path:foo.bar. :foe.bar.

Row 0

Row 1

...

Row m

EntryData

Column1

Column2

Columnn

...

Table: foo.bar. Type: “foo records” Path:fie.bar. :foe.bar.

Starting from foo.bar

Search Path

Page 324: Administration UNIX - Cours Jussieu - 2009-2010

12 SunSoft12 SunSoft

combined with the data from the columns when a row is returned in the formof an entry object. This data is present for all rows, but is neither searchable norexplicitly identified as a column in the table object.

NIS+ Object Model

NIS+ objects are implemented as variant records. All objects share a commonset of properties which include an owner name, group owner name, accessrights, object identifier, and time-to-live values. Additionally, each type ofobject has a variant part that contains specific information for that type ofobject. Directory objects contain the names, addresses, and authenticationinformation for machines that serve a domain. Table objects contain the schemafor NIS+ tables. Group objects contain a list of principals that are members ofthat group. Link objects contain the name of another object, and entry objectscontain data from an NIS+ table. A diagram of these objects is shown in Figure6. The shaded portion represents properties that are unique to a particular typeof object. The top portion show properties that are common to all objects.

Figure 6 Format of NIS+ Objects

DIRECTORY TABLE GROUP LINK ENTRYiodnamedomainownergroupaccess rightstime to livedirectory name table type group flags link name entry’s typedirectory type number of columns group members(s) link type entry dataservers(s) column description(s) member 0 datum 0

master column 0 member 0 datum 1replica(s) column 1 ... ......

CommonProperties

VariantProperties

Page 325: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 13Network Information Service Plus (NIS+) 13

NIS+ Authorization Model

The NIS+ authorization model has four different access rights that can begranted to four classes of NIS+ principal. The four classes of principal are: theowner of an object; the group owner, which is a set of principals that is specifiedby a group object; the set of authenticated principals that are known to the NISservice, called collectively the world; and the set of unauthenticated principalscalled collectively the nobody principal.

The four access rights that are grantable are read, modify, create, and destroy.Read conveys the right to read the contents of objects, directory objects, andtable objects. Modify conveys the right to change the attributes of an objectsuch as the owner, group owner, time-to-live, and so forth. For directory andtable objects, create conveys the right to add objects to the namespacecontrolled by that object, either a domain or a database, depending on theobject’s type. Destroy conveys the right to remove objects from directories ortables. Domains and tables have additional access rights masks that allowrights to be granted with a finer degree of granularity.

The NIS+ service uses authentication information extracted from the RPCmessages it receives to identify the NIS+ principal making the request.ONC/RPC messages have attached to them authentication information in theform of an authentication flavor. Each flavor of authentication contains a uniqueprincipal name. The service uses this name and the authentication type tosearch an NIS+ table named cred.org_dir.<domain>. In that table, there is anentry that contains the flavor-specific name and the NIS+ principal name. ThisNIS+ defined name is used in the authorization mechanism rather than theauthentication flavor-specific name. This mapping allows the NIS+ service toaccept different flavors of authentication information and continue to workcorrectly.

The authorization model for tables is somewhat more sophisticated than that ofthe namespace. Access rights in tables can be granted on a per table, per entry,and per column basis. Each level supersedes all subsequent levels. Thus, ifread access is allowed for the table, it is allowed for every row and everycolumn in the table. If read access is not allowed for the table but is allowed fora particular row, then it is allowed for all columns in that row. Finally, if readaccess is not allowed for the table and not allowed for the row but is grantedfor a particular column, then that column’s value is returned. This is showngraphically in Figure 7. Each mask serves to narrow the authorization to a finergrain. In the figure, the entire table is readable only by the owner of the table.

Page 326: Administration UNIX - Cours Jussieu - 2009-2010

14 SunSoft14 SunSoft

However, all of Row 1 is readable by the group owner of that row. Finally,Column 1 of Row 1 is readable by all NIS+ principals. The modify right may besimilarly granted.

Figure 7 Access Rights for Tables Showing Narrowing of Access Rights

The service enforces read access by censoring the information that therequesting principal is not allowed to read. When one or more, but not all,columns of an entry are protected, the protected columns have the sensitivedata replaced by the “*NP*” string. Entries that are completely protected aresimply removed from the list of entries that are returned. If no access to thetable is allowed, an error of NIS_PERMISSION is returned.

Row 0

Row 1

...

Row m

Entry

Data

Column

1

Column

2

Column

n...

Table: foo.bar. Type: “foo records” Path:fie.bar. :foe.bar.

DATUM

Column n access rights:-----/----/r--/----

Row m Entry data:-----/----/r--/----

Table Object access rights:r----/----/---/----

Access rights shown for:owner/group/world/nobody

Page 327: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 15Network Information Service Plus (NIS+) 15

NIS+ Replication Model

Like the existing NIS service, NIS+ domains are replicated using a masterand slave model. However, the replication is done on a per domain basiswith each internal node in the hierarchy having its own master and replicas.Further, all changes to either a domain or a table within that domain arelogged on an event basis, and it is these change events that are propagatedto replicas rather than to complete databases.

Implementation of NIS+ Service

The components of the NIS+ design which implement these models are shownin Figure 8. The highlighted components are currently part of the SunOSsystem and are not considered to be part of this design. In Figure 8, each boxrepresents a set of interfaces. Dependencies are not strictly linear since thelocation mechanism may be required to lookup directory objects within theNIS+ namespace, and this causes it to make use of the NIS+ client libraryinterfaces.

Figure 8 The Components of the NIS+ Service

Application / System API

NIS+ Client Library

RPC Authentication Mechanism

NIS+ Location Mechanism

ONC/RPC

NIS+ Service Daemon

Cache Manager

Database Storage/Retrieval Mechanism

Page 328: Administration UNIX - Cours Jussieu - 2009-2010

16 SunSoft16 SunSoft

NIS+ Client Library

The NIS+ client library interface provides the application interface to the NIS+service. Generally, applications have their own naming interface that meetstheir particular requirements. For example the operating system defines anaming interface gethostbyname( ), which takes a host name and returns astructure containing addressing information about that machine. Thisadditional level of indirection allows different naming services to be used indifferent implementations of the interface. The NIS+ client library is designedto provide a set of capabilities upon which custom naming interfaces may bebuilt.

The two primary operations that are provided are the lookup and listoperations. The lookup operation locates objects in the namespace and the listoperation searches tables. Both provide the service binding and nameresolution functions. Additionally, they provide services specific to theiroperation.

The lookup routine implements the symbolic link facility. When a lookuprequest is made and the object returned is a link, the function checks to see if aflag was passed that specified links were to be followed. If it was, the functionrestarts the lookup using the name stored within the link.

Similarly, the list function implements the table search paths. When a search ofan NIS+ table returns no entries, and the user has specified that the table’s pathis to be followed, this function begins searching each table in the path until amatch is found or the path is exhausted.

The client library also provides the service location mechanism. All NIS+clients have a file in their file system that contains the name, address, andauthentication information for at least one trusted machine. Requests forservice go to that machine or machines first when the client boots up. Whenthe desired name is not within the local domain, the machine serving thedomain is queried for a server that does serve the desired domain. This querywill be answered by either the name of a server who serves that domain or aserver that is closer to that domain. The location function will cache thisinformation with a local daemon named the NIS+ cache manager. If the returnedinformation is not the desired domain, the domain returned is queried for thename of a machine serving the desired domain. In this way, all nodes in thenamespace can be located.

Page 329: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 17Network Information Service Plus (NIS+) 17

The client library also provides the interfaces to add, remove, or modify NIS+objects and entries in NIS+ tables. Various routines for manipulating NIS+names, routines for returning the NIS+ names associated with the currentprocess, and various object handling functions, round out the package.

NIS+ Cache Manager

The NIS+ location mechanism is predicated on the fact that a machine thatserves a domain is itself a client of a domain above the one it serves. When alocation request comes from a client for a domain, the service checks to see if itserves the requested domain. If it does not serve the domain, then it checks tosee if the desired domain is below the domain it serves in the namespace. If thedesired domain is below its domain, it locates the directory object in its domainthat is an ancestor of the desired domain and returns that to the client. If thedesired domain is located above the server’s domain, it returns the directoryobject for its domain, which is always above the one it serves. Eventually thismechanism will find its way to the root of the namespace and begin to work itsway down again.

Once the desired directory object is found, the service returns it to the client.Prior to returning the directory object, it “signs” it with a cryptographicchecksum, using a key that only a root process on the client machine willknow. When the client library gets the directory object, it passes it to the cachemanager which verifies the signature and adds it to its shared memory cache ofdirectories. Future client requests will find the directory object in the cachemanager’s cache and avoid the time-consuming location step.

NIS+ Service Daemon

Once the directory object for a domain is located, the client library will attemptto bind to each of the servers within it until a binding is successful. Updateoperations will attempt to bind only to the master server. Given a binding, theclient library then makes an RPC call to the NIS+ service. The service uses avirtual memory database to store its information. It receives the request, checksthe access rights, and then responds with the requested information.

The database used is linked to the service at runtime using the shared libraryfacilities of the SunOS system. The use of shared libraries allows the databaseto be replaced with specialized versions for different applications.

Page 330: Administration UNIX - Cours Jussieu - 2009-2010

18 SunSoft18 SunSoft

An In-depth Look at an NIS+ Operation

A diagram showing the execution of an NIS+ lookup is provided in Figure 9.An NIS+ operation begins with a call to an application or system libraryinterface (1) that uses NIS+ in its implementation. Most often, this operationwill be a search of an NIS+ table. In our example, the gethostbynamefunction call searches the hosts table. The gethostbyname function then callsthe NIS+ client library in Step 2. The client library looks in the cache manager’sshared memory location cache for the name and address of an appropriatemachine. If there are no appropriate bindings, the client library will locate oneusing Steps 2.1 and 2.2 to call the nis_finddirectory function in search ofa server. When a machine is located, the client library issues an RPC request,Step 3, to talk to the service. The service consults its database and returns theresults in Step 4. The client library takes the results and passes them up to theapplication interface in Step 5, and the gethostbyname call converts the datain the entry object into a struct hostent for the calling program.

Page 331: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 19Network Information Service Plus (NIS+) 19

Figure 9 Execution of an NIS+ Lookup

Legend:Shared Memory InterfaceShared Library InterfaceRemote Procedure CallCache Message ProtocolShared Memory Mapping

hostent *gethostbyname(“pepper”);

Local library API

NIS+ ClientLibrary

CacheLibrary

Structured StorageManager

NIS+ ServiceDaemon

NIS+find_directory()

NIS+ ServiceDaemon

34

25

16

2.2

2.1

CacheManager

Structured StorageManager

Occurs on Cache Miss

Page 332: Administration UNIX - Cours Jussieu - 2009-2010

20 SunSoft20 SunSoft

Glossary of Terms

Throughout this document, terms are used that have specific meanings. Theseterms are collected here for easy reference.

APIThe Application Programming Interface, or API, consists of a series of Croutines that give application programs access to the naming service.

BindingAn NIS+ name, protocol information and valid credential for the local NIS+server. This information is sufficient to contact the server and resolve namesadministered by it.

CredentialA piece of information that identifies the user or host providing it. If theinformation is encrypted in such a way that only its true owner, as opposed toan imposter, could encrypt it, then it is a Secure Credential.

DatumThe dbm structure that NIS uses: it consists of an opaque key and an opaquedata array.

dbmA collection of C language routines that implement a very simple database.The database is divided into maps.

DNSThe Domain Name Service: the Internet name service that is defined in RFC1034 and RFC 1035.

DomainA namespace administered by a single authority. The domain contains one ormore servers that have its directory.

Global NamespaceThe space of all possible names that NIS+ can name. This space starts at dot (.)and goes down.

Information Base

A generic term for a collection of information that is named.

Page 333: Administration UNIX - Cours Jussieu - 2009-2010

Network Information Service Plus (NIS+) 21Network Information Service Plus (NIS+) 21

InternetA network whose participants are machines and users from more than oneorganization. Additionally, those organizations do not share any commonmanagement at any level.

Leaf NodeA leaf node or name has no other names below it in the namespace tree.

NamespaceA namespace is a collection of names administered by a single authority. Thisspace can be composed of several branches of the Organizational Namespace.

ObjectAn NIS+ object is the basic unit in the namespace. This data structure consistsof an administrative part that identifies ownership, access rights, and so forth,and a data part that contains the value of the object.

Object ValueThe data portion of an NIS+ object.

PrincipalClients of the naming service, such as users and hosts, having credentials.

Page 334: Administration UNIX - Cours Jussieu - 2009-2010

22 SunSoft22 SunSoft

Page 335: Administration UNIX - Cours Jussieu - 2009-2010

SunSoft, Inc.2550 Garcia Avenue

Mountain View, CA 94043

For more information, call 1 800 227-9227.

Printed in USA 9/91 91027-0 1.5K

Page 336: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 18

Mécanisme d’authentification réseau :LDAP

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 536 / 803

18 Mécanisme d’authentification réseau : LDAP 18.1 ProblématiqueChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.1 • Problématique

Cas de l’université de Paris 4 :base Microsoft Excel du personnel administratifbase Microsoft Access du personnel enseignantbase « /etc/passwd » des comptes email des utilisateursbase mysql des 2 catégories de personnelprochainement logiciel à base d’Oracleprochainement Microsoft Active Directory

Question 1 : envoyer un email à tous les personnels administratifs sachantque le service du personnel ne fournira qu’une liste avec nom et prénom.Comment l’ingénieur système fait-il ?Question 2 : envoyer un email à tous les personnels administratifs saufceux du site de Clignancourt, sachant que le service du personnel ne peutpas fournir de liste cette fois-ci. Comment l’ingénieur système fait-il ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 537 / 803

Page 337: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.2 Principe d’annuaireChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.2 • Principe d’annuaire

Un annuaire informatique est un service permettant d’accéder à desinformations, relatives à des personnes ou à diverses ressources de façonorganisée.

Objectif : maintenir de façon cohérente et contrôlée les archipels dedonnées et obtenir des données de référence.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 538 / 803

18 Mécanisme d’authentification réseau : LDAP 18.2 Principe d’annuaire

Un annuaire n’est pas une base de données relationnelles.

Une base de données (SGBD) se caractérise par :

Le schéma des données est défini à 100% pour résoudre un certainproblème.Les applications connaissent explicitement le schéma des données.Les objets sont complexes et éclatés entre plusieurs tables liées pardes relations complexes.Un SGBD supporte les transactions.Un SGBD supporte un langage comme SQL qui permet des fonctionsd’interrogation et de mises à jour très complexes.Un SGBD centralise les données pour éviter les problèmes desynchronisation de données et de qualité des temps de réponse.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 539 / 803

Page 338: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.2 Principe d’annuaire

Un annuaire se caractérise par :

Les objets sont indépendants (pas de liens de dépendance entre eux).Les objets peuvent être distribué sur plusieurs annuaires pour assurerune meilleure disponibilité.Le schéma est standardisé pour pouvoir partager les données.Le schéma est extensible pour prendre en compte tous les besoinsmais cela est fait de façon compatible avec les standards.Les applications d’annuaire ignorent la structure interne des données.Un annuaire est principalement consulté en lecture et est optimisépour cela.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 540 / 803

18 Mécanisme d’authentification réseau : LDAP 18.3 Annuaire LDAPChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.3 • Annuaire LDAP

LDAP ≡ Lightweight Directory Access ProtocolHéritier de l’annuaire ISO X500.Version 3 actuellement. RFC 2251 à 2256, RFC 2829 à 2830, RFC 2849.Il n’y a pas de standard de représentation des contrôles d’accès auxdonnées.

LDAP :nom d’un protocolenom d’une structure de donnéesnom d’implémentations de serveurs suivant le protocole

Confusion possible. . .

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 541 / 803

Page 339: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.4 Modèle de données de LDAP : DIT, suffixeChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.4 • Modèle de données de LDAP : DIT, suffixe

Les entrées sont organisées sous forme d’arbre ou DIT (DirectoryInformation Tree).

L’une des difficultés de LDAP : construire l’organisation du DIT.

De quoi est-il le reflet ? :

DIT à caractère organisationnel ?DIT à caractère géographique ?

Pas de solution universelle.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 542 / 803

18 Mécanisme d’authentification réseau : LDAP 18.4 Modèle de données de LDAP : DIT, suffixe

DIT à caractère organisationnel ?

dc=company,dc=com

dc=marketingdc=financedc=recherche

dc=people

dc=groups

dc=people

dc=groups

dc=people

dc=groups

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 543 / 803

Page 340: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.4 Modèle de données de LDAP : DIT, suffixe

DIT à caractère géographique ?

dc=company,dc=com

dc=people

dc=groups

dc=people

dc=groups

dc=people

dc=groups

dc=america dc=europe dc=asia

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 544 / 803

18 Mécanisme d’authentification réseau : LDAP 18.4 Modèle de données de LDAP : DIT, suffixe

La racine de l’arbre est uniquement conceptuelle et n’existe pas réellement.C’est le suffixe qui sert à déterminer les adresses absolues des objets(comme « / » pour l’arborescence des fichiers UNIX).

dc=company,dc=com

dc=marketingdc=financedc=recherche

dc=people

dc=groups

dc=people

dc=groups

dc=people

dc=groups

SUFFIXE

Le suffixe peut avoir plusieurs formes :forme 1 : « o=company.com »forme 2 : « o=company,c=com »forme 3 : « dc=company,dc=com »

On préférera la 3ième forme, ayant un certain rapport avec les noms dedomaine DNS.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 545 / 803

Page 341: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.4 Modèle de données de LDAP : DIT, suffixe

Exemple de DIT visualisé avec LdapBrowser disponible à l’URLhttp://www.iit.edu/~gawojar/dap/ :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 546 / 803

18 Mécanisme d’authentification réseau : LDAP 18.5 Modèle de données de LDAP : entrée, attributs, DN, URLChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.5 • Modèle de données de LDAP : entrée, attributs, DN, URL

DSE ≡ Directory Service EntryLes entrées dans le DIT (DSE) sont des agrégats d’attributs monovaluésou multivalués qui permettent de stocker n’importe quel format dedonnées (prénom, numéro de téléphone, image, son, etc.)Les DSE sont stockées dans le DIT et arrangés selon leur identifiantunique, le DN (Distinguished Name). Un DN est la concaténation d’unRDN (Relative DN) et du DN des parents. Un DN s’apparente à une clefprimaire.

suffixe : dc=company,dc=com

RDN : ou=Recherche DN : ou=Recherche,dc=company,dc=com

RDN : uid=besancon DN : uid=besancon,ou=Recherche,dc=company,dc=com

(le RDN doit être un des attributs/valeurs du DSE)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 547 / 803

Page 342: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.5 Modèle de données de LDAP : entrée, attributs, DN, URL

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 548 / 803

18 Mécanisme d’authentification réseau : LDAP 18.5 Modèle de données de LDAP : entrée, attributs, DN, URL

Il existe des URL LDAP (RC 2255) qui prennent la forme :ldap://serveur:389/DN

Par exemple dans communicator de netscape :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 549 / 803

Page 343: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.6 Modèle de données de LDAP : schéma, syntaxes, OID, objectclassChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.6 • Modèle de données de LDAP : schéma, syntaxes, OID, objectclass

Le schéma du DIT regroupe les définitions relatives aux types d’objets quepeut contenir l’annuaire ou que l’on peut rechercher.Le schéma contiendra des objets instanciations de classes LDAP, lesdéfinitions de ces classes et de leurs attributs, les syntaxes de cesattributs.Tous ces éléments seront identifiés par des Object Identifiers dits OID.

attributetype ( 1.3.6.1.1.1.1.0 NAME ’uidNumber’

DESC ’An integer uniquely identifying a user in a domain’

EQUALITY integerMatch

SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )

objectclass ( 1.3.6.1.1.1.2.0 NAME ’posixAccount’ SUP top AUXILIARY

DESC ’Abstraction of an account with POSIX attributes’

MUST ( cn $ uid $ uidNumber $ gidNumber $ homeDirectory )

MAY ( userPassword $ loginShell $ gecos $ description ) )

(1.3.6.1.1.1.1.0 et 1.3.6.1.4.1.1466.115.121.1.27 sont des OIDS)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 550 / 803

18 Mécanisme d’authentification réseau : LDAP 18.6 Modèle de données de LDAP : schéma, syntaxes, OID, objectclass

Une syntaxe est un modèle de représentation des valeurs de l’attribut. Parexemple booléen, entier, binaire (pour une image, un son), etc.

L’attribut objectclass spécifie la liste des classes qu’instancie un DSE.Chaque classe va construire la structure du DSE en spécifiant une listed’attributs obligatoirement présents (« MUST » dans l’objectclass) et uneliste d’attributs facultatifs (« MAY » dans l’objectclass).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 551 / 803

Page 344: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.6 Modèle de données de LDAP : schéma, syntaxes, OID, objectclass

Exemple :

objectclass ( 2.16.840.1.113730.3.2.2

NAME ’inetOrgPerson’ DESC ’RFC2798: Internet Organizational Person’

SUP organizationalPerson STRUCTURAL

MAY (

audio $ businessCategory $ carLicense $ departmentNumber $

displayName $ employeeNumber $ employeeType $ givenName $

homePhone $ homePostalAddress $ initials $ jpegPhoto $

labeledURI $ mail $ manager $ mobile $ o $ pager $

photo $ roomNumber $ secretary $ uid $ userCertificate $

x500uniqueIdentifier $ preferredLanguage $

userSMIMECertificate $ userPKCS12 ) )

objectclass ( 1.3.6.1.1.1.2.0 NAME ’posixAccount’ SUP top AUXILIARY

DESC ’Abstraction of an account with POSIX attributes’

MUST ( cn $ uid $ uidNumber $ gidNumber $ homeDirectory )

MAY ( userPassword $ loginShell $ gecos $ description ) )

⇒ l’attribut « uid » sera de type MUST.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 552 / 803

18 Mécanisme d’authentification réseau : LDAP 18.6 Modèle de données de LDAP : schéma, syntaxes, OID, objectclass

Les objectclass de LDAP s’inscrivent dans un hiérarchie dont la racine estl’objectclass « top ».

Chaque classe hérite d’une seule classe mère.

Chaque classe peut donner lieu à plusieurs sous classes.

(Abstract)

top

(Structural)

person(Auxiliary)

companyPerson

(Structural)

residentialPerson

(Structural)

organizationalPerson

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 553 / 803

Page 345: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.7 Protocole LDAP / BindChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.7 • Protocole LDAP / Bind

Au niveau réseau :LDAP : TCP port 389LDAP + SSL : TCP port 636( syntaxe LDAP au format ASN.1 ) + BER

Un dialogue LDAP s’établit après une phase d’ouverture de session ditebind.Le bind peut être anonyme ou authentifié.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 554 / 803

18 Mécanisme d’authentification réseau : LDAP 18.8 Format de données LDIFChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.8 • Format de données LDIF

Problème : comment manipuler les objets LDAP en pratique ?

Réponse : en les manipulant au format LDAP Data Interexchange Format,dit LDIF

LDIF n’intervient pas dans le protocole LDAP (pas de mention dans lesRFC par exemple).

LDIF n’est compris que par les utilitaires qui le convertissent en protocoleLDAP.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 555 / 803

Page 346: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.8 Format de données LDIF

Attention aux caractères non ASCII :si la valeur d’un attribut est uniquement composé de caractèresASCII, on l’écrit « attribut : valeur »si la valeur d’un attribut contient des caractères non ASCII, il fautcoder cette valeur en UTF-8 puis la coder en BASE64 et écrire aufinal « attribut :: valeur2 »

Par exemple l’attribut « description » de valeurUniversité de Paris-Sorbonne, Paris 4

ne sera pas codé en LDIF sous la formedescription: Université de Paris-Sorbonne, Paris 4

mais sous la formedescription:: VW5pdmVyc2l0w6kgZGUgUGFyaXMtU29yYm9ubmUsIFBhcmlzIDQ=!

Notez les différences !

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 556 / 803

18 Mécanisme d’authentification réseau : LDAP 18.8 Format de données LDIF

2 utilitaires pratiques :http://docs.univ-nancy2.fr/ldap/OutilsPERL/DecodLDIF.pl

http://docs.univ-nancy2.fr/ldap/OutilsPERL/EncodLDIF.pl

A verifier...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 557 / 803

Page 347: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.8 Format de données LDIF

Exemple d’une DSE avec des caractères accentués non encore codés enLDIF :

dn: ou=Personnel,dc=paris4,dc=sorbonne,dc=fr

objectclass: top

objectclass: organizationalUnit

ou: Personnels de l’Université de Paris-Sorbonne, Paris 4

businessCategory: academic research

telephoneNumber: +33 (0) 1 40 46 22 11

facsimileTelephoneNumber: +33 (0) 1 40 46 25 88

postOfficeBox: Université de Paris-Sorbonne, Paris 4

postalCode: F-75230

postalAddress: 1 rue Victor Cousin

l: Paris, France

description: Université de Paris-Sorbonne, Paris 4

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 558 / 803

18 Mécanisme d’authentification réseau : LDAP 18.8 Format de données LDIF

Exemple d’une DSE au format LDIF :

dn: ou=Personnel,dc=paris4,dc=sorbonne,dc=fr

objectclass: top

objectclass: organizationalUnit

ou:: UGVyc29ubmVscyBkZSBsJ1VuaXZlcnNpdMOpIGRlIFBhcmlzLVNvcmJvbm5lLCBQYXJpcyA0

businessCategory: academic research

telephoneNumber: +33 (0) 1 40 46 22 11

facsimileTelephoneNumber: +33 (0) 1 40 46 25 88

postOfficeBox:: VW5pdmVyc2l0w6kgZGUgUGFyaXMtU29yYm9ubmUsIFBhcmlzIDQ=

postalCode: F-75230

postalAddress: 1 rue Victor Cousin

l: Paris, France

description:: VW5pdmVyc2l0w6kgZGUgUGFyaXMtU29yYm9ubmUsIFBhcmlzIDQ=

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 559 / 803

Page 348: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.9 ImplémentationsChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.9 • Implémentations

Il existe plusieurs implémentations de LDAP :OpenLdap, http://www.openldap.org, version 2.1.3 (au 21 août2002)SUN ONE (anciennement Netscape Directory Server, racheté parSUN devenu Sun Iplanet Directory puis SUN ONE) incorporé de basedans Solaris 8 et ultérieurNovell Directory Services, version 4 ?autes annuaires commerciaux. . .

Les différentes implémentations respectent les normes du protocole. Parcontre, elles différent au niveau de tout ce qui n’est pas norme. Enparticulier, les droits d’accès aux données sont codés de façonincompatible.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 560 / 803

18 Mécanisme d’authentification réseau : LDAP 18.10 OpenLDAPChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.10 • OpenLDAP

Cf http://www.openldap.org/Les versions 2.x.y d’OpenLDAP sont compatibles avec les normes deLDAP v3.

Le logiciel se compose de :du serveur LDAP « slapd »du serveur de synchronisation « slurpd »d’utilitaires (« slapadd », « ldapsearch », « ldapadd »,« ldapdelete », « ldapmodify », « ldappasswd », etc.)librairies, include LDAPun fichier de configuration « slapd.conf » dans lequel on définit lesuffixe, le rootDN, le mot de passe du rootDN

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 561 / 803

Page 349: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.10 OpenLDAP

Le mécanisme de réplication de serveurs OpenLDAP est le suivant :

slurpd

1) demande de modification

2) réponse : referral

3) demande de modification

4) réponse (OK/not OK)

slapd

(Esclave)

slapd

(Maitre)

Journal desmodifications

client

5)

6)

7)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 562 / 803

18 Mécanisme d’authentification réseau : LDAP 18.11 ObjectClass posixAccount, shadowAccountChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.11 • ObjectClass posixAccount, shadowAccount

Cf RFC2307Cf le schéma « nis.schema » dans OpenLDAP.L’objectclass « posixAccount » est l’objet qui implémente l’équivalent dela structure C de « <pwd.h> » :

objectclass ( 1.3.6.1.1.1.2.0 NAME ’posixAccount’ SUP top AUXILIARY

DESC ’Abstraction of an account with POSIX attributes’

MUST ( cn $ uid $ uidNumber $ gidNumber $ homeDirectory )

MAY ( userPassword $ loginShell $ gecos $ description ) )

L’objectclass « shadowAccount » est l’objet qui implémente le principedes shadow passwds :

objectclass ( 1.3.6.1.1.1.2.1 NAME ’shadowAccount’ SUP top AUXILIARY

DESC ’Additional attributes for shadow passwords’

MUST uid

MAY ( userPassword $ shadowLastChange $ shadowMin $

shadowMax $ shadowWarning $ shadowInactive $

shadowExpire $ shadowFlag $ description ) )

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 563 / 803

Page 350: Administration UNIX - Cours Jussieu - 2009-2010

18 Mécanisme d’authentification réseau : LDAP 18.12 Un peu de bibliographieChapitre 18 • Mécanisme d’authentification réseau : LDAP§18.12 • Un peu de bibliographie

http://docs.univ-nancy2.fr/ldap/

http://www.openldap.org/

http://www.linux-france.org/article/serveur/ldap/

http://www.unich.edu/~dirsvc/ldap/

http://www.redbooks.ibm.com

http://www-sop.inria.fr/semir/personnel/Laurent.Mirtain/LDAP.html

http://www.cru.fr/ldap/

http://www.ldapcentral.com

http://www.rage.net/ldap/

http://www.annuairesldap.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 564 / 803

Page 351: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 19

Sélection de naming services,/etc/nsswitch.conf

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 565 / 803

19 Sélection de naming services, /etc/nsswitch.conf 19.1 ProblématiqueChapitre 19 • Sélection de naming services, /etc/nsswitch.conf§19.1 • Problématique

Exemple :il y a les fichiers système (« /etc/passwd », « /etc/hosts »,« /etc/services », . . .)il y a le DNSil y a NISil y a NIS+il y a LDAPetc.

Comment choisir quels services répondront aux requêtes de recherche denom ?

Une solution : préciser quels naming services seront utilisés et dans quelordre au niveau du fichier « /etc/nsswitch.conf » (en anglais namingservice switch).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 566 / 803

Page 352: Administration UNIX - Cours Jussieu - 2009-2010

19 Sélection de naming services, /etc/nsswitch.conf 19.2 Syntaxe de /etc/nsswitch.confChapitre 19 • Sélection de naming services, /etc/nsswitch.conf§19.2 • Syntaxe de /etc/nsswitch.conf

Le fichier est au format suivant :

service: source [ status=action status=action... ] source...

avec :pour source l’un des mots clef « files », « dns », « ldap », « nis »,« nisplus », « xfn » (liste à vérifier selon les systèmes UNIX offrantplus ou moins de ces services)pour status l’un des mots clef suivants :

« SUCCESS », entrée recherchée trouvée« NOTFOUND », entrée recherchée non trouvée« UNAVAIL », la source n’est pas configurée sur ce système ou bien elleest défaillante« TRYAGAIN », la source est occupée et ne peut pas répondreactuellement, peut-être plus tard

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 567 / 803

19 Sélection de naming services, /etc/nsswitch.conf 19.2 Syntaxe de /etc/nsswitch.conf

pour action l’un des mots clefs :« return », retourner la valeur trouvée ou la non valeur« continue », essayer la source suivante« forever » (uniquement pour « TRYAGAIN »), persister sur cettesource jusqu’à avoir une réponse

Par défaut, on a pour chaque source :

[SUCCESS=return NOTFOUND=continue UNAVAIL=continue TRYAGAIN=forever]

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 568 / 803

Page 353: Administration UNIX - Cours Jussieu - 2009-2010

19 Sélection de naming services, /etc/nsswitch.conf 19.3 Exemple de /etc/nsswitch.confChapitre 19 • Sélection de naming services, /etc/nsswitch.conf§19.3 • Exemple de /etc/nsswitch.conf

(pris sur SOLARIS)

passwd: files ldap

group: files ldap

hosts: ldap [NOTFOUND=return] files

ipnodes: files

networks: ldap [NOTFOUND=return] files

protocols: ldap [NOTFOUND=return] files

rpc: ldap [NOTFOUND=return] files

ethers: ldap [NOTFOUND=return] files

netmasks: ldap [NOTFOUND=return] files

bootparams: ldap [NOTFOUND=return] files

publickey: ldap [NOTFOUND=return] files

netgroup: ldap

automount: files ldap

aliases: files ldap

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 569 / 803

19 Sélection de naming services, /etc/nsswitch.conf 19.4 A propos de LDAPChapitre 19 • Sélection de naming services, /etc/nsswitch.conf§19.4 • A propos de LDAP

Pour les systèmes n’incorporant pas LDAP en natif dans l’OS, se reporterà :

« http://www.padl.com/download/nss_ldap.tgz »« http://www.openldap.org/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 570 / 803

Page 354: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 20

Pluggable Authentication Module (PAM)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 571 / 803

20 Pluggable Authentication Module (PAM) 20.1 ProblématiqueChapitre 20 • Pluggable Authentication Module (PAM)§20.1 • Problématique

Exemple :Soit une machine dans une université, hébergeant les comptes de 10professeurs et de 1000 élèves.La machine est équipée d’un modem.Les professeurs sont autorisés à se connecter à la machine parmodem, pas les élèves.La machine est cliente NIS.Quand on se connecte par modem sur une machine, le système lancela commande « login » lorsque la connexion s’établit.

Comment implémenter cela ?En modifiant le programme « login » pour l’adapter à ce cas trèsparticulier ? ? ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 572 / 803

Page 355: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.1 Problématique

La problématique en général :Comment changer une méthode d’authentification dans un programme(par exemple FTP) sans avoir à tout reprogrammer ?

Solution développée par SUN à l’origine et reprise et encouragée dansLinux : Pluggable Authentication Module dit PAM

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 573 / 803

20 Pluggable Authentication Module (PAM) 20.2 Principe de PAMChapitre 20 • Pluggable Authentication Module (PAM)§20.2 • Principe de PAM

L’authentication fait appel par l’intermédiaire de PAM à des modulesexternes de code d’authentification appropriée selon le service. On déportel’authentification en dehors du programme.

programme1 programme2

moduleA.somoduleB.somoduleC.so

moduleD.so

moduleB.somoduleC.so

moduleE.somoduleF.so

/etc/pam.conf

moduleA.so

moduleB.so

moduleC.so

moduleD.so moduleE.so

moduleF.so

programme1

pam_init()

pam_auth()

programme2

pam_init()

pam_auth()

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 574 / 803

Page 356: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.2 Principe de PAM

4 catégories de modules PAM :

module d’authentification (authentication)fonctionnalités pour authentifier un utilisateur et définir ses créancesmodule de gestion de compte (account management)fonctionnalités pour déterminer si l’utilisateur dispose d’un comptevalide (car possibilité d’expiration de mot de passe dit passwordaging, de restrictions d’accès horaire)module de gestion de session (session management)fonctionnalités pour définir et terminer les sessions utilisateurmodule de gestion de mot de passe (password management)fonctionnalités pour changer un mot de passe utilisateur et certainescaractéristiques du compte

Pour une certaine application, on organise les modules nécessaires sousforme d’une pile et chaque module de la pile va être essayé pour constituerl’authentification demandée.Selon la configuration, un utilisateur pourra être amené à rentrer plusieursmots de passe.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 575 / 803

20 Pluggable Authentication Module (PAM) 20.3 Configuration de PAM : /etc/pam.conf, /etc/pam.dChapitre 20 • Pluggable Authentication Module (PAM)§20.3 • Configuration de PAM : /etc/pam.conf, /etc/pam.d

« /etc/pam.conf » définit quels modules seront utilisés pour chaqueapplication.

Sur Linux, on trouve aussi le répertoire « /etc/pam.d » qui contient unfichier par application portant le nom de l’application. Ainsi« /etc/pam.d/login » pour le service « login ».

Une ligne de « /etc/pam.conf » contient 5 champs :

service_name module_type control_flag module_path options

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 576 / 803

Page 357: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.3 Configuration de PAM : /etc/pam.conf, /etc/pam.d

service_name module_type control_flag module_path options

Le « service_name » nomme le service concerné par la ligne(« other » pour service joker)Le « module_type » est l’un des 4 mots clef : « auth »,« account », « session », « password »Le « control_flag » est l’un des 4 mots clef : « requisite »,« required », « optional », « sufficient »Le « module_path » est le chemin du module.Les options dépendent du module.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 577 / 803

20 Pluggable Authentication Module (PAM) 20.3 Configuration de PAM : /etc/pam.conf, /etc/pam.d

Par exemple, le service « login » fait appel aux modules suivants :

# Authentication management

login auth required /usr/lib/security/pam_unix.so.1

login auth required /usr/lib/security/pam_dial_auth.so.1

# Account management

login account requisite /usr/lib/security/pam_roles.so.1

login account required /usr/lib/security/pam_projects.so.1

login account required /usr/lib/security/pam_unix.so.1

# Session management

other session required /usr/lib/security/pam_unix.so.1

# Password management

other password required /usr/lib/security/pam_unix.so.1

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 578 / 803

Page 358: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.4 Directives d’essai des modulesChapitre 20 • Pluggable Authentication Module (PAM)§20.4 • Directives d’essai des modules

Les directives possibles d’essai des modules sont :

directive « required »

directive « requisite »

directive « optional »

directive « sufficient »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 579 / 803

20 Pluggable Authentication Module (PAM) 20.4 Directives d’essai des modules

� directive « required »

La valeur de retour de ce module doit être « PAM_SUCCESS » pour sortirde la pile d’authentification avec succès ; « PAM_AUTH_ERR » ferarecommencer toute la pile :

Pile demodules PAM

REQUIRED

SUCCESS AUTH_ERR

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 580 / 803

Page 359: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.4 Directives d’essai des modules

� directive « requisite »

Une valeur de retour « PAM_AUTH_ERR » fait sortir de la piled’authentification prématurément en échec :

Pile demodules PAM

REQUISITE

AUTH_ERRSUCCESS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 581 / 803

20 Pluggable Authentication Module (PAM) 20.4 Directives d’essai des modules

� directive « optional »

Si ce module échoue, on sortira de la pile avec succès si un autre moduledans la pile réussit :

Pile demodules PAM

OPTIONAL

SUCCESS AUTH_ERR

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 582 / 803

Page 360: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.4 Directives d’essai des modules

� directive « sufficient »

Une valeur de retour « PAM_SUCCESS » de ce module fait sortir de la piled’authentification prématurément avec succès ; les autres modules dans lapile ne sont pas pris en compte :

Pile demodules PAM

SUFFICIENT

SUCCESSAUTH_ERR

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 583 / 803

20 Pluggable Authentication Module (PAM) 20.5 Modules, /usr/lib/securityChapitre 20 • Pluggable Authentication Module (PAM)§20.5 • Modules, /usr/lib/security

Les modules sont conventionnellement stockés dans« /usr/lib/security/ »

Par exemple sur Solaris :

% ls /usr/lib/securityamiserv pam_ldap.so.1 pam_sample.so.1

pam_ami.so pam_projects.so pam_smartcard.so

pam_ami.so.1 pam_projects.so.1 pam_smartcard.so.1

pam_dial_auth.so pam_rhosts_auth.so pam_unix.so

pam_dial_auth.so.1 pam_rhosts_auth.so.1 pam_unix.so.1

pam_krb5.so pam_roles.so sparcv9

pam_krb5.so.1 pam_roles.so.1

pam_ldap.so pam_sample.so

Chaque module fournit l’implémentation d’un mécanisme spécifique.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 584 / 803

Page 361: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.5 Modules, /usr/lib/security

« /usr/lib/security/pam_unix.so.1 » fournit un suportd’authentification, gestion de compte, session de mot de passe. Il utilise lesmots de passe UNIX pour l’authenfication.

« /usr/lib/security/pam_dial_auth.so.1 » peut seulement êtreutilisé pour l’authentification. Il utilise des données stockées dans« /etc/dialups » et « /etc/d_passwd ». Principalement utilisé par« login ».

« /usr/lib/security/pam_rhosts_auth.so.1 » peut seulement êtreutilisé pour l’authentification. Il utilise les données stockées dans lesfichiers « .rhosts » et « /etc/hosts.equiv ». Principalement utilisépar « rlogin » et « rsh ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 585 / 803

20 Pluggable Authentication Module (PAM) 20.6 Options des modulesChapitre 20 • Pluggable Authentication Module (PAM)§20.6 • Options des modules

On peut passer certaines options aux modules

des options spécifiques à chaque module ; cf la documentation dechaque module ; par exemple « retry=3 » ou « debug »option « use_first_pass »Cette option indique d’utiliser exclusivement le mot de passe entrépour le premier module de la pile du service.option « try_first_pass »Cette option indique d’utiliser d’abord le mot de passe entré pour lepremier module de la pile du service et en cas d’échec de ce mot depasse d’en demander un autre.

(Le support des options « use_first_pass » et « try_first_pass » estfortement conseillé auprès des développeurs de modules PAM ; à vérifier doncavec chaque module)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 586 / 803

Page 362: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.7 Exemple 1Chapitre 20 • Pluggable Authentication Module (PAM)§20.7 • Exemple 1

Extrait de « /etc/pam.conf » :

# Authentication management

login auth required /usr/lib/security/pam_unix.so.1

login auth required /usr/lib/security/pam_dial_auth.so.1

Fichier « /etc/dialups » :

/dev/pts/9

Fichier « /etc/d_passwd » :

/bin/bash:nuemRW70uy9M.:

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 587 / 803

20 Pluggable Authentication Module (PAM) 20.7 Exemple 1

Session interactive :

% tty/dev/pts/9

% exec loginexec login

login: besancon

Password: XXXXXXXX <-- mot de passeDialup Password: YYYYYYYY <-- mot de passe%% <-- connexion établie, shell lancé

On voit bien la ligne supplémentaire « Dialup Password: »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 588 / 803

Page 363: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.7 Exemple 1

Si l’on se trompe dans l’un des mots de passe, toutes les demandes de motde passe sont réessayées :

% exec loginlogin: besancon

Password: ZZZZZZZZ <-- mauvais mot de passeDialup Password: YYYYYYYY <-- mot de passe OKLogin incorrect

login: besancon

Password: XXXXXXXX <-- mot de passe OKDialup Password: ZZZZZZZZ <-- mauvais mot de passeLogin incorrect

login: besancon

Password: XXXXXXXX <-- mot de passe OKDialup Password: YYYYYYYY <-- mot de passe OK%% <-- connexion établie, shell lancé

Au niveau SYSLOG, ça laisse quelques traces :

Aug 20 14:51:14 cerise login: [ID 427203 auth.debug] pam_authenticate: error Authentication failed...Aug 20 14:51:34 cerise login: [ID 427203 auth.debug] pam_authenticate: error Authentication failed

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 589 / 803

20 Pluggable Authentication Module (PAM) 20.8 Exemple 2Chapitre 20 • Pluggable Authentication Module (PAM)§20.8 • Exemple 2

Pour autoriser l’authentification par LDAP, on mettra dans« /etc/pam.conf » :

# Authentication management

login auth sufficient /usr/lib/security/pam_unix.so.1

login auth required /usr/lib/security/pam_ldap.so.1 use_first_pass

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 590 / 803

Page 364: Administration UNIX - Cours Jussieu - 2009-2010

20 Pluggable Authentication Module (PAM) 20.9 A propos de LDAPChapitre 20 • Pluggable Authentication Module (PAM)§20.9 • A propos de LDAP

Pour les systèmes n’incorporant pas LDAP en natif dans l’OS, se reporterà :

« http://diamond.rug.ac.be/pam_LDAP/index.shtml »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 591 / 803

20 Pluggable Authentication Module (PAM) 20.10 Un peu de bibliographieChapitre 20 • Pluggable Authentication Module (PAM)§20.10 • Un peu de bibliographie

http://www.sun.com/software/solaris/pam/

http://www.kernel.org/pub/linux/libs/pam/

http://www.netlogic.ro/linuxdoc/pam-0.64/html/pam.html

http://www.mailgate.org/mailgate/LINUX/linux.redhat.pam/

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 592 / 803

Page 365: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 21

Système de multifenêtrage : X

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 593 / 803

21 Système de multifenêtrage : X 21.1 Introduction : système de multi fenêtrageChapitre 21 • Système de multifenêtrage : X§21.1 • Introduction : système de multi fenêtrage

Système de multifenêtrage (Window System) :ensemble de programmes, de bibliothèques de programmation réalisant uneinterface homme / machine bâtie sur l’utilisation de divers équipements :

claviersourisécran graphiqueautres périphériques (spaceball, plaquette graphique, . . .)

L’écran tente de réaliser un modèle de bureau.

L’idée vient des travaux de Xerox, repris par Apple, repris par le projetAthena du MIT.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 594 / 803

Page 366: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.2 Système de multifenêtrage : XChapitre 21 • Système de multifenêtrage : X§21.2 • Système de multifenêtrage : X

Pour Unix, le système de multi fenêtrage est un système appelé :Xou X Window Systemou X11Ce n’est pas « X Windows » !

Historiquement :X11 sur « UNIX »XFree86 spécifiquement pour LINUXXorg suite à querelles sur XFree86 = retour à l’équipe de X11

http://www.x.org

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 595 / 803

21 Système de multifenêtrage : X 21.2 Système de multifenêtrage : X

Consortium de vendeurs d’UNIX pour mettre au point X.

Historique des versions :X10X11R3X11R4X11R5X11R6X11R7

SUN a sa propre implémentation de X dérivée des X11R[3-7] : SUNOPENWINDOWS

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 596 / 803

Page 367: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.2 Système de multifenêtrage : X

Le système graphique X est construit sur un modèle client – serveur et està la base un protocole de communication :

Evenement (clavier, clic souris, etc.)

Reponse (OK, NOT OK, etc.)

Erreur

AffichageServeur XApplication X

Message (dessine un cercle, etc.)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 597 / 803

21 Système de multifenêtrage : X 21.2 Système de multifenêtrage : X

Serveur X :optimisé pour ses performances graphiquesrépond aux requêtes du client Xenvoie au client X des informations événementielles (« clic du boutondroit de la souris », « appui sur la touche A avec Shift en mêmetemps », etc.)

Client X :effectue les calculsmanipule les fichiersenvoie des requêtes au serveur X (« trace un cercle », « affiche dutexte », « quelles sont les possibilités couleurs de l’écran ? », etc.)

Souvent serveur X = client X = même machine.

Parfois serveur X != client X ⇒ deux machines en réseau. Parfois !

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 598 / 803

Page 368: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.2 Système de multifenêtrage : X

Parfois serveur X != client X ⇒ deux machines en réseau. Parfois !C’est donc un peu plus qu’un système de multifenêtrage : il est réparti.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 599 / 803

21 Système de multifenêtrage : X 21.3 Serveur XChapitre 21 • Système de multifenêtrage : X§21.3 • Serveur X

Serveur X :Au sens large : un serveur graphiqueLe serveur X gére les périphériques :

écrans monochromes, niveaux de gris, couleurs, un ou plusieurs écranssouris, écran tactile, stylet, palette graphiqueclaviersboutons, mollettes

La configuration matérielle du serveur X peut varier considérablement(même si effet d’unification suite à la mode du PC) ⇒ le client Xdoit en tenir compte et doit s’avoir s’adapter.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 600 / 803

Page 369: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.3 Serveur X

A noter qu’il existe des serveurs X sur Windows et sur MacOS X.

Sur Windows, utiliser CYGWIN (« http://www.cygwin.com ») :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 601 / 803

21 Système de multifenêtrage : X 21.4 Client XChapitre 21 • Système de multifenêtrage : X§21.4 • Client X

Client X :Client X == applicationL’application doit être configurable :

Environnement multi plateformes UNIXEnvironnement multi serveurs XEnvironnement multi utilisateurs

L’application ne doit jamais rien supposer du serveur X. Elle doit tenircompte de tous les cas envisageables et être paramétrée en conséquence.

⇒ Nécessité que les applications soient configurables !

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 602 / 803

Page 370: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.5 Chemins d’accèsChapitre 21 • Système de multifenêtrage : X§21.5 • Chemins d’accès

On rencontre :Standard X11R4 et X11R5 :

« /use/bin/X11/ »« /use/lib/X11/ »« /use/include/X11/ »

Standard X11R6 et X11R7 :« /use/X11R6/bin/ »« /use/X11R6/lib/ »« /use/X11R6/include/ »

Standard SUN OPENWINDOWS« /use/openwin/bin/ »« /use/openwin/lib/ »« /use/openwin/include/ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 603 / 803

21 Système de multifenêtrage : X 21.6 Variable d’environnement DISPLAYChapitre 21 • Système de multifenêtrage : X§21.6 • Variable d’environnement DISPLAY

La variable « DISPLAY » définit le serveur X qui sera utilisé.

Formes possibles de la variable :« nom-machine.domaine:numéro-serveur.numéro-écran »« adresse-ip:numéro-serveur.numéro-écran »« :0.0 » (anciennement « unix:0.0 ») ; sens spécial de cetteforme : communication locale rapide via IPC et non pas via le réseauTCP/IP plus lent dans ce cas

On notera « numéro-serveur » : une même machine peut faire tournerplusieurs serveurs X d’où la nécessité de les numéroter. Cas général : unseul serveur X ⇒ numéro = 0.

On notera « numéro-écran » : une même machine peut avoir plusieursécrans d’où la nécessité de les numéroter. Cas général : un seul écran ⇒numéro = 0.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 604 / 803

Page 371: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.6 Variable d’environnement DISPLAY

Exemples :« cerise.example.com:0.0 »« localhost:11.0 »« :0.0 »« 192.168.0.1:0.0 »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 605 / 803

21 Système de multifenêtrage : X 21.7 ClavierChapitre 21 • Système de multifenêtrage : X§21.7 • Clavier

La gestion du clavier est quelque chose de compliqué. . .Tous les types de claviers doivent pouvoir être supportés (FR, EN, RU,etc.).

Par exemple des claviers braille :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 606 / 803

Page 372: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.7 Clavier

Par exemple des boites à boutons ou à molettes (marque SILICONGRAPHICS) :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 607 / 803

21 Système de multifenêtrage : X 21.7 Clavier

Code clavier

1ere conversion

2eme conversion

Keycode

Keysym

Keycode + Keysym + Status

Shift

Alt Graph

SERVEUR X

CLIENT X

Alt, Num Lock, Alt Graph, Meta, Ctrl, Caps Lock, Shift

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 608 / 803

Page 373: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.7 Clavier

� Keycode

X définit une association entre le code généré par la touche du clavier etun code de la touche au niveau du serveur X : c’est le keycode.

Il existe un keycode et un seul par touche du clavier.

On ne peut pas modifier l’association entre le code du clavier et le keycode(sauf à recompiler le serveur X).

On peut obtenir le keycode par l’utilitaire « xev ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 609 / 803

21 Système de multifenêtrage : X 21.7 Clavier

Exemple de XEV : appui sur la touche « p » :

% xev...

KeyPress event, serial 20, synthetic NO, window 0xc00001,

root 0x2f, subw 0x0, time 2631657543, (103,101), root:(927,454),

state 0x2, keycode 26 (keysym 0x70, p), same_screen YES,

XLookupString gives 1 characters: "p"

KeyRelease event, serial 22, synthetic NO, window 0xc00001,

root 0x2f, subw 0x0, time 2631657607, (103,101), root:(927,454),

state 0x2, keycode 26 (keysym 0x70, p), same_screen YES,

XLookupString gives 1 characters: "p"

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 610 / 803

Page 374: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.7 Clavier

Exemple de XEV : appui sur la touche « p » avec SHIFT en même temps :

% xev...

KeyPress event, serial 22, synthetic NO, window 0xc00001,

root 0x2f, subw 0x0, time 2631671991, (103,101), root:(927,454),

state 0x2, keycode 232 (keysym 0xffe1, Shift_L), same_screen YES,

XLookupString gives 0 characters: ""

KeyPress event, serial 22, synthetic NO, window 0xc00001,

root 0x2f, subw 0x0, time 2631672071, (103,101), root:(927,454),

state 0x3, keycode 26 (keysym 0x50, P), same_screen YES,

XLookupString gives 1 characters: "P"

KeyRelease event, serial 22, synthetic NO, window 0xc00001,

root 0x2f, subw 0x0, time 2631672127, (103,101), root:(927,454),

state 0x3, keycode 26 (keysym 0x50, P), same_screen YES,

XLookupString gives 1 characters: "P"

KeyRelease event, serial 22, synthetic NO, window 0xc00001,

root 0x2f, subw 0x0, time 2631672215, (103,101), root:(927,454),

state 0x3, keycode 232 (keysym 0xffe1, Shift_L), same_screen YES,

XLookupString gives 0 characters: ""

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 611 / 803

21 Système de multifenêtrage : X 21.7 Clavier

� Keysym

X définit un nom symbolique pour chaque caractère utilisable. On parle dekeysym. Le fichier « <X11/keysymdef.h> » définit les valeursnumériques de ces noms symboliques.

...

#define XK_dollar 0x024

#define XK_percent 0x025

#define XK_ampersand 0x026

#define XK_apostrophe 0x027

#define XK_parenleft 0x028

#define XK_parenright 0x029

#define XK_asterisk 0x02a

#define XK_plus 0x02b

#define XK_comma 0x02c

#define XK_minus 0x02d

#define XK_period 0x02e

#define XK_slash 0x02f

#define XK_0 0x030

#define XK_1 0x031

#define XK_2 0x032

#define XK_3 0x033

#define XK_4 0x034

#define XK_5 0x035

#define XK_6 0x036

#define XK_7 0x037

#define XK_8 0x038

#define XK_9 0x039

#define XK_colon 0x03a

#define XK_semicolon 0x03b

#define XK_less 0x03c

#define XK_equal 0x03d

#define XK_greater 0x03e

#define XK_question 0x03f

#define XK_at 0x040

#define XK_A 0x041

#define XK_B 0x042

#define XK_C 0x043

#define XK_D 0x044

#define XK_E 0x045

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 612 / 803

Page 375: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.7 Clavier

Au démarrage du serveur X, il y a mise en place de correspondances entrekeycode et keysyms.

On peut modifier les correspondances via la commande « xmodmap ».

X accepte au maximum 5 keysyms pour un keycode via le jeu desmodificateurs comme Shift, Ctrl, etc..Exemple des modificateurs d’une machine SOLARIS

% xmodmap -pmxmodmap: up to 2 keys per modifier, (keycodes in parentheses):

shift Shift_L (0xe8), Shift_R (0xec)

lock Control_L (0x40)

control Control_L (0xe7), Control_R (0xeb)

mod1 Meta_L (0xea), Meta_R (0xee)

mod2 Mode_switch (0xed)

mod3 Num_Lock (0x5a)

mod4 Alt_L (0xe9)

mod5

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 613 / 803

21 Système de multifenêtrage : X 21.7 Clavier

Liste des keycodes et de leurs keysyms associés (exemple pris sur unemachine SUN avec un clavier QWERTY) :

% xmodmap -pkThere are 5 KeySyms per KeyCode; KeyCodes range from 8 to 254.

KeyCode Keysym (Keysym) ...

Value Value (Name) ...

...

32 0x0056 (V)

33 0x0057 (W)

34 0x0058 (X)

35 0x0059 (Y)

36 0x005a (Z)

37 0x0031 (1) 0x0021 (exclam)

38 0x0032 (2) 0x0040 (at)

39 0x0033 (3) 0x0023 (numbersign)

40 0x0034 (4) 0x0024 (dollar) 0x20ac (EuroSign)

41 0x0035 (5) 0x0025 (percent) 0x20ac (EuroSign)

42 0x0036 (6) 0x005e (asciicircum)

43 0x0037 (7) 0x0026 (ampersand)

44 0x0038 (8) 0x002a (asterisk)

45 0x0039 (9) 0x0028 (parenleft)

46 0x0030 (0) 0x0029 (parenright)

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 614 / 803

Page 376: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.7 Clavier

Liste des keycodes et de leurs keysyms associés avec affichage sous uneforme compatible avec la syntaxe de XMODMAP pour les modifications(exemple pris sur une machine SUN avec un clavier QWERTY) :

% xmodmap -pke...

keycode 32 = V

keycode 33 = W

keycode 34 = X

keycode 35 = Y

keycode 36 = Z

keycode 37 = 1 exclam

keycode 38 = 2 at

keycode 39 = 3 numbersign

keycode 40 = 4 dollar EuroSign

keycode 41 = 5 percent EuroSign

keycode 42 = 6 asciicircum

keycode 43 = 7 ampersand

keycode 44 = 8 asterisk

keycode 45 = 9 parenleft

keycode 46 = 0 parenright

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 615 / 803

21 Système de multifenêtrage : X 21.7 Clavier

Pour modifier le fonctionnement du clavier , deux syntaxes :« xmodmap -e ’keysym symbole = valeur’ »« xmodmap -e ’keycode code = valeur’ »

Par exemple : on veut associer « é » à la touche « F2 » (clavier SUNQWERTY) :

Le keycode de « F2 » est 66.Le keysym d’origine associé à la touche est 0xffbf.Le keysym associé à « é » est d’après « <X11/keysymdef.h> »0x0e9 (« XK_eacute »).

⇒ « xmodmap -e ’keycode 66 = 0x0e9’ »

A noter sur SOLARIS le script « /usr/openwin/bin/xmakemap » quirenvoie l’image de la configuration actuelle du clavier.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 616 / 803

Page 377: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.8 SourisChapitre 21 • Système de multifenêtrage : X§21.8 • Souris

Tous les types de souris doivent pouvoir être supportés. . .

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 617 / 803

21 Système de multifenêtrage : X 21.8 Souris

Plus classiquement :

C’est un outil de désignation ayant de 1 à 3 boutons.La position est suivie à l’écran par un curseur.Le curseur est toujours affiché au premier plan.

Pour permuter les boutons de la souris :« xmodmap -e ’pointer = 3 2 1’ »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 618 / 803

Page 378: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.9 EcranChapitre 21 • Système de multifenêtrage : X§21.9 • Ecran

x

y

Il est de type bitmap (affichage point).

L’image est obtenue par balayage d’une mémoire d’écran (frame buffer)contenant une valeur par point à l’écran (pixel).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 619 / 803

21 Système de multifenêtrage : X 21.10 Fenêtre / icôneChapitre 21 • Système de multifenêtrage : X§21.10 • Fenêtre / icône

x

y

h

w

Une fenêtre est un rectangle à l’écran caractérisé par un emplacement, unebordure, ses dimensions.

Une icône est la trace visible à l’écran d’une fenêtre temporairement nonaffichée.

Les fenêtres sont organisées en arbre au niveau interne dans le serveur X.La racine de l’arbre est la root window créée à l’initialisation du serveuret couvrant tout l’écran. Vulgairement, c’est le fond d’écran.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 620 / 803

Page 379: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.11 Copier / collerChapitre 21 • Système de multifenêtrage : X§21.11 • Copier / coller

Pour copier, on sélectionne avec le bouton gauche de la souris.Pour coller, on clique avec le bouton du milieu de la souris.

This is the text to select. All text around it is unselected.

All text around it is unselected.This is the text to select.

Modifiable.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 621 / 803

21 Système de multifenêtrage : X 21.12 Principe de personnalisation des clientsChapitre 21 • Système de multifenêtrage : X§21.12 • Principe de personnalisation des clients

Personnalisation via des ressourcesou des arguments de la ligne decommande :

$XFILESEARCHPATH

/usr/X11R6/lib/X11/app-defaults

Arguments de la ligne de commande

$HOME

$XUSERFILESEARCHPATH

$XAPPLRESDIR

$HOME/.Xdefaults

propriete RESOURCE_MANAGER (xrdb)

$XENVIRONMENT

$HOME/.Xdefaults-nom-hostou

ou

ou

ou

ou

ORDRE

DE

RECHERCHE

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 622 / 803

Page 380: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.13 Options de la ligne de commandeChapitre 21 • Système de multifenêtrage : X§21.13 • Options de la ligne de commande

Il y a des options standard pour la plupart des clients car leurprogrammation s’appuye sur une bibliothèque appelée « Xt ».

Exemples :

display :« -display cerise.example.com:0.0 »couleur des caractères :« -fg couleur »couleur de fond des fenêtres :« -bg couleur »caractères :« -fn font »dimensions et emplacement de la fenêtre :« -geometry WIDTH×HEIGHT±XOFF±YOFF »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 623 / 803

21 Système de multifenêtrage : X 21.13 Options de la ligne de commande

Retour sur l’option « -geometry WIDTH×HEIGHT±XOFF±YOFF » :+0+0 -0+0

-0-0+0-0

X

-450-200

X

Y Y

Y

XX

Y

+100+100 +600+100

+600-100+100-100

-450+150 -200+150

-200-200

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 624 / 803

Page 381: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.14 RessourcesChapitre 21 • Système de multifenêtrage : X§21.14 • Ressources

Une ressource = variable configuréedans un fichier ASCII (analogie :base de registres de Windows ouressources Macintosh)

4 niveaux de ressources :ressources définies par lesystèmeressources définies par le clientXressources définies par leserveur Xressources définies parl’utilisateur

$XFILESEARCHPATH

/usr/X11R6/lib/X11/app-defaults

Arguments de la ligne de commande

$HOME

$XUSERFILESEARCHPATH

$XAPPLRESDIR

$HOME/.Xdefaults

propriete RESOURCE_MANAGER (xrdb)

$XENVIRONMENT

$HOME/.Xdefaults-nom-hostou

ou

ou

ou

ou

ORDRE

DE

RECHERCHE

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 625 / 803

21 Système de multifenêtrage : X 21.14 Ressources

� Ressources définies par le système$XFILESEARCHPATH

/usr/X11R6/lib/X11/app-defaults

Arguments de la ligne de commande

$HOME

$XUSERFILESEARCHPATH

$XAPPLRESDIR

$HOME/.Xdefaults

propriete RESOURCE_MANAGER (xrdb)

$XENVIRONMENT

$HOME/.Xdefaults-nom-hostou

ou

ou

ou

ou

ORDRE

DE

RECHERCHE

Traditionnellement « /usr/X11R6/lib/X11/app-defaults/ ».

Ce répertoire regroupe les fichiers correspondants aux classes desapplications. Par exemple « XTerm » pour l’application X « xterm »,« Bitmap » pour l’application X « bitmap », etc.

Ces ressources sont lues par les clients X qui tournent sur la machine de cerépertoire.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 626 / 803

Page 382: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.14 Ressources

� Ressources définies par le client X$XFILESEARCHPATH

/usr/X11R6/lib/X11/app-defaults

Arguments de la ligne de commande

$HOME

$XUSERFILESEARCHPATH

$XAPPLRESDIR

$HOME/.Xdefaults

propriete RESOURCE_MANAGER (xrdb)

$XENVIRONMENT

$HOME/.Xdefaults-nom-hostou

ou

ou

ou

ou

ORDRE

DE

RECHERCHE

Traditionnellement « $HOME ».

Ce mécanisme s’applique aux applications X développées avec la librairie« Xt ». Le fichier de ressources porte le nom de l’application. Par exemple« XTerm » pour l’application X « xterm », « Bitmap » pour l’applicationX « bitmap », etc.

Ces ressources sont lues par les clients X qui tournent sur la machine de cerépertoire.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 627 / 803

21 Système de multifenêtrage : X 21.14 Ressources

� Ressources définies par le serveur X$XFILESEARCHPATH

/usr/X11R6/lib/X11/app-defaults

Arguments de la ligne de commande

$HOME

$XUSERFILESEARCHPATH

$XAPPLRESDIR

$HOME/.Xdefaults

propriete RESOURCE_MANAGER (xrdb)

$XENVIRONMENT

$HOME/.Xdefaults-nom-hostou

ou

ou

ou

ou

ORDRE

DE

RECHERCHE

Des ressources peuvent être placées dans une base de données dans lamémoire du serveur X.

Ces ressources sont donc communes à tous les clients de ce serveur X. Lesclients les lisent lors de leur démarrage, plus après.

La commande « xrdb » sert à manipuler cette base de données enmémoire dans le serveur X.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 628 / 803

Page 383: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.14 Ressources

� Ressources définies par l’utilisateur$XFILESEARCHPATH

/usr/X11R6/lib/X11/app-defaults

Arguments de la ligne de commande

$HOME

$XUSERFILESEARCHPATH

$XAPPLRESDIR

$HOME/.Xdefaults

propriete RESOURCE_MANAGER (xrdb)

$XENVIRONMENT

$HOME/.Xdefaults-nom-hostou

ou

ou

ou

ou

ORDRE

DE

RECHERCHE

Ce mécanisme permet d’avoir un fichier propre à plusieurs systèmes mêmesi le homedir est partagé (via NFS) entre ces systèmes.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 629 / 803

21 Système de multifenêtrage : X 21.14 Ressources

� Syntaxes des ressources

Syntaxes :« nom-application.attribut: valeur »« classe.nom.sous-nom...attribut: valeur »

Par exemple :

xterm.background: black

xterm.foreground: yellow

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 630 / 803

Page 384: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.14 Ressources

Un client X est construit autourd’un arbre de « widgets » (boutons,dropdown menus, etc.) fournis parles bibliothèques de programmation.

⇒ On a en fait une arborescence deressources.

Programme « editres » pour lesmanipuler.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 631 / 803

21 Système de multifenêtrage : X 21.14 Ressources

La syntaxe utilise des caractères « joker » :

caractère « . » : séparateur des éléments dans la définition de laressourcecaractère « * » : permet de remplacer un ou plusieurs éléments dansla définition de la ressourcecaractère « ? » : permet de remplacer un et un seul élément dans ladéfinition de la ressource

Par exemple :

xterm.background: black

xterm.foreground: yellow

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 632 / 803

Page 385: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.14 Ressources

Notion de :classeapplication de la classefenêtre d’une application

C’est la ressource la plus précise qui est prise en compte.

Par exemple :« mon-application.sous-fenêtre.side.background: yellow »prime sur « mon-application.sous-fenêtre.background: blue »qui prime sur « mon-application.background: red »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 633 / 803

21 Système de multifenêtrage : X 21.14 Ressources

� xrdb

Rappel :$XFILESEARCHPATH

/usr/X11R6/lib/X11/app-defaults

Arguments de la ligne de commande

$HOME

$XUSERFILESEARCHPATH

$XAPPLRESDIR

$HOME/.Xdefaults

propriete RESOURCE_MANAGER (xrdb)

$XENVIRONMENT

$HOME/.Xdefaults-nom-hostou

ou

ou

ou

ou

ORDRE

DE

RECHERCHE

Des ressources peuvent être placées dans une base de données dans lamémoire du serveur X.

La commande « xrdb » sert à manipuler cette base de données enmémoire dans le serveur X.

xrdb = X server Resource DataBase utility

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 634 / 803

Page 386: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.14 Ressources

Syntaxes :« xrdb -query » : liste les ressources actuelles du serveur X« xrdb -merge fichier » : fusionne un fichier de ressources avecles ressources du serveur X« xrdb -load fichier » : écrase les ressources du serveur X parcelles du fichier indiqué« xrdb -remove » : efface les ressources du serveur X« xrdb -symbols » : affiche la liste des symboles prédéfinis (voirci-dessus pour la partie CPP)

« xrdb » utilise « cpp » du langage C. Donc le fichier de ressources àcharger peut contenir les directives classiques de CPP :

« #include »« #ifdef »etc.

Intérêt : un seul fichier mais pouvant traiter plusieurs cas de figures.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 635 / 803

21 Système de multifenêtrage : X 21.14 Ressources

Par exemple :

#ifndef COLOR

XTerm*cursorColor: black

XTerm*pointerColor: black

#else /* COLOR is DEFINED :-) */

XTerm*cursorColor: red

XTerm*pointerColor: red

#endif

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 636 / 803

Page 387: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.15 CouleursChapitre 21 • Système de multifenêtrage : X§21.15 • Couleurs

On peut désigner une couleur sous un nom symbolique :« /usr/X11R6/lib/X11/rgb.txt » définit ainsi 738 couleurs (les nomsne sont pas forcément parlants). Par exemple : « Pink »

On peut aussi donner une couleur via ses composantes Rouge Vert Bleu(RGB en anglais) sous la forme « rgb:red/green/blue ». Ainsi « Pink »équivaut à « rgb:255/192/203 ».

Ancienne syntaxe supportée pour compatibilité :

#RGB (4 bits each)

#RRGGBB (8 bits each)

#RRRGGGBBB (12 bits each)

#RRRRGGGGBBBB (16 bits each)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 637 / 803

21 Système de multifenêtrage : X 21.15 Couleurs

A partir de X11R5, adoption de la gestion des couleurs via X ColorManagement System (XCMS). Le fichier« /usr/X11R6/lib/X11/Xcms.txt » décrit des couleurs.Par exemple :

XCMS_COLORDB_START 0.1

red CIEXYZ:0.3811/0.2073/0.0213

green CIEXYZ:0.3203/0.6805/0.1430

blue CIEXYZ:0.2483/0.1122/1.2417

aquamarine CIEXYZ:0.5512/0.7909/0.9759

cadet blue CIEXYZ:0.2218/0.2815/0.4708

cornflower blue CIEXYZ:0.3400/0.3109/1.1067

navy blue CIEXYZ:0.0478/0.0216/0.2392

navy CIEXYZ:0.0478/0.0216/0.2392

brown CIEXYZ:0.1333/0.0772/0.0217

gray0 TekHVC:0.0/0.0/0.0

gray10 TekHVC:0.0/10.0/0.0

gray20 TekHVC:0.0/20.0/0.0

...

gray80 TekHVC:0.0/80.0/0.0

gray90 TekHVC:0.0/90.0/0.0

gray100 TekHVC:0.0/100.0/0.0

XCMS_COLORDB_END

Commande associée : « xcmsdb »c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 638 / 803

Page 388: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.16 Polices de caractèresChapitre 21 • Système de multifenêtrage : X§21.16 • Polices de caractères

Les fontes ont des noms très détaillés. Par exemple :

-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1

« adobe » : concepteur de la police« courier » : famille de la police« medium » : graisse (bold, medium, extra bold, light, etc.)« r » : angle (roman, italic, etc.)« normal » : largeur (normal, narrow, etc.)vide : style complémentaire« 10 » : hauteur en pixels« 100 » : hauteur en points (un point = 1/72e de pouce)« 75 » : résolution horizontale de conception de la police« 75 » : résolution verticale de conception de la police« m » : espacement (p = proportionnel, m = monospace, etc.)« 60 » : largeur moyenne en 1/10e de pixel« iso8859-1 » : jeu de caractères

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 639 / 803

21 Système de multifenêtrage : X 21.16 Polices de caractères

Plusieurs formats sont possibles. Liste non exhaustive :BDF (Bitmap Distribution Format),SNF (Server Natural Font),PCF (Portable Compiled Font),Type1 PostScript depuis X11R6,True Type (http://www.freetype.org/),PEX,Speedo

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 640 / 803

Page 389: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.16 Polices de caractères

On peut utiliser la commande « xlsfonts » pour avoir la liste des fontesutilisables sur son poste X.

Les polices sont utilisables via les ressources. Par exemple :

XTerm*Font: 7x13bold

Emacs*paneFont: -adobe-times-medium-r-normal--14-140-75-75-p-74-iso8859-1

Les polices sont utilisables via la ligne de commande. Par exemple :

% xfd -fn 9x15bold

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 641 / 803

21 Système de multifenêtrage : X 21.16 Polices de caractères

Les fontes sont stockées dans l’arborescence« /usr/X11R6/lib/X11/fonts/ » contenant plusieurs sous répertoiresdont :

« 75dpi/ » : polices de résolution de 75 dpi« 100dpi/ » : polices de résolution de 100 dpi« misc/ » : polices diverses

Notion de font path.

Configuration du font path via la commande « xset » :« xset -q »« xset +fp /chemin/vers/répertoire/de/fontes/ »« xset fp+ /chemin/vers/répertoire/de/fontes/ »« xset -fp /chemin/vers/répertoire/de/fontes/ »« xset fp rehash »

L’ordre des répertoires est significatif.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 642 / 803

Page 390: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.17 Répertoires de polices de caractèresChapitre 21 • Système de multifenêtrage : X§21.17 • Répertoires de polices de caractères

Un répertoire de polices de caractères a une structure précise :

% ls /usr/X11R6/lib/X11/fonts/misc10x20.pcf.Z Screen6.pcf.Z clR8x10.pcf.Z

12x24.pcf.Z Screen7.pcf.Z clR8x12.pcf.Z

12x24rk.pcf.Z Serif10.pcf.Z clR8x13.pcf.Z

5x7.pcf.Z Serif11.pcf.Z clR8x14.pcf.Z

5x8.pcf.Z Serif12.pcf.Z clR8x16.pcf.Z

6x10.pcf.Z Serif14.pcf.Z clR8x8.pcf.Z

6x12.pcf.Z Serif16.pcf.Z clR9x15.pcf.Z

6x13.pcf.Z clB6x10.pcf.Z cursor.pcf.Z

6x13B.pcf.Z clB6x12.pcf.Z deccurs.pcf.Z

6x9.pcf.Z clB8x10.pcf.Z decsess.pcf.Z

7x13.pcf.Z clB8x12.pcf.Z fonts.alias7x13B.pcf.Z clB8x13.pcf.Z fonts.dir...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 643 / 803

21 Système de multifenêtrage : X 21.17 Répertoires de polices de caractères

Fichier « fonts.dir » : ce fichier contient la liste des polices durépertoire ; plus exactement des lignes au format :« fichier-de-la-police nom-X-de-la-police ». Par exemple :

...

6x13.pcf.Z -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1

...

Fichier « fonts.alias » : ce fichier contient des alias plus parlant que lesnoms complets des polices X. Par exemple :

...

fixed "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1"

...

L’ajout d’une fonte ne se résume pas à copier le fichier de la fonte dans lerépertoire !

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 644 / 803

Page 391: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.17 Répertoires de polices de caractères

Pour ajouter une police, il faudra faire appel à la commande« mkfontdir » :

1 créer le répertoire des polices si nécessaire : « mkdir /tmp/fonts »2 copier la police dans le répertoire : « cp toto.pcf /tmp/fonts »3 créer le fichier « fonts.dir » : « mkfontdir »4 créer éventuellement des alias : « vi /tmp/fonts/fonts.alias »5 ajouter le nouveau répertoire à son font path :

« xset +fp /tmp/fonts/ » ; Attention : il faut le slash final« /tmp/fonts/ »

6 reconstituer la liste à jour des polices X : « xset fp rehash »7 vérification des polices disponibles : « xlsfonts » ou « xset -q »8 utilisation des nouvelles polices :

« application-X.exe -fn nouvelle-fonte »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 645 / 803

21 Système de multifenêtrage : X 21.18 Serveur de polices de caractèresChapitre 21 • Système de multifenêtrage : X§21.18 • Serveur de polices de caractères

L’ajout de polices X sur un parc de machines est une opération pénible(voir transparent précédent).

⇒ Apparition d’un mécanisme de serveur de fontes X.

Administration simplifiée car centralisation des polices.

En X11R5 : programme « fs ».

En X11R6 et après : programme « xfs ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 646 / 803

Page 392: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.18 Serveur de polices de caractères

Syntaxe : « xfs [-config fichier-config] [-port n] »

Par défaut le fichier de configuration est « /etc/X11/fs/config ».

Par défaut le port TCP utilisé est 7100 (voir « /etc/services »).

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 647 / 803

21 Système de multifenêtrage : X 21.18 Serveur de polices de caractères

Exemple de fichier de configuration :

# allow a max of 10 clients to connect to this font server

client-limit = 10

catalogue = /chemin/vers/fonts/ibm,

/chemin/vers/fonts/ooffice,

/chemin/vers/fonts/cmps,

/chemin/vers/fonts/mathematica,

/chemin/vers/fonts/msttcorefonts,

/usr/X11R6/lib/X11/fonts/korean,

/usr/X11R6/lib/X11/fonts/misc:unscaled,

/usr/X11R6/lib/X11/fonts/75dpi:unscaled,

/usr/X11R6/lib/X11/fonts/100dpi:unscaled,

/usr/X11R6/lib/X11/fonts/Type1,

/usr/X11R6/lib/X11/fonts/cyrillic,

...

# how to log errors

use-syslog = on

# don’t listen to TCP ports by default for security reasons

# no-listen = tcp

port = 7100

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 648 / 803

Page 393: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.18 Serveur de polices de caractères

Utilisation d’un serveur de fontes par :« xset +fp tcp/xfs.example.com:7100 »

Liste des polices d’un serveur de fontes par :« fslsfonts -server tcp/xfs.example.com:7100 »

Test du serveur serveur de fontes par :« fsinfo -server tcp/xfs.example.com:7100 »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 649 / 803

21 Système de multifenêtrage : X 21.19 Gestionnaire de fenêtres, window managerChapitre 21 • Système de multifenêtrage : X§21.19 • Gestionnaire de fenêtres, window manager

Gestionnaire de fenêtres ≡ Window Manager ≡ client X au même titreque les autres. Il permet de réaliser les choses suivantes :

déplacer ou redimensionner une fenêtreiconifier ou non une fenêtrefaire passer au premier ou au dernier plan une fenêtredécorer les fenêtrescréer ou détruire les fenêtreslancer ou terminer des applications

L’emploi d’un gestionnaire de fenêtres n’a rien d’obligatoire mais ce seraitse priver de beaucoup de fonctionnalités.

Il ne faut pas confondre le gestionnaire de fenêtres avec le serveur X.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 650 / 803

Page 394: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.19 Gestionnaire de fenêtres, window manager

Quelques exemples de fenêtres décorées par des window managers :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 651 / 803

21 Système de multifenêtrage : X 21.20 Configuration de la session X, $HOME/.xsession, FAILSAFEChapitre 21 • Système de multifenêtrage : X§21.20 • Configuration de la session X, $HOME/.xsession, FAILSAFE

Sur une station avec une mire d’accueil graphique, le script« $HOME/.xsession » est lancé lors de la connexion et il configurel’environnement graphique de l’utilisateur :

applications X à lancer automatiquement au démarrage (par exempledes terminaux)réglages du clavierréglages de la sourisetc.

La durée de vie de la session sous X est celle du script« $HOME/.xsession ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 652 / 803

Page 395: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.20 Configuration de la session X, $HOME/.xsession, FAILSAFE

Forme générale du script « $HOME/.xsession » :

#!/bin/sh

client-X-1 &client-X-2 &...

appliX <--- pas de &

Le dernier client X n’est pas lancé en tâche de fond (sinon le script s’arrêtetout de suite et la session se ferme brutalement).

En général, le dernier client est le window manager.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 653 / 803

21 Système de multifenêtrage : X 21.20 Configuration de la session X, $HOME/.xsession, FAILSAFE

S’il y a des erreurs, les messages de celles-ci sont écrits dans le fichier« $HOME/.xsession-errors ».

En cas d’erreur grave dans « $HOME/.xsession » empêchant ledémarrage de la session X, utiliser le mode FailSafe :

disponible via les menus de la fenêtre d’accueil de KDEdisponible via les menus de la fenêtre d’accueil de GNOMEdans l’environnement de base X :

1 entrer le nom de login2 valider par la touche Retour3 entrer le mot de passe4 valider par la touche F1 et non pas par la touche Retour

Il apparait alors un simple xterm sans window manager. L’utiliser pourcorriger les erreurs indiquées dans le fichier« $HOME/.xsession-errors ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 654 / 803

Page 396: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.20 Configuration de la session X, $HOME/.xsession, FAILSAFE

Version KDE du FAILSAFE : via un menu :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 655 / 803

21 Système de multifenêtrage : X 21.20 Configuration de la session X, $HOME/.xsession, FAILSAFE

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 656 / 803

Page 397: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.20 Configuration de la session X, $HOME/.xsession, FAILSAFE

Pour lancer KDE, mettre au minimum dans son fichier« $HOME/.xsession »

#!/bin/sh

PATH=/usr/X11R6/bin:/usr/local/bin:$PATH

export PATH

startkde

Pour lancer GNOME, mettre au minimum dans son fichier« $HOME/.xsession »

#!/bin/sh

PATH=/usr/X11R6/bin:/usr/local/bin:$PATH

export PATH

enlightment &gnome-session

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 657 / 803

21 Système de multifenêtrage : X 21.21 Environnements CDE, KDE, GNOMEChapitre 21 • Système de multifenêtrage : X§21.21 • Environnements CDE, KDE, GNOME

Objectif avoué : fournir aux utilisateurs un environnement comparable aubureau de Windows, pratique, configurable à souhait

Plusieurs environnements «sympatiques» :CDE : cf « http://www.cde.com »KDE : cf « http://www.kde.org »GNOME : cf « http://www.gnome.org »

CDE quasi mort.

Guerre entre KDE et GNOME.

SUN a adopté GNOME.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 658 / 803

Page 398: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.21 Environnements CDE, KDE, GNOME

� CDE :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 659 / 803

21 Système de multifenêtrage : X 21.21 Environnements CDE, KDE, GNOME

� KDE :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 660 / 803

Page 399: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.21 Environnements CDE, KDE, GNOME

� GNOME :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 661 / 803

21 Système de multifenêtrage : X 21.21 Environnements CDE, KDE, GNOME

Revers de la médaille : complexité de l’environnement par rapport à ce quel’on faisait avant.

⇒ Impossible de configurer manuellement l’environnement.

Par exemple l’environnement graphique GNOME utilise une arborescencecomplexe de fichiers utilisateur :

% du $HOME/.gnome*22 .gnome/accels

18 .gnome/panel.d/default/launchers

38 .gnome/panel.d/default

40 .gnome/panel.d

2 .gnome/apps

2 .gnome/application-info

132 .gnome

14 .gnome-desktop

6 .gnome_private/panel.d/default

8 .gnome_private/panel.d

10 .gnome_private

2 .gnomerc-errors

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 662 / 803

Page 400: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.21 Environnements CDE, KDE, GNOME

Par exemple l’environnement graphique GNOME lance de nombreuxprocess lors d’une session X :% ps -axPID TT STAT TIME COMMAND

...

203 ?? R 53:03.26 X :0 -nolisten tcp (XFree86)

214 ?? Ss 0:00.85 gnome-smproxy --sm-config-prefix /.gnome-smproxy-kumf226 ?? Ss 0:05.55 /usr/X11R6/bin/sawfish --sm-client-id default2 --sm-p228 ?? S 0:03.47 xscreensaver -nosplash275 ?? Ss 0:18.31 panel --sm-config-prefix /panel.d/default-tZvCrQ/ --s277 ?? Ss 0:18.97 nautilus --sm-config-prefix /nautilus-DXsk2u/ --sm-cl280 ?? Is 0:00.02 gnome-name-service282 ?? I 0:00.28 /usr/X11R6/bin/gconfd-1 12285 ?? Is 0:00.85 oafd --ac-activate --ior-output-fd=16290 ?? Ss 0:01.16 tasklist_applet --activate-goad-server tasklist_apple292 ?? Ss 0:01.24 deskguide_applet --activate-goad-server deskguide_app300 ?? Is 0:00.01 /bin/sh -c gnome-terminal --use-factory --start-facto301 ?? R 0:13.20 gnome-terminal --use-factory --start-factory-server303 ?? I 0:00.01 gnome-pty-helper1047 ?? Is 0:00.22 oafd --ac-activate --ior-output-fd=22191 v0 I+ 0:00.00 /bin/sh /usr/X11R6/bin/startx

202 v0 I+ 0:00.00 xinit /users/sri/besancon/.xinitrc -- -nolisten tcp

208 v0 I 0:00.00 /bin/sh /users/sri/besancon/.xinitrc

209 v0 I 0:00.40 gnome-session...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 663 / 803

21 Système de multifenêtrage : X 21.21 Environnements CDE, KDE, GNOME

Le recours à un Control Center est indispensable :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 664 / 803

Page 401: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.22 Réinitialisation des environnements KDE / GnomeChapitre 21 • Système de multifenêtrage : X§21.22 • Réinitialisation des environnements KDE / Gnome

Que faire si votre environnement KDE ou GNOME ne fonctionne plus ?

Lancez la commande suivante spécifique à la Formation Permanente :

% ~besancon/resetX

et suivez les instructions.

Attention : cela effacera toute configuration personnalisée de KDEou de GNOME !

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 665 / 803

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, sshChapitre 21 • Système de multifenêtrage : X§21.23 • Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

Rappel : principe client / serveur :

On veut pouvoir contrôler quels clients X peuvent se connecter auserveur X.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 666 / 803

Page 402: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

� Contrôle d’accès par machine

La commande « xhost » permet de gérer de façon basique les accès auserveur X :

% xhostaccess control enabled, only authorized clients can connect

% xhost + machine2.example.commachine2.example.com being added to access control list

% xhostaccess control enabled, only authorized clients can connect

INET:machine2.example.com

% xhost - machine2.example.commachine2.example.com being removed from access control list

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 667 / 803

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

En pratique :

% echo $DISPLAYmachine1.example.com:0.0

% xhost + machine2.example.com

% rlogin machine2.example.com

$ DISPLAY=machine1.example.com:0.0

$ export DISPLAY

$ clientX <- affichage des fenêtres du client X distant

...

$ exit

% xhost - machine1.example.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 668 / 803

Page 403: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

Défauts de la commande « xhost » :

Le principal défaut de la commande xhost est d’autoriser unemachine et donc tout utilisateur y étant connecté.Si l’utilisateur fait « xhost + » sans comprendre ⇒ tout client Xpeut se connecter ! Dangereux !

Exemples :lecture / espionnage du clavier ≡ spywarePar exemple récupération de mots de passe lors de «su root»Cf « ftp://ftp.giga.or.at/pub/hacker/unix/xscan.tar.gz »destruction de fenêtres par l’utilisation de « xkill » par exemplecapture d’écran par l’utilisation de « xwd -root »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 669 / 803

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

� Contrôle d’accès par utilisateur : MAGIC-COOKIE, xauth

Solution au problème de l’autorisation XHOST : emploi d’un cookie,pseudo secret connu du serveur à rappeler lors d’une demande deconnexion au serveur X.

Serveur X

réseau

xdm

transmission du cookie au démarrage

démarrage du terminal X : lancement de X −direct$HOME/.Xauthority

copie du cookie2 2bis

1

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 670 / 803

Page 404: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

Qui peut connaître le cookie ?Celui qui peut accèder au contenu du fichier « $HOME/.Xauthority »

Serveur X

magic cookie A

réseau

~alice/.XauthorityTransmission magic cookie A

Transmission magic cookie B~bob/.Xauthority

CLIENT X 1

CLIENT X 2

ACCEPTÉ

REFUSÉ

⇒ La sécurité de X repose dans ce cas sur la sécurité du filesystem. D’où :

% ls -l $HOME/.Xauthority-rw------- 1 besancon software 1510 Dec 17 19:12 $HOME/.Xauthority

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 671 / 803

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

Que faire si « $HOME/.Xauthority » n’est pas disponible sur la machinedistante ?

⇒ Utiliser la commande « xauth » pour les opérations suivantes :1 extraction du MAGIC-COOKIE du DISPLAY de la machine locale

(login local = « besancon »)2 copie sur la machine distante du MAGIC-COOKIE

(le login distant peut être différent = « tbesancon »)3 fusion sur la machine distante du MAGIC-COOKIE au fichier

« $HOME/.Xauthority » distantce qui se traduit par l’une de ces commandes :

% xauth extract - $DISPLAY | rsh host2.example.com -l tbesancon xauthmerge -

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 672 / 803

Page 405: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

Défauts du mécanisme du MAGIC-COOKIE : le cookie transite en clair surle réseau et peut donc être récupéré par un mouchard.

⇒ Pas de réponse simple à ce problème en dehors du protocoleSUN-DES-1 mais très peu répandu (chiffrement des données d’autorisationpar DES et transfert par Secure RPC ce qui implique NIS = compliqué)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 673 / 803

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

� SSH et MAGIC-COOKIE

Défaut de la commande « xauth » : syntaxe lourde lorsque le fichier« $HOME/.Xauthority » n’est pas disponible sur la machine distante ;rappel :

% xauth extract - $DISPLAY | rsh host2.example.com -l tbesancon xauthmerge -

Solution : SSH (voir « http://www.openssh.org »)

SSH incorpore de base un mécanisme de transmission automatique duDISPLAY et du cookie associé avec sécurisation de la liaison parchiffrement de la communication.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 674 / 803

Page 406: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.23 Sécurité : xhost, MAGIC-COOKIE, xauth, ssh

$DISPLAY = stationA:0.0

client X

ChiffrementDechiffrement

ChiffrementDechiffrement

PSEUDO SERVEUR X

PSEUDO $DISPLAY

= stationB:11.0

client X

SSH

PSEUDO CLIENT X

SSH

réseau

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 675 / 803

21 Système de multifenêtrage : X 21.24 X Display Manager ProtocolChapitre 21 • Système de multifenêtrage : X§21.24 • X Display Manager Protocol

XDMCP : X Display Management Control ProtocolX Display Manager (processus « xdm ») est un client qui contrôle laconnexion de l’utilisateur et lance sa session.Visuellement, c’est une fenêtre d’authentification :

cerise.example.com

Login:

Password:

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 676 / 803

Page 407: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

On a plusieurs programmes XDM disponibles :« xdm » : programme de base historique« kdm » : version KDE améliorée de XDM« gdm » : version GNOME améliorée de XDM

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 677 / 803

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

Programmes plus ou moins complexes, riches, personnalisables :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 678 / 803

Page 408: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

Plusieurs fichiers et shell-scripts de configuration de XDM :

TakeConsole

Xsetup_0

Xservers

Xaccess

Xresources

GiveConsole

Xsession

xdm-config

.xsession

.Xresources

/usr/X11R6/lib/X11/xdm $HOME

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 679 / 803

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

� fichier « xdm-config »

C’est un fichier de ressources pour le programme « xdm ».

Il indique les autres fichiers de configuration ou des shell scripts.

� fichier « Xservers »

A l’origine indique la liste des serveurs X à gérer ; à partir de X11R4, leprotocole XDMCP permet à un DISPLAY de contacter XDM et de se fairegérer

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 680 / 803

Page 409: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

� fichier « Xaccess »

Il définit la liste des serveurs X autorisés à se connecter à XDM ; unserveur X émet une requête de gestion d’un de ces types :

requête « direct »requête « indirect »requête « broadcast »

Syntaxe utilisant des metacharacters :« *.example.com », « !cerise.example.com », etc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 681 / 803

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

Accès direct :

X

Login:

Requete XDMCP directe

xdm

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 682 / 803

Page 410: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

Accès indirect :

X

Login:

Requete XDMCP indirecte

xdm1 xdm2

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 683 / 803

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

Accès broadcast :

X

Login:

Requete XDMCP broadcast

xdm3

xdm2

xdm1

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 684 / 803

Page 411: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

Possibilité d’avoir un chooser (sélection de hôtes UNIX) :liste explicite d’hôtes :« ncd.example.com CHOOSER unix1.example.com unix2.example.com »

liste par broadcast d’hôtes :« ncd.example.com CHOOSER BROADCAST »

X

Liste predefinieou broadcast

X

chooser

Requete XDMCP indirecte

xdm

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 685 / 803

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

� fichier « Xresources »

Définit les ressources utilisés par la fenêtre de connexion.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 686 / 803

Page 412: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

� fichiers « GiveConsole », « TakeConsole »

Ce sont des shells scripts.

Ils définissent les opérations système à faire à la connexion et à ladéconnexion de l’utilisateur. Par exemple :

rendre l’utilisateur propriétaire de « /dev/console »rendre l’utilisateur propriétaire de « /dev/fb »rendre l’utilisateur propriétaire du périphérique de la carte son

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 687 / 803

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

� fichier « Xsession »

Définit la session de l’utilisateur après sa connexion.

En général, c’est un shell script qui appelle le script « $HOME/.xsession »de l’utilisateur, qui charge les ressources de l’utilisateur, etc.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 688 / 803

Page 413: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

Par exemple sur SUN SOLARIS :

#!/bin/sh

# redirect errors to a file in user’s home directory if we can

for errfile in "$HOME/.xsession-errors" "${TMPDIR-/tmp}/xses-$USER" "/tmp/xses-$USER"

do

if ( cp /dev/null "$errfile" 2> /dev/null )

then

chmod 600 "$errfile"

exec > "$errfile" 2>&1

break

fi

done

case $# in

1)

case $1 in

failsafe)

exec xterm -geometry 80x24-0-0

;;

esac

esac

Suite sur le transparent suivant. . .c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 689 / 803

21 Système de multifenêtrage : X 21.24 X Display Manager Protocol

Suite. . .

startup=$HOME/.xsession

resources=$HOME/.Xresources

if [ -f "$startup" ]; then

exec "$startup"

else

if [ -f "$resources" ]; then

xrdb -load "$resources"

fi

twm &

exec xterm -geometry 80x24+10+10 -ls

fi

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 690 / 803

Page 414: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminauxChapitre 21 • Système de multifenêtrage : X§21.25 • Terminaux X / Clients légers X / Autres terminaux

� Terminaux X

Un terminal X est un poste de travail graphique :offrant le système graphique Xsans système d’exploitation complexe à gérer et à maintenirsimple à configurer

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 691 / 803

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Fonctionnement :

boot du terminalrequête DHCP ou BOOTP qui retourne l’adresse IP et l’adresseTFTP du serveur X à télécharger :host droopy.example.com {

hardware ethernet 00:80:96:04:71:63;

fixed-address 192.168.1.69;

filename "/hds/netOS/tX/prom/common/X.hds";

}

téléchargement par TFTP du serveur X du terminal et de saconfigurationlancement du serveur X qui accroche le XDM d’un serveur précisé parla configuration téléchargée

Parfois, NFS est utilisable à la place des téléchargements TFTP.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 692 / 803

Page 415: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Après 2000, on constate :

coût élevé d’un terminal X ; parfois plus cher qu’un poste PCWindows multimédiadésaffection des constructeurs (HDS, NCD ont fermé boutique)manque de périphériques supportés ; pas de floppy, pas de son, pas deUSB. . .

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 693 / 803

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

� Terminaux légers

Un «vrai» terminal X est maintenant trop cher.Un «vrai» terminal X est maintenant trop limitatif : pas de multimédia

Solution : le client léger

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 694 / 803

Page 416: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Le client léger : ni un PC, ni un terminal X :

succédané d’architecture de PC x86faible consommation électrique ⇒ pas de ventilateur ⇒ silencieuxmémoire flash (pas de disque dur local)système d’exploitation de type LINUX minimaliste ou Windows CE ⇒support des périphériques récents (USB, wake-on-lan, . . .)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 695 / 803

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

� Autres terminaux : Sunray

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 696 / 803

Page 417: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 697 / 803

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Caractéristiques du SUNRAY :

Pas de disque durPas d’applications localesPas de configurationPas de système d’exploitationPas de barrette mémoirePas de ventilateurPas de paramétrage particulierIl est 10 fois plus léger qu’un PC et 12 fois moins volumineuxIl peut même s’intégrer dans un écran cathodique 17 pouces ou unécran plat de 15 pouces...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 698 / 803

Page 418: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Avantages :

Instantané, constant et simpleGestion centraliséeJamais besoin de mise à jourSilencieux16 millions de couleurs (24 bits)Pas de setupDonc, pas de dé-setupPas de modifications de vos applicationsAUCUN tranfert de fichier au boot

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 699 / 803

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Caractéristiques hardware :

CPU Sparc1280 x 1024 @ 76 Hzframe buffer 24 bits10/100Mb EthernetAccès a Solaris , X11, Java , ICAfonctionnalités multimédiaLecteur de carte à puceE/S audio qualité CDEntrée vidéo NTSC/PALSupport USB ( 4 ports ) mais limité en pratique. . .

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 700 / 803

Page 419: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Architecture réseau :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 701 / 803

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Architecture logicielle :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 702 / 803

Page 420: Administration UNIX - Cours Jussieu - 2009-2010

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Architecture logicielle (2) :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 703 / 803

21 Système de multifenêtrage : X 21.25 Terminaux X / Clients légers X / Autres terminaux

Cohabitation avec Windows possible :

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 704 / 803

Page 421: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 22

Langage SQL

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 705 / 803

22 Langage SQL 22.1 IntroductionChapitre 22 • Langage SQL§22.1 • Introduction

SQL ≡ Structured Query Language

SQL permet :la définition et la modification du schéma de la base de donnéesla manipulation des donnéesl’interrogation des donnéesle contrôle des accès à la base

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 706 / 803

Page 422: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.2 Définition des exemplesChapitre 22 • Langage SQL§22.2 • Définition des exemples

Voici les relations qui seront utilisées dans ce cours :

Table AVIONNumav Capacite Type Entrepot

14 25 A400 Garches345 75 B200 Maubeuge

Table PILOTEMatricule Nom Ville Age Salaire

1 Figue Cannes 45 280042 Lavande Touquet 24 11758

Table PASSAGERNumtab Nomab

1 Nifance2 Tearice

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 707 / 803

22 Langage SQL 22.2 Définition des exemples

Table VOLNumvol Heure_depart Heure_arrivee Ville_depart Ville_arrivee

AL12 08-18 09-12 Paris LillesAF8 11-20 23-54 Vaux Rio

Table DEPARTNumvol Date_dep Numav Matricule

AL12 31-DEC-95 14 1AL12 19-DEC-95 342 2

Table RESERVATIONNumab Numvol Date_sep

1 AL12 31-DEC-952 AL12 31-DEC-95

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 708 / 803

Page 423: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.3 Description des donnéesChapitre 22 • Langage SQL§22.3 • Description des données

� Création d’une relation

CREATE TABLE Pilote (

pl# Number(4),

plnom char(20),

adresse char(30)

) ;

� Création d’une relation avec contraintes d’intégrité

CREATE TABLE Pilote (

pl# Number(4) not null,

plnom char(20),

adresse char(30)

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 709 / 803

22 Langage SQL 22.3 Description des données

� Création d’index

CREATE UNIQUE INDEX IPL#

ON Pilote(pl#);

� Suppression d’une relation

DROP TABLE Pilote ;

� Modification du schéma d’une relation

ALTER TABLE Pilote ADD ( age number(2) );

ALTER TABLE Pilote MODIFY ( adresse char(50) );

ALTER TABLE Pilote MODIFY ( pl# not null );

� Création d’une vue

CREATE VIEW VoldeParis AS (

SELECT vol#, va, hd, ha

FROM Vol

WHERE vd=’Paris’

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 710 / 803

Page 424: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.4 Manipulation des donnéesChapitre 22 • Langage SQL§22.4 • Manipulation des données

� Insertion des données

INSERT INTO Pilote values (1, ’Antoine’, ’Annecy’) ;

INSERT INTO Pilote values (2, ’Arthur’, ’Adge’) ;

INSERT INTO Pilote values (3, ’Jean’, null) ;

� Suppression des données

DELETE FROM Pilote WHERE pl# = 1 ;

� Modification des données

UPDATE Pilote

SET adresse = ’Aurillac’

WHERE pl#=2 ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 711 / 803

22 Langage SQL 22.5 Contrôle des accèsChapitre 22 • Langage SQL§22.5 • Contrôle des accès

� Fin normale (validation) d’une transaction

COMMIT ;

L’instruction commit rend effectifs les changements effectués sur la base.Ils deviennent visibles aux autres utilisateurs.

� Annulation d’une transaction

ROLLBACK ;

L’instruction rollback défait toutes les modifications effectuées sur la basedepuis le début de la transaction.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 712 / 803

Page 425: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.6 Projection, RestrictionChapitre 22 • Langage SQL§22.6 • Projection, Restriction

� Principe

SELECT AVION.numav

FROM AVION

WHERE AVION.capacite > 200 ;

Projection seule :

SELECT AVION.numav

FROM AVION ;

Restriction seule :

SELECT AVION.*FROM AVION

WHERE AVION.capacite > 200 ;

Exercice 1 : Quel est l’âge du pilote de matricule 15 ?Exercice 2 : Quels sont les pilotes de cette compagnie aérienne ? (leurmatricule, leur nom, leur ville, leur âge et leur salaire)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 713 / 803

22 Langage SQL 22.6 Projection, Restriction

� Tri

Tri croissant : ORDER BY... ASC

Tri décroissant : ORDER BY... DESC

SELECT AVION.numav

FROM AVION

WHERE AVION.capacite > 200

ORDER BY AVION.numav DESC ;

� Suppression des doubles

SELECT DISTINCT AVION.numav

FROM AVION

WHERE AVION.capacite > 200 ;

� Omission du préfixe

SELECT numav

FROM AVION

WHERE capacite > 200 ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 714 / 803

Page 426: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.6 Projection, Restriction

� Emploi de variables

SELECT A.numav

FROM AVION A

WHERE A.capacite > 200 ;

Exercice 3 : Quels sont les types d’avions entreposés à Tarascon, avec leurcapacité, par ordre de capacités croissantes ?

� Prédicats dans le critère de sélection

Les prédicats disponibles :=, !=, >, <, >=, <=OR, AND, LIKE, NOT NULL, IN, NOT, BETWEEN X AND Y

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 715 / 803

22 Langage SQL 22.6 Projection, Restriction

SELECT numav

FROM AVION

WHERE capacite > 200

AND ( (ENTREPOT = ’Saint nom la Breteche’)

OR (ENTREPOT = ’Mantes la jolie’)

)

AND numav != 300 ;

SELECT numav

FROM AVION

WHERE entrepot in (’Saint nom la Breteche’, ’Mantes la jolie’)

AND capacite BETWEEN 200 AND 210

AND TYPE LIKE ’B_EING%’;

Exercice 4 : Quelles sont les villes ayant un nom commencant par ’L’ et oùun pilote de moins de 20 ans gagne plus de 20000 F ?Exercice 5 : Quels sont les numéros d’avions, avec leut entrepôt, nerésidant pas à Marolles-en-Hurepoix, ayant une capacité supérieure à 200 ?(donnés par ordre de numéros décroissants)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 716 / 803

Page 427: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.6 Projection, Restriction

� Les fonctions

Quelques fonctions disponibles :

fonction lower(a)

fonction soundex(a)

fonction abs(a)

fonction sqrt(a)

fonction length(a)

etc.

SELECT numav

FROM AVION

WHERE LOWER(ENTREPOT) = ’le vesiney’;

SELECT MATRICULE, NOM

FROM PILOTE

WHERE SOUNDEX(NOM) = SOUNDEX(’SINTEXUPERI’) ;

SELECT UPPER(NOM)

FROM PILOTE

WHERE ADRESSE = ’Cordillère des Andes’ ;

Exercice 6 : Quelles sont les villes d’où part un vol pour Ajaccio ? (donnerles résultats en majuscule)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 717 / 803

22 Langage SQL 22.6 Projection, Restriction

� Les agrégats

Quelques agrégats disponibles :

agrégat avg()agrégat count()agrégat max()agrégat min()

agrégat sum()agrégat stddev()agrégat variance()etc.

Exemple : Quel est le nombre d’avions ayant une capacité supérieure à200 ?

SELECT COUNT(NUMAV)

FROM AVION

WHERE CAPACITE > 200 ;

SELECT COUNT(DISTINCT NUMAV)

FROM AVION

WHERE CAPACITE > 200 ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 718 / 803

Page 428: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.6 Projection, Restriction

Exercice 7 : Quel est le nombre d’avions en service (ie dans la relationDEPART), le 19 décembre 1995 ?Exercice 8 : Quelle est la capacité moyenne des avions entreposés à PogoTogo ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 719 / 803

22 Langage SQL 22.7 Les requêtes imbriquéesChapitre 22 • Langage SQL§22.7 • Les requêtes imbriquées

� Prédicat d’existence

SELECT

FROM

WHERE EXISTS ( SELECT

FROM

WHERE

) ;

Exemple : Quels sont les pilotes qui habitent dans une ville où n’est baséaucun avion ?

SELECT PILOTE.NOM

FROM PILOTE

WHERE NOT EXISTS ( SELECT AVION.*FROM AVION

WHERE AVION.ENTREPOT = PILOTE.VILLE

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 720 / 803

Page 429: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.7 Les requêtes imbriquées

� Requête à l’intérieur du IN

Exemple : Quels sont les noms des pilotes qui habitent dans une ville oùsont localisés des avions de capacité supérieure à 250 ?

SELECT PILOTE.NOM

FROM PILOTE

WHERE VILLE IN ( SELECT ENTREPOT

FROM AVION

WHERE CAPACITE > 250

) ;

Exercice 9 : Exprimer la requête suivante avec un EXISTS : Quels sont lesnoms des pilotes qui habitent dans une ville où sont localisés des avions decapacité supérieure à 250 ?Exercice 10 : Exprimer la requête suivante avec un IN : Quels sont lesnoms des passagers ayant réservé pour le 1er avril 1996 ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 721 / 803

22 Langage SQL 22.8 La jointureChapitre 22 • Langage SQL§22.8 • La jointure

2 méthodes principales :prédicativerequêtes imbriquées

Exemple : Quels sont les noms des pilotes qui assurent un vol le vendredi13 octobre 1996 ?Prédicative :SELECT PILOTE.NOM

FROM PILOTE, DEPART

WHERE PILOTE.MATRICULE = DEPART.MATRICULE

AND DEPART.DAPE_SEP = ’13-10-95’;

Imbrication :SELECT NOM

FROM PILOTE

WHERE MATRICULE IN ( SELECT DEPART.MATRICULE

FROM MATRICULE

WHERE DATE_SEP = ’13-10-95’

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 722 / 803

Page 430: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.8 La jointure

Il y a de nombreuses autres façons d’exprimer une jointure.Par exemple :

SELECT PILOTE.NOM

FROM PILOTE

WHERE EXISTS ( SELECT *FROM DEPART

WHERE

PILOTE.MATRICULE = DEPART.MATRICULE

AND DEPART.DATE_DEP = ’13-10-95’

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 723 / 803

22 Langage SQL 22.8 La jointure

Exercice 11 : Quels sont les noms des pilotes qui assurent un vol levendredi 13 octobre 1995, sur un avion de capacité supérieure à 250 ?

de manière prédicativeà l’aide de requêtes imbriquées

Exercice 12 : Quelles sont les paires de pilotes (matricules) habitant dansla même ville ?Exercice 13 : Quels sont les noms des pilotes qui conduisent l’avion denuméro 666 ?Exercice 14 : Quels sont les noms des pilotes qui habitent dans la ville oùest entreposé l’avion 666 ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 724 / 803

Page 431: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.9 L’unionChapitre 22 • Langage SQL§22.9 • L’union

Quels sont les pilotes qui conduisent l’avion de numéro 666 OU quihabitent dans la ville où est entreposé l’avion 666 ?

SELECT NOM

FROM PILOTE, DEPART

WHERE PILOTE.MATRICULE = DEPART.MATRICULE

AND DEPART.NUMAV = 666

UNION

SELECT NOM

FROM PILOTE, AVION

WHERE PILOTE.VILLE = AVION.ENTREPOT

AND AVION.NUMAV = 666 ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 725 / 803

22 Langage SQL 22.10 L’intersectionChapitre 22 • Langage SQL§22.10 • L’intersection

Quels sont les pilotes qui conduisent l’avion de numéro 666 ET quihabitent dans la ville où est entreposé l’avion 666 ?

SELECT NOM

FROM PILOTE, DEPART

WHERE PILOTE.MATRICULE = DEPART.MATRICULE

AND DEPART.NUMAV = 666

INTERSECT

SELECT NOM

FROM PILOTE, AVION

WHERE PILOTE.VILLE = AVION.ENTREPOT

AND AVION.NUMAV = 666 ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 726 / 803

Page 432: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.11 La différenceChapitre 22 • Langage SQL§22.11 • La différence

Quels sont les pilotes qui conduisent l’avion de numéro 666 SAUF ceux quihabitent dans la ville où est entreposé l’avion 666 ?

SELECT NOM

FROM PILOTE, DEPART

WHERE PILOTE.MATRICULE = DEPART.MATRICULE

AND DEPART.NUMAV = 666

MINUS

SELECT NOM

FROM PILOTE, AVION

WHERE PILOTE.VILLE = AVION.ENTREPOT

AND AVION.NUMAV = 666 ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 727 / 803

22 Langage SQL 22.12 La divisionChapitre 22 • Langage SQL§22.12 • La division

Quels sont les pilotes qui conduisent tous les avions ?≡ Quels sont les pilotes tels que, quel que soit l’avion, ils le conduisent ?≡ Quels sont les pilotes tels que, quel que soit l’avion, il existe un départassuré par ce pilote sur cet avion ?≡ Quels sont les pilotes tels qu’il n’existe pas d’avion tel qu’il n’existe pasdépart de ce pilote sur cet avion ?

SELECT MATRICULE

FROM PILOTE

WHERE NOT EXISTS ( SELECT *FROM AVION

WHERE NOT EXISTS ( SELECT *FROM DEPART

WHERE DEPART.MATRICULE = PILOTE.MATRICULE

AND DEPART.NUMAV = AVION.NUMAV

)

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 728 / 803

Page 433: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.12 La division

Exercice 15 : Quels sont les passagers qui ont réservé sur tous les vols ?Exercice 16 : Quel est le nombre de pilotes qui conduisent des avions enservice ? (ie dans la relation DEPART)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 729 / 803

22 Langage SQL 22.13 Group byChapitre 22 • Langage SQL§22.13 • Group by

L’opérateur GROUP BY partitionne la table.Exemple : Quel est le nombre de pilotes qui conduisent des avions enservice, par avion ?

SELECT NUMAV, COUNT(DISTINCT DEPART.MATRICULE)

FROM DEPART

GROUP BY NUMAV ;

Exercice 17 : Quelle est la capacité moyenne des avions, par entrepôt etpart type ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 730 / 803

Page 434: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.14 Group by . . . HAVINGChapitre 22 • Langage SQL§22.14 • Group by . . . HAVING

L’opérateur HAVING permet d’introduire une qualification sur lessous-tables issues du GROUP BY.Le HAVING est au GROUP BY ce que le WHERE est au FROM.Exemple : quels sont les avions qui assurent plus de 3 départ ?

SELECT DEPART.NUMAV

FROM DEPART

GROUP BY NUMAV

HAVING COUNT(*) > 3 ;

Exercice 18 : Quelles sont les villes où sont entreposés plus de 2 avions detype ICBM ?

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 731 / 803

22 Langage SQL 22.15 ConclusionChapitre 22 • Langage SQL§22.15 • Conclusion

SQL est un langage d’interrogation très lisible, par tous les utilisateurs.SQL est un langage dans lequel il est relativement facile d’écrire, pour unprogrammeur, à condition de bien visualiser l’ordre d’application desinstructions :

1 From2 Where3 Group By4 Having5 Select6 Order By

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 732 / 803

Page 435: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.16 Correction des exercicesChapitre 22 • Langage SQL§22.16 • Correction des exercices

� Exercice 1

Quel est l’âge du pilote de matricule 15 ?

SELECT PILOTE.AGE

FROM PILOTE

WHERE MATRICULE = 15 ;

� Exercice 2

Quels sont les pilotes de cette compagnie aérienne (leur matricule, leurnom leur ville, leur âge et leur salaire)

SELECT *FROM PILOTE ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 733 / 803

22 Langage SQL 22.16 Correction des exercices

� Exercice 3

Quels sont les types d’avions entreposés à Tarascon, avec leur capacité,par ordre de capacité croissantes ?

SELECT DISTINCT TYPE, CAPACITE

FROM AVION

WHERE ENTREPOT = ’Tarascon’

ORDER BY CAPACITE ASC ;

� Exercice 4

Quelles sont les villes ayant un nom commençant par L et où un pilote demoins de 20 ans gagne plus de 200000 F ?

SELECT VILLE

FROM PILOTE

WHERE AGE < 20

AND SALAIRE > 200000

AND VILLE LIKE ’L%’;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 734 / 803

Page 436: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.16 Correction des exercices

� Exercice 5

Quels sont les numéros d’avions, avec leur entrepôt, ne résidant pas àMarolles-en-Hurepoix, ayant une capacité supérieure à 200 ? (donnés parordre de numéros décroissants)

SELECT NUMAV, ENTREPOT

FROM AVION

WHERE ENTREPOT != ’Marolles-en-Hurepoix’

AND CAPACITE > 200

ORDER BY NUMAV DESC ;

� Exercice 6

Quelles sont les villes d’où part un vol pour Ajaccio ? (donner les résultatsen majuscules)

SELECT UPPER(VILLE_DEPART)

FROM VOL

WHERE VILLE_ARRIVEE = ’Ajaccio’;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 735 / 803

22 Langage SQL 22.16 Correction des exercices

� Exercice 7

Quel est le nombre d’avions en service (ie dans la relation DEPART), le 19décembre 1995 ?

SELECT COUNT(DISTINCT NUMAV)

FROM DEPART

WHERE DATE_DEP = ’19-12-95’ ;

� Exercice 8

Quelle est la capacité moyenne des avions entreposés à Pogo Togo ?

SELECT AVG(ALL CAPACITE)

FROM AVION

WHERE AVION.ENTREPOT = ’Pogo Togo’;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 736 / 803

Page 437: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.16 Correction des exercices

� Exercice 9

Exprimer la requête suivante avec un EXISTS :Quels sont les noms des pilotes qui habitent dans une ville où sontlocalisés des avions de capacité supérieure à 250 ?

SELECT PILOTE.NOM

FROM PILOTE

WHERE EXISTS ( SELECT *FROM AVION

WHERE CAPACITE > 250

AND AVION.ENTREPOT = PILOTE.VILLE

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 737 / 803

22 Langage SQL 22.16 Correction des exercices

� Exercice 10

Quels sont les noms des passagers ayant réservé pour le 1er avril 1996 ?(avec un IN)

SELECT PASSAGER.NOMAB

FROM PASSAGER

WHERE NUMAB IN ( SELECT RESERVATION.NUMAB

FROM RESERVATION

WHERE RESERVATION.DATE_DEP = ’01-04-96’

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 738 / 803

Page 438: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.16 Correction des exercices

� Exercice 11 a

Quels sont les noms des pilotes qui assurent un vol le vendredi 13 octobre1995, sur un avion de capacité supérieure à 250 ?De manière prédicative :

SELECT PILOTE.NOM

FROM PILOTE, DEPART, AVION

WHERE PILOTE.MATRICULE = DEPART.MATRICULE

AND DEPART.DATE_DEP = ’13-10-95’

AND DEPART.NUMAV = AVION.NUMAV

AND AVION.CAPACITE > 250 ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 739 / 803

22 Langage SQL 22.16 Correction des exercices

� Exercice 11 b

Quels sont les noms des pilotes qui assurent un vol le vendredi 13 octobre1995, sur un avion de capacité supérieure à 250 ?A l’aide de requêtes imbriquées :

SELECT NOM

FROM PILOTE

WHERE MATRICULE IN ( SELECT DEPART.MATRICULE

FROM DEPART

WHERE DATE_DEP = ’13-10-95’

AND NUMAV IN ( SELECT AVION.NUMAV

FROM AVION

WHERE CAPACITE > 250

)

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 740 / 803

Page 439: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.16 Correction des exercices

� Exercice 12

Quelles sont les paires de pilotes (matricules) habitant dans la même ville ?

SELECT P1.MATRICULE, P2.MATRICULE

FROM PILOTE P1, PILOTE P2

WHERE P1.VILLE = P2.VILLE

AND P1.MATRICULE > P2.MATRICULE ;

(il s’agit d’une auto jointure)

� Exercice 13

Quels sont les noms des pilotes qui conduisent l’avion de numéro 666 ?

SELECT NOM

FROM PILOTE, DEPART

WHERE PILOTE.MATRICULE = DEPART.MATRICULE

AND DEPART.NUMAV = ’666’ ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 741 / 803

22 Langage SQL 22.16 Correction des exercices

� Exercice 14

Quels sont les noms des pilotes qui habitent dans la ville où est entreposél’avion 666 ?

SELECT NOM

FROM PILOTE, AVION

WHERE PILOTE.VILLE = AVION.ENTREPOT

AND AVION.NUMAV = ’666’;

� Exercice 15

Quels sont les passagers qui ont réservé sur tous les vols ?

SELECT NUMAB

FROM PASSAGER

WHERE NOT EXISTS ( SELECT *FROM VOL

WHERE NOT EXISTS ( SELECT *FROM RESERVATION

WHERE RESERVATION.NUMAB = PASSAGER.NUMAB

AND RESERVATION.NUMVOL = VOL.NUMVOL

)

) ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 742 / 803

Page 440: Administration UNIX - Cours Jussieu - 2009-2010

22 Langage SQL 22.16 Correction des exercices

� Exercice 16

Quel est le nombre de pilotes qui conduisent des avions en service ? (iedans la relation DEPART)

SELECT COUNT(DISTINCT DEPART.MATRICULE)

FROM DEPART ;

� Exercice 17

Quelle est la capacité moyenne des avions, par entrepôt et par type ?

SELECT ENTREPOT, TYPE, AVG(CAPACITE)

FROM AVION

GROUP BY ENTREPOT, TYPE ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 743 / 803

22 Langage SQL 22.16 Correction des exercices

� Exercice 18

Quelles sont les villes où sont entreposés plus de 2 avions de type ICBM ?

SELECT ENTREPOT

FROM AVION

WHERE TYPE = ’ICBM’

GROUP BY ENTREPOT

HAVING COUNT(*) > 2 ;

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 744 / 803

Page 441: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 23

Base de données ORACLE

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 745 / 803

23 Base de données ORACLE 23.1 IntroductionChapitre 23 • Base de données ORACLE§23.1 • Introduction

Plusieurs moteurs de bases de données disponibles :OracleMicrosoft SQL ServerMicrosoft MSDE (version light et gratuite de SQL Server)IBM DB2SybaseMYSQLPOSTGRESQL

ORACLE est la référence en bases de données.

Version de ORACLE disponible au moment de l’écriture de ce document :10gSite officiel : http://www.oracle.com

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 746 / 803

Page 442: Administration UNIX - Cours Jussieu - 2009-2010

23 Base de données ORACLE 23.1 Introduction

A noter qu’Oracle diffuse maintenant des versions gratuites 100%fonctionnelles pour LINUX, pour SOLARIS, pour WINDOWS.

A noter le livre « Oracle 9i sous Linux » par Gilles Briard, éditeur Eyrolles,prix 50 euros, livré avec la distribution Oracle 9i complète pour Linux. (jen’ai pas lu le livre)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 747 / 803

23 Base de données ORACLE 23.2 Outil TOADChapitre 23 • Base de données ORACLE§23.2 • Outil TOAD

Outil de mise au point des requêtes SQL : TOAD

Voir « http://www.toadsoft.com »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 748 / 803

Page 443: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 24

Base de données MYSQL

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 749 / 803

24 Base de données MYSQL 24.1 IntroductionChapitre 24 • Base de données MYSQL§24.1 • Introduction

Plusieurs moteurs de bases de données disponibles :OracleMicrosoft SQL ServerMicrosoft MSDE (version light et gratuite de SQL Server)IBM DB2SybaseMYSQLPOSTGRESQL

Version de MYSQL disponible au moment de l’écriture de ce document :5.0.22 (2006-08-03)Site officiel : http://www.mysql.comChangement de la licence de MYSQL dans la version 4. Mal reçu par lacommunauté des développeurs ⇒ Par exemple dans PHP 5, il n’y a plusde support d’origine pour MYSQL.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 750 / 803

Page 444: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.2 Utilisateur UNIX dédié à MYSQL : mysqlChapitre 24 • Base de données MYSQL§24.2 • Utilisateur UNIX dédié à MYSQL : mysql

Etape préliminaire à l’installation mais indispensable.

Le bon fonctionnement de MYSQL nécessite la définition d’un utilisateurau sens UNIX qui s’appelle « mysql ».

On créera aussi un groupe UNIX « mysql ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 751 / 803

24 Base de données MYSQL 24.3 Arborescence MYSQLChapitre 24 • Base de données MYSQL§24.3 • Arborescence MYSQL

Par défaut, les sources de MYSQL s’installeront dans« /usr/local/mysql ».On trouvera alors dans « /usr/local/mysql » :

sous-répertoire « bin » : binaires de l’applicationsous-répertoire « include/mysql » : headers de programmation Csous-répertoire « info » : fichiers de documentationsous-répertoire « lib/mysql » : librairies partagéessous-répertoire « libexec » : binaires « système » de l’applicationsous-répertoire « share/mysql » : fichiers des textes des erreurssous-répertoire « sql-bench » : fichiers de testssous-répertoire « var » : fichiers de données et de log

A noter le fichier « var/my.cnf » qui définit la configuration de MYSQL.L’installation de MYSQL doit se compléter de la création des basesinitiales de MYSQL.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 752 / 803

Page 445: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.4 Création des bases initiales MYSQL : mysql_install_dbChapitre 24 • Base de données MYSQL§24.4 • Création des bases initiales MYSQL : mysql_install_db

(en anglais MYSQL install databases)Syntaxe : mysql_install_db

Par défaut, c’est le répertoire « var » dans l’arborescence MYSQL (pardéfaut donc « /usr/local/mysql/var »).

La création des bases initiales se fera sous l’identité de l’utilisateur« mysql ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 753 / 803

24 Base de données MYSQL 24.4 Création des bases initiales MYSQL : mysql_install_db

% iduid=6000(mysql) gid=6000(mysql)

% mysql_install_dbInstalling all prepared tables

Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server

to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/local/mysql/bin/mysqladmin -u root password ’new-password’

/usr/local/mysql/bin/mysqladmin -u root -h linux.example.com password ’new-password’

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the ’sql-bench’ directory:

cd sql-bench ; perl run-all-tests

Please report any problems with the /usr/local/mysql/bin/mysqlbug script!

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at https://order.mysql.comc©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 754 / 803

Page 446: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.4 Création des bases initiales MYSQL : mysql_install_db

ATTENTION : Finaliser l’installation par la mise en place d’un mot depasse pour le compte SQL de nom « root » :

% /usr/local/mysql/bin/mysqladmin -u root password ’XXXXXXXX’

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 755 / 803

24 Base de données MYSQL 24.5 lancement/arrêt de MYSQLChapitre 24 • Base de données MYSQL§24.5 • lancement/arrêt de MYSQL

Lancer sous l’identité de mysql le programme « bin/mysqld_safe » sousl’identité UNIX « mysql ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 756 / 803

Page 447: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.6 Création de bases MYSQL (1) : mysqladminChapitre 24 • Base de données MYSQL§24.6 • Création de bases MYSQL (1) : mysqladmin

La création de bases normales MYSQL se fait par la commande« mysqladmin ».Syntaxe : mysqladmin [options] create base

� Exemple 1 : création d’une base

% mysqladmin -u root -p create arsEnter password: XXXXXXX

� Exemple 2 : suppression d’une base

% mysqladmin -u root -p drop arsEnter password: XXXXXXX

Dropping the database is potentially a very bad thing to do.

Any data stored in the database will be destroyed.

Do you really want to drop the ’base’ database [y/N] y

Database "base" dropped

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 757 / 803

24 Base de données MYSQL 24.7 Création de bases MYSQL (2) : commandes SQLChapitre 24 • Base de données MYSQL§24.7 • Création de bases MYSQL (2) : commandes SQL

% mysql -u root -pXXXXXXXXmysql> create database ars ; mysql> drop database ars ;Query OK, 1 row affected (0.01 sec) Query OK, 0 rows affected (0.02 sec)

mysql> show databases ; mysql> show databases ;

+----------+ +----------+

| Database | | Database |

+----------+ +----------+

| ars | | mysql |

| mysql | | test |

| test | +----------+

+----------+ 2 rows in set (0.01 sec)

3 rows in set (0.01 sec)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 758 / 803

Page 448: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.8 Dialogue interactif avec MYSQL en mode CLI : mysqlChapitre 24 • Base de données MYSQL§24.8 • Dialogue interactif avec MYSQL en mode CLI : mysql

La commande « mysql » permet d’interagir avec MYSQL et de luidemander d’exécuter des commandes SQL. Cela se présente comme unshell spécialisé en SQL.Syntaxe : mysql [options] base

De nombreuses commandes sont ensuite disponibles.

� Exemple 1 : connexion et déconnexion

% mysql -u root -pXXXXXXXX ars...

mysql> quit ;

Bye

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 759 / 803

24 Base de données MYSQL 24.8 Dialogue interactif avec MYSQL en mode CLI : mysql

� Exemple 2 : liste des bases

% mysql -u root -pXXXXXXXX...

mysql> show databases ;

+----------+

| Database |

+----------+

| ars |

| mysql |

| test |

+----------+

3 rows in set (0.01 sec)

mysql> quit ;

Bye

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 760 / 803

Page 449: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.8 Dialogue interactif avec MYSQL en mode CLI : mysql

� Exemple 3 : liste des tables systèmes

% mysql -u root -pXXXXXXXX mysql...

mysql> show tables ;

+---------------------------+

| Tables_in_mysql |

+---------------------------+

| columns_priv |

| db |

| func |

| help_category |

| help_keyword |

| help_relation |

| help_topic |

| host |

| tables_priv |

| time_zone |

| time_zone_leap_second |

| time_zone_name |

| time_zone_transition |

| time_zone_transition_type |

| user |

+---------------------------+

15 rows in set (0.00 sec)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 761 / 803

24 Base de données MYSQL 24.8 Dialogue interactif avec MYSQL en mode CLI : mysql

� Exemple 4 : liste des utilisateurs

% mysql -u root -pXXXXXXXX mysql...

mysql> select User from user order by User asc ;

+------+

| User |

+------+

| |

| |

| root |

| root |

+------+

4 rows in set (0.03 sec)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 762 / 803

Page 450: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.9 Notion d’utilisateurs MYSQLChapitre 24 • Base de données MYSQL§24.9 • Notion d’utilisateurs MYSQL

Une requête SQL est émise au nom d’un utilisateur fictif interne à la baseSQL.Un utilisateur SQL n’est pas nécessairement un vrai utilisateur UNIX.

La notion d’utilisateurs SQL est utilisée dans le contrôle des requêtes SQL :

GRANT privilège[,privilège...]

ON table | * | *.* | base.*TO utilisateur [IDENTIFIED BY [PASSWORD] ’PASSWORD’]

[, utilisateur [IDENTIFIED BY [PASSWORD] ’PASSWORD’]] ...

où :les privilèges sont parmi les mots clef « SELECT », « INSERT »,« UPDATE », « DELETE », « RULE », « ALL »utilisateur désignera un utilisateur bien précis qui obtient lesprivilèges indiqués

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 763 / 803

24 Base de données MYSQL 24.9 Notion d’utilisateurs MYSQL

� Exemple : ajout de droits pour un utilisateur

% mysql -u root -pXXXXXXXX mysql...

mysql> grant all on ars.* to besancon@localhost identified by ’XXXXXXXX’ ;

Query OK, 0 rows affected (0.02 sec)

� Exemple : révocation de droits pour un utilisateur

% mysql -u root -pXXXXXXXX mysql...

mysql> revoke all privileges on ars.* from besancon@localhost ;

Query OK, 0 rows affected (0.02 sec)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 764 / 803

Page 451: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.10 Fichier de configuration : my.cnfChapitre 24 • Base de données MYSQL§24.10 • Fichier de configuration : my.cnf

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 765 / 803

24 Base de données MYSQL 24.11 Sauvegarde : mysqldumpChapitre 24 • Base de données MYSQL§24.11 • Sauvegarde : mysqldump

MYSQL fournit un outil pour sauvegarder au format SQL sous forme decommandes SQL une ou plusieurs bases.

Pour sauver une base, utiliser la commande « mysqldump ».Syntaxe : mysqldump -u root -p [options] base

Pour sauver toutes les bases, utiliser la commande« mysqldump --all-databases ».

Syntaxe : mysqldumpall -u root -p [options]

Attention : joindre à la sauvegarde le fichier my.cnf qui n’est passauvegardé par l’outil SQL mysqldump.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 766 / 803

Page 452: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.11 Sauvegarde : mysqldump

� Exemple 1 : sauvegarde d’une seule base

% mysqldump -u root -pXXXXXXXX base > /tmp/base.sql

% ls -l /tmp/base.sql-rw-r--r-- 1 besancon adm 15054229 Oct 23 12:12 /tmp/base.sql

% head /tmp/base.sql-- MySQL dump 10.8

--

-- Host: localhost Database: ars

-- ------------------------------------------------------

-- Server version 4.1.7-log

...

DROP TABLE IF EXISTS ‘t1‘;

CREATE TABLE ‘t1‘ (

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 767 / 803

24 Base de données MYSQL 24.11 Sauvegarde : mysqldump

� Exemple 2 : sauvegarde de toutes les bases

% mysqldump -u root -pXXXXXXXX --all-databases > /tmp/bases.sql

% ls -l /tmp/bases.sql-rw-r--r-- 1 besancon adm 15064263 Oct 23 12:18 /tmp/bases.sql

% head /tmp/base.sql-- MySQL dump 10.8

--

-- Host: localhost Database:

-- ------------------------------------------------------

-- Server version 4.1.7-log

...

CREATE DATABASE /*!32312 IF NOT EXISTS*/ ‘ars‘;

USE ‘ars‘;

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 768 / 803

Page 453: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.12 Rechargement d’une sauvegardeChapitre 24 • Base de données MYSQL§24.12 • Rechargement d’une sauvegarde

S’il s’agit de recharger la sauvegarde d’une base, faire sous l’identité del’utilisateur « mysql » :

% mysql -u root -pXXXXXXXX < /tmp/base.sql

S’il s’agit de recharger la sauvegarde de la totalité des bases, faire sousl’identité de l’utilisateur « mysql » :

% mysql -u root -pXXXXXXXX < /tmp/bases.sql

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 769 / 803

24 Base de données MYSQL 24.13 Interface de gestion de MYSQL : phpmyadminChapitre 24 • Base de données MYSQL§24.13 • Interface de gestion de MYSQL : phpmyadmin

A noter un interface WWW de configuration et d’administration :phpmyadmin

Cf http://www.phpmyadmin.net/

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 770 / 803

Page 454: Administration UNIX - Cours Jussieu - 2009-2010

24 Base de données MYSQL 24.14 Outil TOADChapitre 24 • Base de données MYSQL§24.14 • Outil TOAD

Outil de mise au point des requêtes SQL : TOAD

Voir « http://www.toadsoft.com »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 771 / 803

Page 455: Administration UNIX - Cours Jussieu - 2009-2010

Chapitre 25

Base de données POSTGRESQL

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 772 / 803

25 Base de données POSTGRESQL 25.1 IntroductionChapitre 25 • Base de données POSTGRESQL§25.1 • Introduction

(On rencontre souvent le mot PGSQL pour POSTGRESQL)

Plusieurs moteurs de bases de données disponibles :OracleMicrosoft SQL ServerMicrosoft MSDE (version light et gratuite de SQL Server)IBM DB2SybaseMYSQLPOSTGRESQL

Version de PGSQL disponible au moment de l’écriture de ce document :8.1.4 (2006-08-03)Site officiel : http://www.postgresql.org

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 773 / 803

Page 456: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.1 Introduction

Système de réplication possible mais cela semble un produit jeune.

A completer...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 774 / 803

25 Base de données POSTGRESQL 25.2 Utilisateur UNIX dédié à PGSQL : pgsqlChapitre 25 • Base de données POSTGRESQL§25.2 • Utilisateur UNIX dédié à PGSQL : pgsql

Etape préliminaire à l’installation mais indispensable.

Le bon fonctionnement de PGSQL nécessite la définition d’un utilisateurau sens UNIX qui s’appelle « pgsql ».

On créera aussi un groupe UNIX « pgsql ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 775 / 803

Page 457: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.3 Arborescence PGSQLChapitre 25 • Base de données POSTGRESQL§25.3 • Arborescence PGSQL

Par défaut, les sources de PGSQL s’installeront dans /usr/local/pgsql.On trouvera alors dans /usr/local/pgsql :

sous-répertoire bin : répertoire des binaires de l’applicationsous-répertoire data : répertoire des fichiers de configuration aupremier niveau ; ce répertoire devra être la propriété de l’utilisateur« pgsql ».sous-répertoire data/base : répertoire des fichiers de stockage de labase de donnéessous-répertoire doc : répertoire de documentation (format HTML)sous-répertoire include : répertoire des headers de programmation Csous-répertoire lib : répertoire des librairies partagées des binairesPGSQLsous-répertoire man : répertoire des pages de manuelsous-répertoire share : répertoire de fichiers d’exemples

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 776 / 803

25 Base de données POSTGRESQL 25.3 Arborescence PGSQL

A noter le fichier « data/pga_hba.conf » qui définit les accès autorisés.

L’installation de PGSQL doit se compléter de la création des basesinitiales de PGSQL.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 777 / 803

Page 458: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.4 Création des bases initiales PGSQL : initdbChapitre 25 • Base de données POSTGRESQL§25.4 • Création des bases initiales PGSQL : initdb

(en anglais initialize database)

Syntaxe : initdb -D répertoire-de-données

Par défaut, on prend le répertoire « data » dans l’arborescence PGSQL(par défaut donc « /usr/local/pgsql/data »).

La création des bases initiales se fera sous l’identité de l’utilisateur« pgsql ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 778 / 803

25 Base de données POSTGRESQL 25.5 Lancement/arrêt de PGSQL : pg_ctlChapitre 25 • Base de données POSTGRESQL§25.5 • Lancement/arrêt de PGSQL : pg_ctl

Deux processus sont en jeu :postmaster : accepte les requêtes de connexionpostgres : exécute les requêtes SQL et renvoie les résultats

Attention : les processus doivent être lancés au nom de l’utilisateur« pgsql ».

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 779 / 803

Page 459: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.5 Lancement/arrêt de PGSQL : pg_ctl

Un script de lancement et d’arrêt est fourni avec PGSQL : pg_ctl

Syntaxes :démarrage de PGSQL : « pg_ctl start » :# su pgsql -c "pg_ctl -D /chemin/vers/pgsql/data start"

postmaster successfully started

arrêt de PGSQL : « pg_ctl stop » :# su pgsql -c "pg_ctl -D /chemin/vers/pgsql/data stop"

waiting for postmaster to shut down......done

postmaster successfully shut down

redémarrage de PGSQL : « pg_ctl restart »

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 780 / 803

25 Base de données POSTGRESQL 25.6 Création de bases PGSQL : createdbChapitre 25 • Base de données POSTGRESQL§25.6 • Création de bases PGSQL : createdb

La création de bases normales PGSQL se fait par la commande« createdb ».Syntaxe : createdb [options] base

La création de toute nouvelle base se fait par duplication de la base initialede nom « template1 ».

� Exemple

% createdb -e testCREATE DATABASE base; <-- commande interne lancée

CREATE DATABASE <-- affichage du résultat de cette commande

L’option « -e » sert à afficher les commandes internes SQL en faitréalisées par le programme.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 781 / 803

Page 460: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.7 Destruction de bases PGSQL : dropdbChapitre 25 • Base de données POSTGRESQL§25.7 • Destruction de bases PGSQL : dropdb

La destruction de bases normales PGSQL se fait par la commande« dropdb ».Syntaxe : dropdb [options] base

� Exemple

% dropdb -e testDROP DATABASE base; <-- commande interne lancée

DROP DATABASE <-- affichage du résultat de cette commande

L’option « -e » sert à afficher les commandes internes SQL en faitréalisées par le programme.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 782 / 803

25 Base de données POSTGRESQL 25.8 Dialogue interactif avec PGSQL en mode CLI : psqlChapitre 25 • Base de données POSTGRESQL§25.8 • Dialogue interactif avec PGSQL en mode CLI : psql

La commande « psql » permet d’interagir avec PGSQL et de luidemander d’exécuter des commandes SQL. Cela se présente comme unshell spécialisé en SQL.Syntaxe : psql base

De nombreuses commandes sont ensuite disponibles.

� Exemple 1 : connexion et déconnexion

% psql template1

Welcome to psql 7.4.2, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms

\h for help with SQL commands

\? for help on internal slash commands

\g or terminate with semicolon to execute query

\q to quit

template1=# \q

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 783 / 803

Page 461: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.8 Dialogue interactif avec PGSQL en mode CLI : psql

� Exemple 2 : liste des bases

% psql template1

...

template1=# \l

List of databases

Name | Owner | Encoding

-----------+----------+-----------

template0 | pgsql | SQL_ASCII

template1 | pgsql | SQL_ASCII

(2 rows)

template1=# select * from pg_database ;

datname | datdba | encoding | datistemplate | datallowconn | datlastsysoid | datvacuumxid | datfrozenxid | datpath | datconfig | datacl

-----------+--------+----------+---------------+--------------+---------------+--------------+--------------+---------+-----------+--------------------

template1 | 1 | 0 | t | t | 17140 | 464 | 464 | | | {pgsql=C*T*/pgsql}

template0 | 1 | 0 | t | f | 17140 | 464 | 464 | | | {pgsql=C*T*/pgsql}

(2 rows)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 784 / 803

25 Base de données POSTGRESQL 25.8 Dialogue interactif avec PGSQL en mode CLI : psql

� Exemple 3 : liste des tables systèmes

% psql template1

...

template1=# \dS

List of relations

Schema | Name | Type | Owner

------------+--------------------------+---------+-------

...

pg_catalog | pg_database | table | pgsql

...

pg_catalog | pg_user | view | pgsql

...

(54 rows)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 785 / 803

Page 462: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.8 Dialogue interactif avec PGSQL en mode CLI : psql

� Exemple 4 : liste des utilisateurs

% psql template1

...

template1=# select * from pg_user ;

usename | usesysid | usecreatedb | usesuper | usecatupd | passwd | valuntil | useconfig

----------+----------+-------------+----------+-----------+----------+----------+-----------

pgsql | 1 | t | t | t | ******** | |

apache | 1002 | f | f | f | ******** | |

besancon | 1003 | t | t | t | ******** | |

(3 rows)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 786 / 803

25 Base de données POSTGRESQL 25.9 Création de bases PGSQL : commandes SQLChapitre 25 • Base de données POSTGRESQL§25.9 • Création de bases PGSQL : commandes SQL

% psql template1

Welcome to psql 7.4.2, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms

\h for help with SQL commands

\? for help on internal slash commands

\g or terminate with semicolon to execute query

\q to quit

template1=# create database exemple ;

CREATE DATABASE

template1=# \l

List of databases

Name | Owner | Encoding

-----------+----------+-----------

exemple | besancon | SQL_ASCII

template0 | pgsql | SQL_ASCII

template1 | pgsql | SQL_ASCII

(3 rows)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 787 / 803

Page 463: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.10 Destruction de bases PGSQL : commandes SQLChapitre 25 • Base de données POSTGRESQL§25.10 • Destruction de bases PGSQL : commandes SQL

% psql template1

Welcome to psql 7.4.2, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms

\h for help with SQL commands

\? for help on internal slash commands

\g or terminate with semicolon to execute query

\q to quit

template1=# drop database exemple ;

DROP DATABASE

template1=# \l

List of databases

Name | Owner | Encoding

-----------+----------+-----------

template0 | pgsql | SQL_ASCII

template1 | pgsql | SQL_ASCII

(2 rows)

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 788 / 803

25 Base de données POSTGRESQL 25.11 Notion d’utilisateurs PGSQLChapitre 25 • Base de données POSTGRESQL§25.11 • Notion d’utilisateurs PGSQL

Une requête SQL est émise au nom d’un utilisateur fictif interne à la baseSQL.Un utilisateur SQL n’est pas nécessairement un vrai utilisateur UNIX.

La notion d’utilisateurs SQL est utilisée dans le contrôle des requêtes SQL :

GRANT privilège[,...] ON objet[,...] TO {PUBLIC | utilisateur} ;

où :les privilèges sont parmi les mots clef « SELECT », « INSERT »,« UPDATE », « DELETE », « RULE », « ALL »un objet désigne une table, une vue ou une séquencePUBLIC indiquera que tous les utilisateurs SQL peuvent obtenir lesprivilèges indiquésutilisateur désignera un utilisateur bien précis qui obtient lesprivilèges indiqués

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 789 / 803

Page 464: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.11 Notion d’utilisateurs PGSQL

� Exemple% psql base

...

base=# \d

List of relations

Schema | Name | Type | Owner

--------+---------+-------+----------

public | exemple | table | besancon

(1 row)

t=# \z

Access privileges for database "base"

Schema | Table | Access privileges

--------+---------+-------------------

public | exemple |

(1 row)

t=# grant all on exemple to public ;

GRANT

t=# \z

Access privileges for database "base"

Schema | Table | Access privileges

--------+---------+------------------------------------------------------

public | exemple | {besancon=a*r*w*d*R*x*t*/besancon,=arwdRxt/besancon}

(1 row)

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 790 / 803

25 Base de données POSTGRESQL 25.12 Gestion d’utilisateurs PGSQL (1) : createuserChapitre 25 • Base de données POSTGRESQL§25.12 • Gestion d’utilisateurs PGSQL (1) : createuser

Pour créer un utilisateur SQL, employer la commande « createuser » etrépondre aux diverses questions posées.

Syntaxe : createuser [options] [utilisateur-SQL]

-a -A Création de nouveaux utilisateurs ou pas-d -D Création de nouvelles databases ou pas

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 791 / 803

Page 465: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.12 Gestion d’utilisateurs PGSQL (1) : createuser

� Exemple 1 : création toute interactive

# createuser

Enter name of user to add: ars

Shall the new user be allowed to create databases? (y/n) n

Shall the new user be allowed to create more new users? (y/n) n

CREATE USER

� Exemple 2 : création non interactive

# createuser -D -A ars

CREATE USER

� Exemple 3 : création non interactive et avec affichage des instructionsSQL internes

# createuser -D -A -e ars

createuser -D -A -e ars

SET autocommit TO ’on’;CREATE USER "ars" NOCREATEDB NOCREATEUSER

CREATE USER

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 792 / 803

25 Base de données POSTGRESQL 25.13 Gestion d’utilisateurs PGSQL (2) : dropuserChapitre 25 • Base de données POSTGRESQL§25.13 • Gestion d’utilisateurs PGSQL (2) : dropuser

Pour supprimer un utilisateur SQL, employer la commande « dropuser »et répondre aux diverses questions posées.

Syntaxe : dropuser [options] [utilisateur-SQL]

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 793 / 803

Page 466: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.13 Gestion d’utilisateurs PGSQL (2) : dropuser

� Exemple 1 : suppression toute interactive

# dropuser

Enter name of user to drop: ars

DROP USER

� Exemple 2 : suppression non interactive

# dropuser ars

DROP USER

� Exemple 3 : suppression interactive avec garde fou et avec affichage desinstructions SQL internes

# dropuser -e -i ars

User "ars" will be permanently removed.

Are you sure? (y/n) y

DROP USER ars;

DROP USER

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 794 / 803

25 Base de données POSTGRESQL 25.14 Fichier de configuration : postgresql.confChapitre 25 • Base de données POSTGRESQL§25.14 • Fichier de configuration : postgresql.conf

Le fichier « data/postgresql.conf » est créé après la phase du« initdb ».

Il contiendra les paramètres de gestion mémoire pour PGSQL.

Le paramètre tcpip_socket indiquera si PGSQL accepte lesconnexions réseau.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 795 / 803

Page 467: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.15 Fichier de configuration : pg_hba.confChapitre 25 • Base de données POSTGRESQL§25.15 • Fichier de configuration : pg_hba.conf

Le fichier « data/pg_hba.conf » est créé après la phase du « initdb ».

Ce fichier sert à régler les contrôles d’accès.

Syntaxe :

local DATABASE USER METHOD [OPTION]

host DATABASE USER IP-ADDRESS IP-MASK METHOD [OPTION]

hostssl DATABASE USER IP-ADDRESS IP-MASK METHOD [OPTION]

hostnossl DATABASE USER IP-ADDRESS IP-MASK METHOD [OPTION]

host DATABASE USER IP-ADDRESS/CIDR-MASK METHOD [OPTION]

hostssl DATABASE USER IP-ADDRESS/CIDR-MASK METHOD [OPTION]

hostnossl DATABASE USER IP-ADDRESS/CIDR-MASK METHOD [OPTION]

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 796 / 803

25 Base de données POSTGRESQL 25.15 Fichier de configuration : pg_hba.conf

Syntaxe plus précise :

The first field is the connection type : "local" is a Unix-domain socket,"host" is either a plain or SSL-encrypted TCP/IP socket, "hostssl" isan SSL-encrypted TCP/IP socket, and "hostnossl" is a plain TCP/IPsocket.

DATABASE can be "all", "sameuser", "samegroup", a database name(or a comma-separated list thereof), or a file name prefixed with "@".

USER can be "all", an actual user name or a group name prefixed with"+" or a list containing either.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 797 / 803

Page 468: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.15 Fichier de configuration : pg_hba.conf

IP-ADDRESS and IP-MASK specify the set of hosts the record matches.CIDR-MASK is an integer between 0 and 32 (IPv6) or 128(IPv6) inclusive,that specifies the number of significant bits in the mask, so an IPv4CIDR-MASK of 8 is equivalent to an IP-MASK of 255.0.0.0, and anIPv6 CIDR-MASK of 64 is equivalent to an IP-MASK offfff:ffff:ffff:ffff::.

METHOD can be "trust", "reject", "md5", "crypt", "password","krb4", "krb5", "ident", or "pam". Note that "password" usesclear-text passwords ; "md5" is preferred for encrypted passwords.

OPTION is the ident map or the name of the PAM service.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 798 / 803

25 Base de données POSTGRESQL 25.16 Sauvegarde : pg_dump, pg_dumpallChapitre 25 • Base de données POSTGRESQL§25.16 • Sauvegarde : pg_dump, pg_dumpall

PGSQL fournit un outil pour sauvegarder au format SQL sous forme decommandes SQL une ou plusieurs bases.

Pour sauver une base, utiliser la commande « pg_dump » sous l’identité del’utilisateur « pgsql ».Syntaxe : pg_dump [options] base

Pour sauver toutes les bases, utiliser la commande « pg_dumpall » sousl’identité de l’utilisateur « pgsql ».Syntaxe : pg_dumpall [options]

Attention : joindre à la sauvegarde le fichier pg_hba.conf quicontrôle les accès et qui n’est pas sauvegardé par les 2 outil SQLpg_dump et pg_dumpall.

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 799 / 803

Page 469: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.16 Sauvegarde : pg_dump, pg_dumpall

� Exemple 1 : sauvegarde d’une seule base

% pg_dump base > /tmp/base.sql

% ls -l /tmp/base.sql

-rw-r--r-- 1 besancon adm 15054229 Oct 23 12:12 /tmp/base.sql

% head /tmp/base.sql

--

-- PostgreSQL database dump

--

SET client_encoding = ’SQL_ASCII’;

SET check_function_bodies = false;

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 800 / 803

25 Base de données POSTGRESQL 25.16 Sauvegarde : pg_dump, pg_dumpall

� Exemple 2 : sauvegarde de toutes les bases

% pg_dumpall > /tmp/bases.sql

% ls -l /tmp/bases.sql

-rw-r--r-- 1 besancon adm 15064263 Oct 23 12:18 /tmp/bases.sql

% head /tmp/base.sql

--

-- PostgreSQL database cluster dump

--

\connect "template1"

--

-- Users

--

DELETE FROM pg_shadow WHERE usesysid <> (SELECT datdba FROM pg_database WHERE datname = ’template0’);

CREATE USER apache WITH SYSID 1002 NOCREATEDB NOCREATEUSER;

CREATE USER besancon WITH SYSID 1003 CREATEDB CREATEUSER;

...

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 801 / 803

Page 470: Administration UNIX - Cours Jussieu - 2009-2010

25 Base de données POSTGRESQL 25.17 Rechargement d’une sauvegardeChapitre 25 • Base de données POSTGRESQL§25.17 • Rechargement d’une sauvegarde

S’il s’agit de recharger la sauvegarde d’une base, faire sous l’identité del’utilisateur « pgsql » :

% dropdb base% psql < /tmp/base.sql

S’il s’agit de recharger la sauvegarde de la totalité des bases, faire sousl’identité de l’utilisateur « pgsql » :

% initdb -D /chemin/vers/pgsql/data/base% psql < /tmp/bases.sql

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 802 / 803

25 Base de données POSTGRESQL 25.18 Interface de gestion de PGSQL : phppgadminChapitre 25 • Base de données POSTGRESQL§25.18 • Interface de gestion de PGSQL : phppgadmin

A noter un interface WWW de configuration et d’administration :phppgadmin

Cf http://sourceforge.net/projects/phppgadmin/

c©T.Besançon (v12.0.364) Administration UNIX ARS 2009 – 2010 Partie 3 803 / 803