1
Reti di Calcolatori
οΏ½οΏ½Computer Networking: A Top Down Approach Featuring the Internet, οΏ½3rd edition. οΏ½Jim Kurose, Keith RossοΏ½Addison-Wesley, July 2004. οΏ½DISPONIBILE in versione italianaοΏ½
All material copyright 1996-2005
J.F Kurose and K.W. Ross, All Rights Reserved
http://www.mat.unical.it/informatica/Reti_di_Calcolatori
Utility per il debugging di una rete
Introduzione
Obiettivi
Sommario:
2
Comandi utili per il debug di problemi di rete β Parte 1
3
1. ping
4
Sinossi:
ping [opzioni] destinazione
Esempio:
ping 8.8.8.8
Output: (Pacchetti ricevuti)
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=56 time=25.9 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=56 time=26.4 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=56 time=33.1 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 25.996/28.151/33.146/2.911 ms
Output: (Pacchetti persi)
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
ping: sendmsg: Invalid argument
ping: sendmsg: Invalid argument
ping: sendmsg: Invalid argument
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2001ms
2. ifconfig
5
Sinossi:
ifconfig [opzioni] [interface]
Esempi:
ifconfig
ifconfig βa π‘ͺ Mostra tutte le schede di rete anche se non attive
ifconfig eth0 π‘ͺ Mostra la configurazione di rete del scheda eth0
ifconfig eth1 up π‘ͺ Attiva la scheda di rete eth1
ifconfig eth1 down π‘ͺ Disattiva la scheda di rete eth1
Output:
lo Link encap:Loopback locale
indirizzo inet:127.0.0.1 Maschera:255.0.0.0
indirizzo inet6: ::1/128 Scope:Global
UP LOOPBACK RUNNING 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
collisioni:0
Byte RX:0 (0.0 B) Byte TX:0 (0.0 B)
2. ip
6
Sinossi:
ip OBJECT COMMAND
ip [options] OBJECT COMMAND
ip OBJECT help
Esempi:
ip a / ip addr π‘ͺ Mostra gli indirizzi ip associate a tutte le interface di rete
ip a show eth0 π‘ͺ Mostra la configurazione della scheda di rete eth0
ip link ls up π‘ͺ Mostra la configurazione delle sole interface di rete attive
ip a add 10.0.0.1/24 dev eth0 π‘ͺ Assegna lβindirizzo IP 10.0.0.1 Maschera 24 al device eth0
ip a del 10.0.0.1/24 dev eth0 π‘ͺ Rimuove lβindirizzo IP 10.0.0.1 Maschera 24 al device eth0
Output: ip a show enp2s0
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:01:6c:6a:ce:cf brd ff:ff:ff:ff:ff:ff
inet 192.168.1.107/24 brd 192.168.1.255 scope global noprefixroute enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::5201:e5f1:5511:3ca5/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3. netstat / ss
7
Sinossi:
vedi man netstat
Esempi:
netstat π‘ͺ Di default netstat mostra la lista delle socket aperte
netstat βa π‘ͺ Mostra lo stato di tutte le socket. Se non si specifica il parametro βa, le socket usate dai processi del server non verranno mostrate.
netstat -tupan π‘ͺ Mostra lo stato di tutte (-a) le socket il cui protocollo Γ¨ TCP (-t) o UDP (-u) specificando inoltre il PID/programma (-p) ad esse connesso.
Lβopzione βn mostra il local address in formato numerico
Output:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:6897 0.0.0.0:* LISTEN 1286/myserver1
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1775/named
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 1775/named
tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 1286/myserver
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 13845/sshd
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1796/mysqld
4. telnet
8
Sinossi:
telnet <host> <port>
Esempi:
telnet ml.mat.unical.it 25 π‘ͺ Connessione al mail server di mat.unical.it
telnet google.it 80 π‘ͺ Connessione alla porta 80 del webserver google.it
Output: (Comunicazione con un mail server)
Trying 160.97.62.2...
Connected to ml.mat.unical.it.
Escape character is '^]'.
220 ml.mat.unical.it ESMTP Postfix
helo fra
250 ml.mat.unical.it
mail from: <francesco@mat.unical.it>
250 2.1.0 Ok
rcpt to: <pacenza@mat.unical.it>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
ciao test email
.
250 2.0.0 Ok: queued as 6DCD018D0115
quit
221 2.0.0 Bye
5. netcat
9
Sinossi:
nc [OPTIONS] [destination] [port]
Esempi:
nc -l 1234 π‘ͺ Avvia un socket server in ascolto sulla porta 1234
nc localhost 1234 π‘ͺ Avvia un socket client connesso in localhost sulla porta 1234
Output: (Comunicazione tra server e client nella stessa rete)
Server: francesco@pcino:~$ netcat -l 1234οΏ½ ciao
Client: francesco@XPS:/mnt/c/Users/Francesco$ nc 192.168.1.107 1234οΏ½ ciao
6. Wireshark (basics)
10
Γ possibile utilizzare wireshark direttamente tramite la sua user interface.
Una volta avviato il programma, sarΓ possibile selezionare lβinterfaccia di rete dalla quale si desidera effettuare la cattura dei pacchetti.
Non appena si seleziona lβinterfaccia, la cattura avrΓ inizio.
6. Wireshark (basics)
11
Wireshark Γ¨ in grado di catturare tutti i pacchetti che viaggiano allβinterno della tua stessa rete (questo accade quando lβopzione promiscuous mode Γ¨ abilitata β di default Γ¨ abilitata).
Γ possibile quindi vedere a colpo dβocchio i dati che stanno circolando allβinterno della rete.
Quando si vuole fermare la cattura dei pacchetti Γ¨ sufficiente premere sul tasto stop situato in alto a sinistra (si puΓ² decidere di analizzare i dati successivamente salvando la cattura appena effettuata).
6. Wireshark (basics) β Color coding
12
Una volta iniziata la cattura, sarΓ possibile vedere pacchetti evidenziati con colori diversi.
Wireshark utilizza diversi colori per aiutarti a identificare diversi tipi di pacchetti al primo sguardo.
Per visualizzare la legenda dei colori vai su Visualizza π‘ͺ Regole di colorazione
6. Wireshark (basics) β Filtrare i pacchetti
13
Se si vogliono visualizzare nel dettaglio solo specifici pacchetti (ma anche richieste o dati provenienti da uno specifico ip) Γ¨ possibile utilizzare i filtri.
Esempi:
dns π‘ͺ Filtra e mostra solo i pacchetti dns
ip.src==192.168.1.5 && ip.dst==192.168.1.1 π‘ͺ Mostra tutti i pacchetti la cui sorgente ip Γ¨ 192.168.1.5 e destinazione 192.168.1.1
Nota bene:
Γ possibile creare filtri piΓΉ complessi cliccando sul tasto Β«EspressioniΒ» situato di fianco la barra dei filtri
6. Wireshark (basics) β Ispezionare un pacchetto
14
Facendo doppio click sul pacchetto selezionato Γ¨ possibile visualizzare il dettaglio del suo contenuto.
Comandi utili per il debug di problemi di rete β Parte 2
15
7. ethtool
16
Sinossi:
ethtool [opzioni] device_name
Esempi:
ethtool eth0 π‘ͺ Mostra le proprietΓ del device eth0
ethtool -s eth0 speed 100 autoneg off π‘ͺ Modifica la velocitΓ del dispositivo di rete (se supportato)
ethtool -i eth0 π‘ͺ Mostra i driver della scheda di rete
ethtool -a eth0 π‘ͺ Mostra i settaggi di autonegoziazione, RX e TX di eth0
ethtool -S eth0 π‘ͺ Mostra statistiche sul device
Output:
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
...
...
8. dig / nslookup (1)
17
NSLOOKUP:
Sinossi:
nslookup [opzioni][server]
Esempi:
nslookup www.mat.unical.it π‘ͺ Effettua una interrogazione DNS per risolvere il dominio www.mat.unical.it
nslookup -type=MX mat.unical.it π‘ͺ Effettua una interrogazione DNS di tipo MX (mappa il nome di un dominio ai suoi server mail)
Output 1:
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
www.mat.unical.it canonical name = sv.mat.unical.it.
Name: sv.mat.unical.it
Address: 160.97.62.1
8. dig / nslookup (2)
18
DIG: Mostra molte piΓΉ informazioni con maggiori dettagli senza uso di opzioni
Sinossi:
vedi man dig
Esempi:
dig www.mat.unical.it π‘ͺ Effettua una interrogazione DNS per risolvere il dominio www.mat.unical.it
dig www.mat.unical.it +nocomments +noquestion +noauthority +noadditional +nostats
Output 1:
; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.mat.unical.it
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7999
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 3, ADDITIONAL: 4
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.mat.unical.it. IN A
;; ANSWER SECTION:
www.mat.unical.it. 258407 IN CNAME sv.mat.unical.it.
sv.mat.unical.it. 258408 IN A 160.97.62.1
...
...
9. iperf
19
Sinossi:
iperf [-s|-c] [opzioni] [host]
Esempi:
iperf -s π‘ͺ Avvia un server in ascolto di un client per la misurazione della banda
iperf βc localhost π‘ͺ Avvia una connessione client su un server in localhost
Output:
------------------------------------------------------------
Client connecting to localhost, TCP port 5001
TCP window size: 512 KByte (default)
------------------------------------------------------------
[ 3] local 127.0.0.1 port 51233 connected with 127.0.0.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 3.04 GBytes 2.61 Gbits/sec
10. tcpdump
20
Sinossi:
tcpdump [opzioni]
Esempi:
tcpdump βi eth0 π‘ͺ Ascolta solo su un'interfaccia (eth0)
tcpdump -i eth0 -nnXvvSeq -c 10 π‘ͺ Ascolta le eth0 senza resolvere i nomi degli hosts e mostrando info dettagliate
Output:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
11:27:40.161870 IP 37.187.111.190.9418 > 160.97.63.164.50000: Flags [P.], seq 3352199730:3352199926, ack 3568060729, win 337, length 196
11. route
21
Sinossi:
route [opzioni]
Esempi:
route π‘ͺ Mostra la routing table dellβhost corrente
route βn π‘ͺ Mostra la routing table con address numerici
route βe π‘ͺ Mostra la routing table nel formato netstat(8)
Attenzione:
route add βnet 10.0.1.0 netsmask 255.255.255.0 gw 10.0.0.1 dev eth0
route add βnet 10.0.1.0/24 gw 10.0.0.1 dev eth0
Il comando sopra mostrato aggiunge (add β [del per rimuovere]) una nuova rotta alla routing table settando i seguenti parametri:
Output:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.1 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
12. traceroute
22
Sinossi:
traceroute [opzioni] address
Esempi:
traceroute www.mat.unical.it π‘ͺ Traccia le rotte seguite dai pacchetti fino allβhost www.mat.unical.it
traceroute βn www.mat.unical.it π‘ͺ Disabilita il mapping di address e hostname
Output:
traceroute to www.mat.unical.it (160.97.62.1), 30 hops max, 60 byte packets
1 * * *
2 178.33.103.229 0.271 ms 0.211 ms 0.300 ms
3 10.95.33.8 1.396 ms 1.280 ms 1.392 ms
4 91.121.215.177 4.702 ms 213.186.32.213 9.069 ms 9.023 ms
5 91.121.215.218 11.777 ms 94.23.122.136 12.059 ms 12.206 ms
6 91.121.215.195 17.525 ms 91.121.215.221 16.241 ms 16.635 ms
7 217.29.66.39 16.677 ms 16.556 ms 16.035 ms
8 90.147.80.18 34.384 ms 34.400 ms 34.815 ms
9 90.147.80.30 31.151 ms 30.399 ms 30.930 ms
10 90.147.82.242 34.596 ms 34.179 ms 35.146 ms
11 193.206.142.194 34.141 ms 34.110 ms 33.701 ms
...
...
...
30 * * *
Comandi utili per il debug di problemi di rete β Parte 3
23
13. arp
24
Sinossi:
arp [opzioni]
Esempi:
arp π‘ͺ Mostra la arp table dellβhost corrente
arp βn π‘ͺ Mostra la arp table senza risolvere gli hostname
arp βs hostname π‘ͺ Aggiunge una static entry nella arp table
arp βd hostname π‘ͺ Rimuove una entry nella arp table
Output:
Address HWtype HWaddress Flags Mask Iface
10.0.0.1 ether 00:07:b4:00:00:01 C eth0
10.0.1.1 ether 00:07:b4:00:00:01 C eth0
10.0.1.1 ether 00:07:b4:00:00:01 C eth0
172.17.2.2 (incomplete) docker0
10.0.0.1 ether 00:07:b4:00:00:01 C eth0
14. iftop
25
Sinossi:
iftop [opzioni]
Esempi:
iftop π‘ͺ Mostra in realtime le statistiche sullβuso della banda
iftop βp π‘ͺ Mostra lβuso della banda in modalitΓ Β«promiscuous modeΒ»
iftop βnN π‘ͺ Mostra lβuso della banda senza risolvere hostname e porte
Output:
191Mb 381Mb 572Mb 763Mb 954Mb
βββββββββββββββββββββββββ΄ββββββββββββββββββββββββ΄ββββββββββββββββββββββββ΄ββββββββββββββββββββββββ΄βββββββββββββββββββββββns327787.ip-XX-XXX-XXX.eu => net-Y-YY-YYY-Y.cust.vodafonedsl.it 0b 1.88Mb 1.88Mb
<= 0b 46.4Kb 46.4Kb
pc.ip-XX-XXX-XXX.eu => net-Y-YY-YYY-Y.cust.vodafonedsl.it 2.01Mb 1.12Mb 1.12Mb
<= 21.2Kb 9.40Kb 9.40Kb
pc.ip-XX-XXX-XXX.eu => A.AAA.AAA.A 0b 1.10Mb 1.10Mb
<= 0b 2.10Kb 2.10Kb
pc.ip-XX-XXX-XXX.eu => net-Y-YY-YYY-Y.cust.vodafonedsl.it 1.57Mb 1.05Mb 1.05Mb
<= 20.8Kb 15.3Kb 15.3Kb
pc.ip-XX-XXX-XXX.eu => CCC-90-static.CC-CC-b.business.telecomita 624Kb 483Kb 483Kb
<= 16.3Kb 12.7Kb 12.7Kb
pc.ip-XX-XXX-XXX.eu => hostRR-RR-dynamic.RRR-RR-r.retail.telecomitali 444Kb 315Kb 315Kb
<= 8.77Kb 6.00Kb 6.00Kb
pc.ip-XX-XXX-XXX.eu => S-SSS-S-SS.ipSS.fastwebnet.it 252Kb 288Kb 288Kb
<= 6.41Kb 4.48Kb 4.48Kb
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββTX: cum: 5.41MB peak: 9.62Mb rates: 6.41Mb 7.21Mb 7.21Mb
RX: 95.3KB 175Kb 129Kb 127Kb 127Kb
TOTAL: 5.50MB 9.79Mb 6.54Mb 7.34Mb 7.34Mb
2: Application Layer