Skip to content

Instantly share code, notes, and snippets.

@hamidrhashmi
Last active February 13, 2025 06:36
Show Gist options
  • Save hamidrhashmi/9c787d8ba8d73bdc486694964ec484de to your computer and use it in GitHub Desktop.
Save hamidrhashmi/9c787d8ba8d73bdc486694964ec484de to your computer and use it in GitHub Desktop.
Use full Linux Commands

How to check the Linux OS version

lsb_release -a 

OR

cat /etc/*lease

How to grep network traffic on a specific port or port range

ngrep -W byline -d eno3 -l -t -O dump.pcap  portrange 5060-6000 
ngrep -W byline -d eno3 -l -t -O dump.pcap  portrange 5060-6000  > debug.log
ngrep -W byline -d any -l -t -O dump.pcap  > debug.log
ngrep -W byline -d any -l portrange 5060-6000 and (ip[6:2] & 0x3fff != 0)
ngrep -W byline -d any -l -t -O dump.pcap  -F filter.txt > debug.log

andother example with tcpdump

tcpdump -i any not port 5060 and not port 22 and not arp and not icmp and not port bootps -nn -w ./NGCP+RTP.pcap

Scan if remote port is open or not

nmap -sU 127.0.0.1 -p 9063 --reason
nmap -sT 127.0.0.1 -p 9062 --reason
Write string on socket
echo "HEP0BLABLABLABLABLA" | nc 127.0.0.1 9082
Delete journalctl logs
journalctl --vacuum-size=512M
How to copy lines in Vim with a mouse
set mouse-=a

Delete a row in Clickhouse-Database

alter table fraud_rules delete where uuid='0c026a6b-a4ef-48d6-b2e1-7066007554ab';
insert into users (username, partid,email,firstname,lastname,department,usergroup,hash) VALUES('admin','10','root@localhost','Hepic','Admin','Develop','admin','$2a$10$yAltOkF7vWTjBM74DetN4./pygRlAYzV.Dgg0GwVHD466d3b0.Qe.');

Check clickhouse-Database table sizes

export CLICKHOUSE_PASSWORD=`cat /etc/clickhouse-server/users.d/users_hepic.xml | grep "<password>"|  awk '{ print $1 }' | grep -v Example: | sed 's/<password>//g' | sed 's/<\/password>//g'`
clickhouse-client -u default --password $CLICKHOUSE_PASSWORD -q "SELECT table, formatReadableSize(sum(bytes)) AS size, min(min_date) AS min_date, max(max_date) AS max_date FROM system.parts WHERE active GROUP BY table"

How to add firewall rules using firewalls

firewall-cmd --zone=public --add-port={5060/udp,18091/tcp,80/tcp,20000-30000/udp,9000/tcp,9062/tcp,18100/tcp}

How to create a quick openssl self-signed certificate

openssl req -new -x509 -nodes -out \
/etc/openldap/certs/myldap.field.linuxhostsupport.com.cert \
-keyout /etc/openldap/certs/myldap.field.linuxhostsupport.com.key \
-days 365

Save Curl output to a file

curl -X POST http://127.0.0.1:18100/api/hepsub/request \
   -H 'Content-Type: application/json' \
   -d '{"uuid":"375fd72a-f051-4cfd-916f-bca3c69fff96","liid":127,"sid":0,"correlation_id":"313633343635353333373530363238-d60yef8r2znw","direction":0,"record_datetime":"2021-10-19T16:55:42+02:00","storedir":"/home/hrhashmi/","src_ip":"92.200.216.135","src_port":53176,"dst_ip":"136.243.16.181","dst_port":20714,"time_sec":1634655342,"time_usec":641247,"proto":17,"ssrc":0,"filename":"rtp_255_0_1633611342651_3502669417_3a8bb82063616c6c02053961@204.197.191.183.pcap","node":"node-botauro","create_date":0,"date":"20211019","type":"mp3","active":true}' \
   --output file.mp3

How to create new MySQL DB USER

SELECT user,authentication_string,plugin,host FROM mysql.user;
create user user@localhost;
grant all privileges on . to user@localhost;
ALTER USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
FLUSH PRIVILEGES;

How to connect Clickhouse-Database

clickhouse-client --host 127.0.0.1 --user default --password `cat /etc/clickhouse-server/users.xml | grep "<password>"|  awk '{ print $1 }' | grep -v Example: | sed 's/<password>//g' | sed 's/<\/password>//g'` -d hepic_data

How to restore Clickhouse-Database

sudo -u clickhouse touch /var/lib/clickhouse/flags/force_restore_data

Check Disk Usage

du -cha --max-depth=1 /var | grep -E "M|G"
Hepgen Tool
pcap2hepgen.js /home/hamid/export_manuallCorrelation.txt /home/hamid/export_manuallCorrelation.js
hepgen.js -s 127.0.0.1 -p 9063 -c /home/hamid/export_manuallCorrelation.js

find and delete some specific files

find / -name clickhouse-* | xargs rm -f

How to top a specific service

 top -p $(pidof clickhouse-server) -H -n 5 > Clickhouse-server.txt

Disk Performance

fdisk -l
hdparm -T /dev/sda1
hdparm -t /dev/sda1

Steno type query

stenotype --preallocate_file_mb=20 --blocks=128 --seccomp=none -v --threads=1 --iface=eth0 --dir=/data/stenographer --fileage_sec=1200 --blockage_sec=30

Kill a TCP connection in debian OS

iptables -A OUTPUT -p tcp --dport 9062 -j REJECT
ss -K dport = 9062

Restore a TCP Connection

iptables -D OUTPUT -p tcp --dport 9062 -j REJECT

File Symlink

unlink filename

ln -vfns /remote/filename filename

How to Read json file in bash

cat /usr/local/hepic/etc/hepicapp_config.json | jq '.loki_config'

update dnf

grep limit /etc/dnf/dnf.conf
installonly_limit=3

Check number of old kernels

rpm -qa | grep kernel

Remove old kernel from CentOS/Rocky/RedHat

dnf -y remove --oldinstallonly --setopt installonly_limit=2 kernel

IPv6 Address

ip -6 -brief address show scope global

Network Monitoring

ethtool -S enp1s0
ethtool -g enp1s0
ethtool -k enp1s0
netstat -antus
watch -d netstat -antus
ethtool -S enp1s0 | grep drop

Save top command to a file

lscpu
netstat -nlpt
top -b -n 1 | head -n 20
top -b -n 1 -H -p `pidof rtpagent`
top -b -n 1 -H -p `pidof picserver`
top -b -n 1 -H -p `pidof clickhouse-server`

Check Service memery consumption

pmap

Simulate bad network

Add Rule

tc qdisc add dev enp0s3 root netem delay 400ms 50ms loss 50% corrupt 10% duplicate 10%

Delete Rule

tc qdisc del dev enp0s3 root netem delay 1500ms 200ms loss 20% corrupt 10% duplicate 5%

Replay a Pcap file

tcpreplay-edit --mtu-trunc -v -i enp0s3 /home/hrhashmi/call_from8882258634.pcap

How to create a Swapfile

sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile

Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)

no label, UUID=71eba4e6-761d-4971-b3e6-14dc2409bd62

sudo swapon /swapfile

/swapfile none swap sw 0 0

-bash: /swapfile: Permission denied

free -m

Enjoy 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment