Quick and frequent commands

PATH for Debian

echo "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /etc/environment

Make swap file

From superuser:
fallocate -l 1G /swapfile
#or
dd if=/dev/zero of=/swapfile bs=1024 count=1048576
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab

Check and set swappiness

cat /proc/sys/vm/swappiness
echo "vm.swappiness = 15" >> /etc/sysctl.conf
sysctl -p

MySQL create user, database, grant privileges

In mysql cli:
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE db;
GRANT ALL PRIVILEGES ON db.* TO 'user'@'localhost';
FLUSH PRIVILEGES;

Add IP address to network interface

ip addr add 127.0.0.2/16 dev lo

Add route

Default GW:
route add default gw 10.0.0.1

Specified host:
route add -host 8.8.8.8 gw 10.0.0.1

Network route:
ip route add 10.0.1.0/24 via 10.0.1.1 dev eth0

Mount samba share

mount.cifs //ip_addr/share /mnt/share/ -o user=login

Enable IP forwarding

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p

Port forwarding with socat

socat TCP-LISTEN:LOCAL_PORT,fork TCP:REMOTE_IP:REMOTE_PORT

Remove iptables rules

iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X

Restrict access using iptables

ip6tables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -I INPUT 1 -i lo -j ACCEPT
ip6tables -A INPUT -p icmpv6 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

Port forwarding using socat

socat TCP-LISTEN:1500,fork TCP:10.0.0.2:80

Test filesystem with fio

Read:
fio --name TEST --eta-newline=5s --filename=fio-tempfile.dat --rw=read --size=500m --io_size=10g --blocksize=1024k --ioengine=libaio --fsync=10000 --iodepth=32 --direct=1 --numjobs=1 --runtime=60 --group_reporting

Write:
fio --name TEST --eta-newline=5s --filename=fio-tempfile.dat --rw=write --size=500m --io_size=10g --blocksize=1024k --ioengine=libaio --fsync=10000 --iodepth=32 --direct=1 --numjobs=1 --runtime=60 --group_reporting