Skip to content Gå til innhold


How to block an IP address in IPTables in Linux Slik blokkerer en IP-adresse i iptables på Linux

LinuxSikkerhet

If you are responsible for a Linux server, security becomes a big concern. Hvis du er ansvarlig for en Linux server, blir sikkerhet en stor bekymring. Some of the biggest threats to a server's security are DDOS attacks and repeated attempts to enter the server using automates bots. Noen av de største truslene mot en server sikkerhet er DDOS-angrep og gjentatte forsøk på å komme inn på serveren ved hjelp automatiserer bots. There are a number of ways by which you can detect the IP address of a potential intruder. Det finnes en rekke måter som du kan finne IP-adressen til en potensiell inntrenger. But what do you do after you have located his/her IP address? Men hva gjør du etter at du har funnet sin IP-adresse? Well, you block it. Vel, blokkerer du det. Here's how you do it using IPTables which is the firewall that ships with most flavors of Linux. Her er hvordan du gjør det ved hjelp iptables som er brannmuren som leveres med de fleste varianter av Linux.

If you have just one IP address that you want to block you can use the following method: Hvis du har bare én IP-adresse som du vil blokkere kan du bruke følgende metode:

# iptables -I INPUT -s 122.174.12.228 -j DROP # Iptables-I INPUT-s 122.174.12.228-j DROP

This command will add an entry into your iptables configuration file, instructing it to drop any packets that come from the IP 122.172.9.222 . Denne kommandoen vil legge til en oppføring i iptables konfigurasjonsfil, instruerte den til å slippe alle pakker som kommer fra IP 122.172.9.222. If you face numerous attacks you are better of using a slightly more automated method to add the IPs from your ban list. Hvis du står overfor tallrike angrepene du er bedre å bruke en litt mer automatisert metode for å legge til IP fra svartelisten. To do that create the following script: Å gjøre det opprette følgende skript:

#!/bin/sh #! / bin / sh
for i in $(< banned_IPs.cfg) ; do for i in $ (<banned_IPs.cfg); do
iptables -I INPUT -i eth1 -s "$i" -j DROP iptables-I INPUT-i eth1-s "$ i"-j DROP
done ferdig

Save the script into a file named something like banned_IPs.sh and grant it executable privileges: Lagre skriptet i en fil som heter noe sånt som banned_IPs.sh og gi det startbar privilegier:

# chmod +x banned_IPs.sh # Chmod + x banned_IPs.sh

Now create a file called banned_IPs.cfg and enter the list of IP addressed you want to block, each in a new line: Nå oppretter en fil kalt banned_IPs.cfg og skriv en liste med IP adressert du vil blokkere, hver på en ny linje:


122.174.12.228 122.174.12.228
129.122.10.23 129.122.10.23
111.154.84.130 111.154.84.130

Now run the script banned_IPs.sh to have the IP addresses you want blocked added to the list of banned IPs in iptables: Nå kjører skriptet banned_IPs.sh å ha IP-adressene du ønsker blokkert lagt til i listen over forbudte IPer i iptables:

# ./banned_IPs.sh #. / Banned_IPs.sh

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

Related Posts: Relaterte innlegg:

How to block DDOS attacks in Linux Slik blokkerer DDOS-angrep i Linux
How to redirect traffic to another machine in Linux Hvordan omdirigere trafikken til en annen maskin i Linux
Getting started with iptables in Linux Komme i gang med iptables på Linux
How to delete an individual site from the address bar's list of previously viewed sites in Firefox Slik sletter du en individuell området fra adresselinjen liste over tidligere sett nettsteder i Firefox
How to use the OR operator in grep Slik bruker du operatoren OR i grep

One Response One Response

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. Teixeira says Teixeira sier

    Simple, clear and efficient. Enkel, tydelig og effektiv.
    Btw, is there any nice black list website where we can sync the “banned_IPs.cfg” file dailly for example? Btw, er det noen fine svart liste webside der vi kan synkronisere "banned_IPs.cfg" fil Dailly for eksempel? Should be nice…. Skal være snille ....

    br, br,
    TT TT



Some HTML is OK Some HTML is OK

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