[Day 7] 5. LAB 3 GeoIP Traffic Filtering and Logging
Objective:
To block traffic from China and log the packets received, ensuring proper traffic filtering and logging using
iptablesxtablesSteps:
-
Install Required Dependencies:
bashsudo apt-get install -y automake ca-certificates gcc libc6-dev libnet-cidr-lite-perl libtext-csv-xs-perl libxtables-dev linux-headers-$(uname -r) make pkg-config unzip wget xz-utils sudo which iptables sudo apt-get install iptables -y -
Source Code Extraction:
-
Sir will provide the source code.
-
Extract it using the following command:
bashtar -xf <file_name> -
Note: This command is used because the file extension is different.
-
-
Build and Install
:xtables-
Navigate to the extracted folder:
bashcd <extracted_folder> -
Run the following commands:
bashsudo ./configure sudo make sudo make install -
Verify installation:
bashls -l /usr/local/libexec/xtables-addons/
-
-
Create Directory for GeoIP Database:
-
Create a working directory for GeoIP:
bashmkdir xtables cd xtables -
Download the GeoIP database:
bash/usr/local/libexec/xtables-addons/xt_geoip_dl ls -l -
Create the GeoIP directory:
bashsudo mkdir /usr/share/xt_geoipNote: The directory name must be
.xt_geoip
-
-
Process GeoIP Database:
-
Ensure you are in the
directory:xtablesbashcd xtables -
Build the GeoIP database:
bashsudo /usr/local/libexec/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip/ *.csv -
Verify database creation:
bashls -lThis command will add entries to the GeoIP directory. If no
file is present, it won't work..csv
-
-
Handle Errors:
- If any error occurs, restart the process from step 1.
-
Verify GeoIP Module:
-
Test the GeoIP module (this will initially throw an error):
bashsudo iptables -m geoip -h
-
-
Load GeoIP Dependencies:
-
Load dependencies into memory using:
bashsudo depmod -a -
Retry the GeoIP test:
bashsudo iptables -m geoip -h
-
-
Traffic Blocking and Logging:
-
Do NOT Run: Command to drop packets from China:
bashsudo iptables -A INPUT -m geoip --src-cc CN -j DROP -
Run This Instead: Command to log packets from China:
bashsudo iptables -A INPUT -m geoip --src-cc CN -j LOG --log-level debug --log-prefix "| Kuch Bhi China |"This will redirect Chinese traffic to the logs with a debug level and a prefix
.Kuch Bhi
-
-
View Iptables Rules:
bashsudo iptables -L -
Monitor Logs in Real-Time:
bashsudo journalctl -fThis command displays logs in real-time.
DIY Task:
- Research how to generate an IP address from China for testing purposes.
Read Next
[Day 7] 6. Extra
- **MOU**: Memorandum of Understanding; a formal agreement between two or more parties outlining their intentions to collaborate or work togeth...
[Day 8] 1. PKI using XCA (LAB 1)
#### **1. Installation of XCA** - Install **XCA** on your Windows machine using the "typical" installation option. - Complete the installation and...