This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
All connections to server | |
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | |
All connection States | |
netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n | |
Limit HTTP connections to 20 sessions | |
iptables -I INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above | |
20 --connlimit-mask 24 -j DROP | |
Checking how many connections to 80 | |
netstat -n | grep :80 |wc -l |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Users & Groups | |
Group file: /etc/group | |
Add User: | |
adduser USER | |
New Group: | |
groupadd GROUP | |
newgrp GROUP | |
Account numbering and important settings: /etc/login.defs | |
Own a user a folder: | |
chown -R USER FOLDER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PostgreSQL | |
Client: psql | |
Connect to server: psql -h server.domain.org database user | |
Connection quit: \q | |
Connect: sudo -u postgres psql postgres | |
Create user: sudo -u postgres createuser -D -A -P myuser | |
Create Database: sudo -u postgres createdb -O myuser mydb | |
Drop Database: drop database DATABASE ; | |
Dump Database: pg_dump -Fc -U USER DATABASE > NAME | |
Restore Database: pg_restore -Fc -j CORE_LIMIT -U USER -d DB OLDDB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NMAP | |
Ping with nmap | |
nmap -sP IP | |
Port state | |
nmap --reason HOST | |
TCP connect() scan—(Nmap -sT ) | |
TCP SYN or half-open scan—(Nmap -sS ) | |
TCP FIN, XMAS, and NULL scans—(Nmap -sF , -sX , -sN ) | |
TCP ACK scan—(Nmap -sA ) | |
TCP idle scan—(Nmap -sI ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NetCat | |
Ex: nc -v IP PORT → Connect to the port | |
Open port and listen: nc -k -l PORT → -k means keep listening | |
Port scanning: nc -zv IP PORTRANGE | |
nc -p 31337 -w 5 host.example.com 42 | |
Open a TCP connection to port 42 of host.example.com, using port 31337 as | |
the source port, with a timeout of 5 seconds: | |
nc -u host.example.com 53 | |
Open a UDP connection to port 53 of host.example.com | |
To listen on port PORT and accept: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kill TCP connection | |
tcpkill -9 host google.com | |
Create IPIP Tunnel: | |
Linux 1: | |
# ip tunnel add ipip-Tunnel mode ipip remote 20.0.0.2 local 20.0.0.1 | |
# ifconfig ipip-Tunnel 10.0.0.1/24 | |
Linux 2: | |
# ip tunnel add ipip-Tunnel mode ipip remote 20.0.0.1 local 20.0.0.2 | |
# ifconfig ipip-Tunnel 10.0.0.2/24 | |
# ip tunnel show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lsof → List open files. | |
lsof -i :PORT → Shows networking related port | |
lsof -i@IP → Shows connections to a specific host | |
lsof -i -sTCP:LISTEN → Shows listening ports | |
lsof -i -sTCP:ESTABLISHED → Shows established connections | |
lsof -u USER → What user opens | |
lsof DIR → Shows everything interacting with a given DIR | |
lsof -i :PORT → Shows which process uses the port |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Find all files in home folder with mp3 format | |
find ~ -iname '*.mp3' | |
Find all directories with 777 perm | |
find /var/www -type d -perm 777 | |
Find all files greater than 20M and sort | |
find / -type f -size +20M -exec ls -lh {} \; 2> /dev/null | awk '{ print | |
$NF ": " $5 }' | sort -nk 2,2 | |
Find text files that were last modified 60 days ago | |
find /home/you -iname "*.txt" -mtime -60 -print |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nethogs - iptraf - bmon - iftop - nmon - glances - iostat - iotop - tload - pstree | |
- httpry- dhcpdump - mysql-sniffer - p0f - pktstat- sysdig- tcptrack - | |
vnstat - goaccess - apachetop - whowatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
According to some problems which happend on servers, it's good idea to use Tmux with RED pane color on servers to avoid problems. | |
After installing Tmux, put this config in "/etc/tmux.conf" or "~/.tmux.conf": set -g status-bg red | |
My terminal demonstration: | |
Green: is my local tmux | |
Red: is server tmux |