Skip to content Gå til innhold


How to monitor your Linux machine with netstat Hvordan overvåke din Linux-maskin med netstat

LinuxSikkerhet

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 er et svært nyttig Linux kommandolinje-verktøy som lar deg sjekke hvor tjenesten er å koble til en port på din maskin. 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. Det er svært nyttig å analysere hva som skjer på maskinen når du står eller prøver å å hindre et angrep på den. 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. Du kan finne informasjon, for eksempel hvor mange forbindelsen blir gjort på en port, som IP-adresser disse forbindelsene kommer fra, og mye mer. Netstat ships with most distributions of Linux so it should already be installed on yours. Netstat skip med de fleste distribusjoner av Linux, så det burde allerede være installert på din.

Launch a shell terminal on your machine and run the following command: Starte et shell-terminal på maskinen din og kjøre følgende kommando:

# netstat -ant # Netstat-ant
Active Internet connections (servers and established) Aktiv Internett-tilkoblinger (servere og etablerte)
Proto Recv-Q Send-Q Local Address Foreign Address State Proto recv-Q Send-Q Local Address Foreign Address State
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. Produksjonsgapet vil mest sannsynlig bli svært lang. I've just given a snapshot of the output above. Jeg har nettopp fått et øyeblikksbilde av produksjonen ovenfor. 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. Som du kan se på dataene over det er en sammenheng laget fra 192.168.1.240 til min server's port 80 bruker TCP-protokollen og sammenhengen i en tilstand av 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. De la ut på at du får for din server vil ha informasjon om alle portene på din maskin, og ikke bare port 80.

The first thing you realize is that an output this big is not of too much use. Det første du innser er at en produksjon denne store, er ikke av for mye bruk. So let's organize it a bit. Så la oss organisere det litt. Here are a few tricks I use to analyze the nature of the connections being made to of from my server. Her er noen triks jeg bruker for å analysere innholdet i tilkoblingene gjøres til av fra serveren min. the first thing I do is figure out which services I want to analyze. det første jeg gjør er å finne ut hvilke tjenester jeg ønsker å analysere. 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. Vanligvis er det port 80 som det er standard port for web-serveren for å kjøre på, og port 3306 som er standard port for MySQL å kjøre på. So i use the following query to see what's going on on port 80: Så jeg bruke følgende spørring for å se hva som skjer på port 80:

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

Again I get big list of connections, smaller than the first, but still too big to grasp. Igjen får jeg store listen over tilkoblinger, mindre enn den første, men fortsatt for stor til å fatte. 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: Så jeg bruker "wc-l" kommandoen til å telle antall linjer i produksjonen for å se omtrent hvor mange forbindelser jeg har på min port 80:

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

And then I do the same for MySQL: Og så gjøre det samme for MySQL:

# netstat -ant | grep 3306 | wc -l # Netstat-maur | 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: Nå, hvis jeg ønsker å få et fullstendig bilde av hva som skjer på serveren min i forhold til natur forbindelser her er hva jeg gjør:

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

1 established) 1 etablerte)
1 Foreign 1 Utenlandske
4 FIN_WAIT2 4 FIN_WAIT2
8 LISTEN 8 LISTEN
16 CLOSE_WAIT 16 CLOSE_WAIT
134 ESTABLISHED 134 ESTABLISHE D
409 TIME_WAIT 409 TIME_WAIT

This tells me how many connections of different types of state I have on my machine. Dette forteller meg hvor mange forbindelser av ulike typer statlige jeg har på min maskin. I can run a similar command to see a complete picture of the state of all the connections made to my web server: Jeg kan kjøre en lignende kommando for å se et fullstendig bilde av tilstanden til alle tilkoblinger gjort til min webserver:

netstat -ant | grep 80 | awk '{print $6}' | sort | uniq -c | sort -n netstat-maur | 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 ESTABLISHE D
534 TIME_WAIT 534 TIME_WAIT

You can perform a lot more complex things using Netstat along with other Linux command line tools. Du kan utføre mye mer kompliserte ting med Netstat sammen med andre Linux kommandolinje-verktøy. 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. Det kan være nyttig å være kjent med noen triks for å få denne type informasjon ved hjelp Netstat, spesielt når du står overfor et angrep på serveren.

Posted in Posted in Linux Linux , , Security Sikkerhet . .

Get Simple Help tutorials just like this one in your email inbox every day - for free! Få Enkelt Hjelp opplæring akkurat som dette i innboksen hver dag - helt gratis! Just enter your email address below: Bare skriv inn din e-postadresse nedenfor:

You can always opt out of this email subscription at any time. Du kan alltid velge bort denne e-abonnementet når som helst.

2 Responses 2 Svar

Stay in touch with the conversation, subscribe to the Hold kontakten med samtalen, abonnere på RSS feed for comments on this post RSS feed for kommentarer til dette innlegget . .

  1. Quetzal Quetzal says sier

    nice web translation nice web oversettelse :-P

  2. Swaroop - India Web Hosting Swaroop - India Web Hosting says sier

    Nice Tutorial! Nice opplæring!



Some HTML is OK Some HTML is OK

or, reply to this post via eller svare på dette innlegget via trackback styrekule . .