This shows you the differences between two versions of the page.
uso:laboratoare:laborator-07:static_ip [2020/12/06 20:19] maria.mihailescu Modify ip a s in ip address show/ip a a in ip address add |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Configurarea statică a adreselor IP ====== | ||
- | |||
- | În mod obișnuit, adresa IP se obține dinamic, așa cum am văzut în [[https://ocw.cs.pub.ro/courses/uso/laboratoare/laborator-03/troubleshoot|laboratorul 03: Configurarea sistemului]]. În această secțiune vom vedea cum putem să setăm o adresă IP static pe interfața unei stații. Scopul final este să creăm o legătură între 2 mașini (containere), cu alte cuvinte, să ne putem conecta de pe o mașină pe cealaltă. | ||
- | |||
- | În această secțiunile vom folosi containerele ''tom'' și ''jerry''. Containtele ''tom'' dispune de o interfață numită ''eth0'', iar ''jerry'' de o interfață numită ''eth0''. Vom configura aceste interfațe astfel încât cele 2 containere să aibă conexiune între ele. | ||
- | |||
- | Ne autentificăm pe mașina ''tom'' folosind comanda: | ||
- | |||
- | <code bash> | ||
- | student@uso:~$ cd ~/uso-lab/labs/07-networking/lab-container | ||
- | student@uso:~/uso-lab/labs/07-networking/lab-container$ ./lab_prepare.sh connect tom | ||
- | root@tom:~# | ||
- | </code> | ||
- | |||
- | Observăm că pe mașina ''tom'' nu avem nicio adresă IP configurată pe interfața ''eth0'' și că interfața este în starea ''DOWN'': | ||
- | <code bash> | ||
- | root@tom:~$ ip address show eth0 | ||
- | 14: eth0@if15: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN group default | ||
- | link/ether 02:42:0a:0a:0a:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0 | ||
- | </code> | ||
- | |||
- | Configurăm adresa IP ''10.10.10.1/24'' și trecem interfața ''eth0'' în starea ''UP'', ca în exemplul de mai jos: | ||
- | <code bash> | ||
- | root@tom:~# ip address add 10.10.10.1/24 dev eth0 | ||
- | root@tom:~# ip link set dev eth0 up | ||
- | root@tom:~# ip address show eth0 | ||
- | 14: eth0@if15: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default | ||
- | link/ether 02:42:0a:0a:0a:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0 | ||
- | inet 10.10.10.1/24 scope global eth0 | ||
- | valid_lft forever preferred_lft forever | ||
- | </code> | ||
- | |||
- | **Exercițiu:** Deschideți un alt tab și conectați-vă la containerul ''jerry''. | ||
- | |||
- | **Exercițiu:** Configurați adresa IP ''10.10.10.2/24'' pe interfața ''eth0'' de pe containerul ''jerry''. Nu uitați să treceți interfața ''eth0''. | ||
- | |||
- | După aceasta verificăm de pe fiecare stație conectivitatea la celelaltă stație folosind comanda ''ping''. De pe mașina ''tom'', ca în exemplul de mai jos: | ||
- | <code> | ||
- | root@tom:~# ping 10.10.10.2 | ||
- | PING 10.10.10.2 (10.10.10.2) 56(84) bytes of data. | ||
- | 64 bytes from 10.10.10.2: icmp_seq=1 ttl=64 time=0.530 ms | ||
- | 64 bytes from 10.10.10.2: icmp_seq=2 ttl=64 time=0.945 ms | ||
- | ^C | ||
- | --- 10.10.10.2 ping statistics --- | ||
- | 2 packets transmitted, 2 received, 0% packet loss, time 1016ms | ||
- | rtt min/avg/max/mdev = 0.530/0.737/0.945/0.209 ms | ||
- | </code> | ||
- | |||
- | De pe mașina ''jerry'', ca în exemplul de mai jos: | ||
- | <code> | ||
- | root@jerry:~$ ping 10.10.10.1 | ||
- | PING 10.10.10.1 (10.10.10.1) 56(84) bytes of data. | ||
- | 64 bytes from 10.10.10.1: icmp_seq=1 ttl=64 time=0.737 ms | ||
- | 64 bytes from 10.10.10.1: icmp_seq=2 ttl=64 time=0.395 ms | ||
- | ^C | ||
- | --- 10.10.10.1 ping statistics --- | ||
- | 2 packets transmitted, 2 received, 0% packet loss, time 1001ms | ||
- | rtt min/avg/max/mdev = 0.395/0.566/0.737/0.171 ms | ||
- | </code> | ||