Skip to content Prejsť na obsah


How to monitor your Linux machine with netstat Ako sledovať váš počítač s Linuxom netstat

LinuxBezpečnosť

Netstat is an extremely useful Linux command line tool that allows you to check which service is connecting to a port on your machine. Netstat je veľmi užitočné, Linux command line nástroj, ktorý vám umožní skontrolovať, ktoré služby je pripojenie k portu na vašom počítači. It is very useful to analyze what's going on on your machine when you are facing or trying to to prevent an attack on it. To je veľmi užitočné analyzovať, čo sa deje na vašom počítači, keď sa pozeráte, alebo sa snažia zabrániť útoku na neho. You can find information such as how many connection are being made on a port, which IP addresses these connections originate from, and much more. Nájdete informácie, ako koľko spojenia sú vykonávané na portu, IP adries, ktoré pochádzajú z týchto spojení, a ešte oveľa viac. Netstat ships with most distributions of Linux so it should already be installed on yours. Netstat lodí, s väčšinou distribúcií Linuxu, takže by malo byť už nainštalovaný na vás.

Launch a shell terminal on your machine and run the following command: Spustenie shellu terminálu na vašom počítači a spustite nasledujúci príkaz:

# netstat -ant # Netstat-ant
Active Internet connections (servers and established) Aktívne pripojenie k internetu (servery a stanovil)
Proto Recv-Q Send-Q Local Address Foreign Address State Preto Recv-Q Send-Q Local adresa Cudzia adresa Stav
tcp 0 0 ::ffff:192.168.1.19:80 ::ffff:192.168.1.240:63049 TIME_WAIT tcp 0 0:: ffff: 192.168.1.19:80:: ffff: 192.168.1.240:63049 TIME_WAIT
tcp 0 0 ::ffff:192.168.0.19:80 ::ffff:192.168.1.240:62793 TIME_WAIT tcp 0 0:: ffff: 192.168.0.19:80:: ffff: 192.168.1.240:62793 TIME_WAIT
tcp 0 0 ::ffff:192.168.1.19:80 ::ffff:192.168.1.240:62795 TIME_WAIT tcp 0 0:: ffff: 192.168.1.19:80:: ffff: 192.168.1.240:62795 TIME_WAIT

The output will most likely be very long. Výstup bude s najväčšou pravdepodobnosťou veľmi dlho. I've just given a snapshot of the output above. Práve som dostal snímka výstupe vyššie. As you can see in the data above there is a connection made from 192.168.1.240 to my server's port 80 using the TCP protocol and the connection in the a state of TIME_WAIT. Ako môžete vidieť vo vyššie uvedených údajov vyplýva, že existuje spojenie z 192.168.1.240 na môj server na porte 80 pomocou protokolu TCP a pripojenie do stavu TIME_WAIT. The out put that you get for your server will have information about all the ports on your machine, not just port 80. Dal, že sa dostanete na serveri budú mať informácie o všetkých portov na vašom počítači, nie len port 80.

The first thing you realize is that an output this big is not of too much use. Prvá vec, ktorú by ste si uvedomiť, že tento veľký výkon nemá moc využitie. So let's organize it a bit. Tak poďme na to trochu usporiadať. Here are a few tricks I use to analyze the nature of the connections being made to of from my server. Tu je pár trikov, ktoré používam na analýzu charakteru pripojenie, ktoré robí z z môjho servera. the first thing I do is figure out which services I want to analyze. Prvá vec, ktorú robím, je zistiť, aké služby chcem analyzovať. Usually it is port 80 as that's the default port for the web server to run on, and port 3306 which is the default port for MySQL to run on. Zvyčajne je to port 80, tak ako to je štandardný port pre webový server bežať ďalej, a port 3306, ktorý je štandardný port pre MySQL až k plynúť ďalej. So i use the following query to see what's going on on port 80: Tak aj pomocou nasledujúceho dotazu zistiť, čo sa deje na porte 80:

# netstat -ant | grep 80 # Netstat-ant | grep 80

Again I get big list of connections, smaller than the first, but still too big to grasp. Znovu som si veľký zoznam spojenie, menší ako ten prvý, ale stále príliš veľká, aby pochopili. So I use the “wc -l” command to count the number of lines in the output to see approximately how many connections I have on my port 80: Tak som sa použiť "wc-l" príkaz spočítať počet riadkov produkcie asi vidieť, koľko spojov mám na svojom porte 80:

# netstat -ant | grep 80 | wc -l # Netstat-ant | grep 80 | wc-l
625 625

And then I do the same for MySQL: A potom som sa urobiť to isté pre MySQL:

# netstat -ant | grep 3306 | wc -l # Netstat-ant | grep 3306 | wc-l
61 61

Now, if I want to get a complete picture of what's going on on my server in terms of the nature of connections here's what I do: Teraz, keď chcem získať ucelený obraz o tom, čo sa deje na svojom serveri, pokiaľ ide o typ koncentrácie tu je to, čo mám robiť:

# netstat -ant | awk '{print $6}' | sort | uniq -c | sort -n # Netstat-ant | awk '(print $ 6)' | sort | Uniq-c | sort-n

1 established) 1 usadené)
1 Foreign 1 Zahraniční
4 FIN_WAIT2 4 FIN_WAIT2
8 LISTEN 8 LISTEN
16 CLOSE_WAIT 16 CLOSE_WAIT
134 ESTABLISHED 134 establish D
409 TIME_WAIT 409 TIME_WAIT

This tells me how many connections of different types of state I have on my machine. Táto mi hovorí, ako veľa spojov rôznych typov štátnych mám na mojom stroji. I can run a similar command to see a complete picture of the state of all the connections made to my web server: Nemôžem spustiť príkaz podobný vidieť úplný prehľad o stave všetkých pripojení sa na môj web server:

netstat -ant | grep 80 | awk '{print $6}' | sort | uniq -c | sort -n netstat-ant | grep 80 | awk '(print $ 6)' | sort | Uniq-c | sort-n

1 FIN_WAIT1 1 FIN_WAIT1
4 LISTEN 4 LISTEN
6 FIN_WAIT2 6 FIN_WAIT2
17 CLOSE_WAIT 17 CLOSE_WAIT
94 ESTABLISHED 94 establish D
534 TIME_WAIT 534 TIME_WAIT

You can perform a lot more complex things using Netstat along with other Linux command line tools. Môžete urobiť oveľa zložitejšie veci pomocou Netstat spolu s ďalšími nástrojmi príkazového riadka Linuxu. It can be helpful to be familiar with some tricks to get this kind of information using Netstat, particularly when you are facing an attack on your server. To môže byť užitočné poznať niekoľko trikov, ktoré si tento druh informácií pomocou Netstat, obzvlášť, keď sa pozeráte na útok na vašom serveri.

Posted in Publikované v Linux Linux , , Security Bezpečnosť . .

Related Posts: Súvisiace zmeny:

How to monitor your Internet bandwidth usage in Windows Ako sledovať vaše internetové využitie šírky pásma v systéme Windows
How to set the date on your Linux machine Ako nastaviť dátum na počítači Linux
How to use dstat to monitor your Linux/UNIX server Ako používať dstat sledovať váš Linux / Unix Server
How to redirect traffic to another machine in Linux Ako presmerovať prevádzku na iný stroj v Linuxe
How to see a detailed history of the commands run in Linux Ako vidieť podrobnú históriu príkazov spustiť v Linuxe

2 Responses 2 Citlivosť

Stay in touch with the conversation, subscribe to the Zostať v kontakte s konverzácia, prihláste sa RSS feed for comments on this post RSS kanál pre komentáre k tomuto príspevku . .

  1. Quetzal Guatemalský quetzal says hovorí

    nice web translation nice preklady internetových stránok :-P

  2. Swaroop - India Web Hosting Swaroop - India web hosting says hovorí

    Nice Tutorial! Nice výučba!



Some HTML is OK Niektoré HTML je v poriadku

or, reply to this post via alebo odpovede na tento príspevok prostredníctvom trackback Trackback . .