Linux
Snippets
Sending signals to process
kill -s SIGUSR1 <process_name>
Create a linux network namespace
sudo ip netns add my-net-ns # create a network namespace
sudo ip netns exec my-net-ns sh # open a shell in the namespace
nsenter --net=/run/netns/netns0 bash # alternative to open a shell in the namespace, note that this
# creates a nested shell session
sudo ip netns exec my-net-ns ip link ls # lists network interfaces
Connecting containers to host using virtual Ethernet devices (veth)
sudo ip link add veth0 type veth peer name veth1
sudo ip link set veth0 netns my-net-ns
sudo ip link set veth1 up
sudo ip netns exec my-net-ns ip link set veth0 up
sudo ip netns exec my-net-ns ip addr add 192.168.1.1/24 dev veth0
Identify port a service listens on
APP_PID="$(sudo pgrep -f /usr/local/bin/app)"
sudo ss -lntp | grep "pid=${APP_PID}," | awk '{print $4}' | cut -d':' -f2
Identify process using given port
# man lsof -> -i [46][protocol][@hostname|hostaddr][:service|port]
sudo lsof -i :12345
# another approach using ss
sudo ss -lntp | grep 12345