This Gist contains a few tips and tricks that I've gathered over time to optimize my experience when working on unix based systems. Some of the things mentioned in this document, will explained in further detail below. This file will contain things in a more compact manner.
Ping though a specific NIC:
If you have multiple NICs, i.e.
eth0 10.0.0.2
eth1 172.16.0.6
You can ping through a particular NIC using -S
:
ping google.com -S 10.0.0.2 # through eth0
ping 10.0.0.1 -S 10.0.0.2 # through eth0
ping 172.16.1.123 -S 172.16.0.6 # through eth1
Show time:
# on macOS
ping --apple-time 1.1.1.1
Ping every n seconds:
ping -i 2 1.1.1.1 # every 2 seconds
Ping 1.1.1.1 every 5 seconds through NIC on 10.0.0.2 with time:
ping --apple-time -i 5 -S 10.0.0.2 1.1.1.1
On sender's end, cd
into the directory you want to serve files from. Then
python3 -m http.server {port}
The file can now be downloaded on http://{ip}:{port}/relative/path/to/file
, i.e.
curl -O http://127.0.0.1:1234/my-file.txt
For a simpler usecase, we can use netcat
Receivers End:
nc -lp 1234 > out.file
# or on macOS:
nc -l 1234 > out.file
Senders End:
nc -w 3 {ip} {port} < in.file
A cool use-case is for sending a file to a server:
ssh [email protected]
nc -lp 1234 > my.file & # backgrounds the process, this will end once the file has been received
exit
nc -w 3 my.host 1234 < my.file # mostly useful on local networks, as the port (1234 in this case) has to be open
# the process on the server will end once the file has been uploaded
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "[email protected]"
SHA256:
ssh-keygen -lf ~/.ssh/my-key.pub
MD5:
ssh-keygen -lE md5 -f ~/.ssh/my-key.pub
Forward a port on a server to your local machine:
ssh -L {local port}:127.0.0.1:{remote port} [email protected]
# ex
ssh -L 9999:127.0.0.1:1433 # forwards port 1433 on server 127.0.0.1 to your local machine on port 9999
Sometimes the SSH connection gets stale, and makes your terminal hang. To get out of this (to end the session), type ~.
, and it should stop the process.