Last active
December 19, 2020 10:17
-
-
Save ivbor7/0ae7741e70a54809cb8cf1276bcdcd18 to your computer and use it in GitHub Desktop.
Collect the TCP configuration data in Linux
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
#!/bin/bash | |
#--------------------------------------------------------- | |
# Usage: sudo ./collect_data.sh <network-interface-name> | |
#--------------------------------------------------------- | |
# Define some variables | |
LOGFILE=/tmp/tcp_conf.log | |
DateStr=$(date +"%Y-%m-%d %H:%M:%S") | |
# Make shure the script is being executed with root privileges | |
if [[ "${UID}" -ne 0 ]] | |
then | |
echo "Please run the script with sudo or as root. It's needed just for tcpdump in the very end of the script." >&2 | |
echo -e "\n\e[92mUsage: sudo ${0} <network-interface-name>\e[32m" >&2 | |
tput sgr0 | |
exit 1 | |
fi | |
function print_line () { | |
echo "--------------------------------------------------------------" >> $LOGFILE 2>&1 | |
} | |
# Read the NIC | |
if [[ -z $1 ]] | |
then | |
echo "The number of arguments passed to the script: $#" | |
echo -e "\n\e[92mUsage: sudo ${0} <network-interface-name>\e[32m" | |
ip a s | grep -E "inet.*brd|^[0-9]:" | |
tput sgr0 | |
read -p "Enter the name of NIC:" NIC | |
else | |
NIC=$1 | |
fi | |
# Get the internal and external IPs | |
EXTERNAL_IP=$(curl ifconfig.me) | |
INTERNAL_IP=$(ip addr show ${NIC} | grep "inet " | awk '{print $2}' | cut -d / -f 1) | |
# Create a log file if it not exist | |
if [[ ! -f ${LOGFILE} ]] | |
then | |
>"${LOGFILE}" | |
fi | |
uname -n >> $LOGFILE 2>&1 | |
print_line | |
ip a s $NIC | grep -E "inet.*brd|^[0-9]:" >> $LOGFILE 2>&1 | |
echo "External_ip: ${EXTERNAL_IP}" >> $LOGFILE 2>&1 | |
print_line | |
free -m >> $LOGFILE 2>&1 | |
print_line | |
lshw -C network >> $LOGFILE 2>&1 | |
print_line | |
echo "$DateStr Internal IP: ${INTERNAL_IP}; External IP: ${EXTERNAL_IP} " >> $LOGFILE 2>&1 | |
echo "$DateStr TCP buffer sizes:" >> $LOGFILE 2>&1 | |
echo "tcp_mem: $(cat /proc/sys/net/ipv4/tcp_mem)" >> $LOGFILE 2>&1 | |
print_line | |
echo "$DateStr the default and maximum amount for the receive socket memory:" >> $LOGFILE 2>&1 | |
echo "rmem_default: $(cat /proc/sys/net/core/rmem_default)" >> $LOGFILE 2>&1 | |
echo "rmem_max: $(cat /proc/sys/net/core/rmem_max)" >> $LOGFILE 2>&1 | |
print_line | |
echo "$DateStr the default and maximum amount for the send socket memory:" >> $LOGFILE 2>&1 | |
echo "wmem_default: $(cat /proc/sys/net/core/wmem_default)" >> $LOGFILE 2>&1 | |
echo "wmem_default: $(cat /proc/sys/net/core/wmem_max)" >> $LOGFILE 2>&1 | |
print_line | |
echo "$DateStr maximum amount of option memory buffers:" >> $LOGFILE 2>&1 | |
echo "optmem_max: $(cat /proc/sys/net/core/optmem_max)" >> $LOGFILE 2>&1 | |
print_line | |
echo "default congestion control is: $(sysctl net.ipv4.tcp_congestion_control)" >> $LOGFILE 2>&1 | |
echo "list of congestion control algorithms that are available in the kernel: $(sysctl net.ipv4.tcp_available_congestion_control)" >> $LOGFILE 2>&1 | |
echo "MTU probing is: $(sysctl net.ipv4.tcp_mtu_probing)" >> $LOGFILE 2>&1 | |
echo "Fair queueing is: $(sysctl net.core.default_qdisc)" >> $LOGFILE 2>&1 | |
echo "Window scaling is: $(sysctl net.ipv4.tcp_window_scaling)" >> $LOGFILE 2>&1 | |
echo "Maximum number of packets, queued on the INPUT side: $(sysctl net.core.netdev_max_backlog )" >> $LOGFILE 2>&1 | |
echo "========================================================================" >> $LOGFILE 2>&1 | |
echo "TCP Socket memory usage:" >> $LOGFILE 2>&1 | |
ss -tm >> $LOGFILE 2>&1 | |
# Uncomment the below line to install the tcpdump utility | |
# command -v tcpdump >> $LOGFILE 2>&1 || apt install -y tcpdump | |
# or run this command manualy | |
# tcpdump -ttt -nni eth0 -s0 '(host <INTERNAL_IP> or <EXTERNAL_IP>) and (not port 22 or 53) and not icmp' -c 10000 -C 5000 -w /tmp/tcp_dump.pcap | |
# tcpdump -ttt -nni ${NIC} -s0 -w /tmp/tcp_dump.pcap -c 10000 -C 10000 host ${EXTERNAL_IP} and not port 22 and not port 53 and not icmp | |
tcpdump -tttt -nni ${NIC} -s0 -w /tmp/tcp_dump.pcap -c 10000 -C 10000 'not port 22 and not port 53 and not icmp' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment