Ora vivam. Hoje é dia de network (rede) em Linux. Para tal vou deixar aqui uns comandos para dominarem e administrarem as ligações de rede da vossa máquina, saberem quais os portos abertos, correrem um sniffer, etc, etc.
Já têm a shell aberta? Óptimo. Bem, vamos então começar.
>> ping
Serve para verificar a resposta de um outro host (máquina) na rede.
exemplo: ping www.google.com
[root@pplware.com ~]# ping google.com PING google.com (72.14.205.100) 56(84) bytes of data. 64 bytes from google.com (72.14.205.100): icmp_seq=1 ttl=238 time=157 ms 64 bytes from google.com (72.14.205.100): icmp_seq=2 ttl=238 time=155 ms 64 bytes from google.com (72.14.205.100): icmp_seq=3 ttl=238 time=155 ms
>> traceroute <nome da máquina>
Com traceroute podemos ver em tempo real todo o caminho que um pacote percorre até chegar ao seu destino.
exemplo: traceroute www.google.com
>> netstat –r (ou route –v)
Ver rotas
[root@pplware.com]# netstat -r Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 169.254.0.0 * 255.255.0.0 U 0 0 0 eth0 10.15.0.0 * 255.255.0.0 U 0 0 0 eth0 default 10.10.254.254 0.0.0.0 UG 0 0 0 eth0
>> netstat –a
Ver portas abertas no computador
>> netstat –nt
Verifica todas as ligações TCP
[root@pplware.com]# netstat -nt Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 192.18.0.77:49453 192.18.0.20:389 ESTABLISHED tcp 0 0 127.0.0.1:5432 127.0.0.1:48896 ESTABLISHED tcp 0 0 127.0.0.1:5432 127.0.0.1:47444 ESTABLISHED
>> ifconfig (ou ip addr show)
Mostra o endereço IP da nossa máquina
[root@pplware.com]# ifconfig eth0 Link encap:Ethernet HWaddr 00:04:75:C8:1E:C9 inet addr:192.18.0.20 Bcast:192.18.0.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2562828 errors:0 dropped:0 overruns:1 frame:0 TX packets:819327 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:283710198 (270.5 MiB) TX bytes:119183438 (113.6 MiB) Interrupt:193 Base address:0x6000
lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:25326 errors:0 dropped:0 overruns:0 frame:0 TX packets:25326 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:7914566 (7.5 MiB) TX bytes:7914566 (7.5 MiB)
>> telnet <hostname> <porto>
Permite ligar um determinado host a um porto específico.
exemplo: telnet www.google.com 80
>> dig
Permite fazer consultas mais detalhadas ao serviço DNS
[root@pplware.com ~]# dig google.com
; <<>> DiG 9.3.3rc2 <<>> google.com ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36771 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION: ;google.com. IN A
;; ANSWER SECTION: google.com. 274 IN A 72.14.205.100 google.com. 274 IN A 74.125.45.100 google.com. 274 IN A 209.85.171.100
;; Query time: 1 msec ;; SERVER: 172.16.0.2#53(172.16.0.2) ;; WHEN: Tue Dec 9 14:46:26 2008 ;; MSG SIZE rcvd: 76
>> whois
Permite saber informações sobre um determinado domínio.
exemplo: whois sapo.pt
>> nslookup
Resolve o nome de um host para um IP.
[root@pplware.com ~]# nslookup www.google.com Server: 10.10.0.1 Address: 10.10.0.1#53
Non-authoritative answer: www.google.com canonical name = www.l.google.com. Name: www.l.google.com Address: 74.125.39.147 Name: www.l.google.com Address: 74.125.39.104 Name: www.l.google.com Address: 74.125.39.99 Name: www.l.google.com Address: 74.125.39.103
>> mtr
mostra a rota até determinado IP
>> tcpdump -i <interface>
Sniffer de rede.
Exemplo: tcpdump –i eth0
>> iptab
Para quem já não se lembrar de subnetting
exemplo: iptab
[root@pplware.com ~]# iptab +———————————————-+ | addrs bits pref class mask | +———————————————-+ | 1 0 /32 255.255.255.255 | | 2 1 /31 255.255.255.254 | | 4 2 /30 255.255.255.252 | | 8 3 /29 255.255.255.248 | | 16 4 /28 255.255.255.240 | | 32 5 /27 255.255.255.224 | | 64 6 /26 255.255.255.192 | | 128 7 /25 255.255.255.128 | | 256 8 /24 1C 255.255.255.0 | | 512 9 /23 2C 255.255.254.0 | | 1K 10 /22 4C 255.255.252.0 | | 2K 11 /21 8C 255.255.248.0 | | 4K 12 /20 16C 255.255.240.0 | | 8K 13 /19 32C 255.255.224.0 | | 16K 14 /18 64C 255.255.192.0 | | 32K 15 /17 128C 255.255.128.0 | | 64K 16 /16 1B 255.255.0.0 | | 128K 17 /15 2B 255.254.0.0 | | 256K 18 /14 4B 255.252.0.0 | | 512K 19 /13 8B 255.248.0.0 | | 1M 20 /12 16B 255.240.0.0 | | 2M 21 /11 32B 255.224.0.0 | | 4M 22 /10 64B 255.192.0.0 | | 8M 23 /9 128B 255.128.0.0 | | 16M 24 /8 1A 255.0.0.0 | | 32M 25 /7 2A 254.0.0.0 | | 64M 26 /6 4A 252.0.0.0 | | 128M 27 /5 8A 248.0.0.0 | | 256M 28 /4 16A 240.0.0.0 | | 512M 29 /3 32A 224.0.0.0 | | 1024M 30 /2 64A 192.0.0.0 | | 2048M 31 /1 128A 128.0.0.0 | | 4096M 32 /0 256A 0.0.0.0 | +———————————————-+ Se me esqueci de algum, avisem !!!! Feliz Natal 🙂