Last active
April 15, 2023 14:54
-
-
Save YuviGold/7f1bcbbd6c486c53523e8fa1520deca2 to your computer and use it in GitHub Desktop.
Verify running docker containers run with the same MTU as the Uplink
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 | |
set -o nounset | |
set -o errexit | |
set -o pipefail | |
function get_route_device() { | |
ip route get "${1}" | grep -Po '(?<=dev\s)[\w-]+' | cut -f1 -d ' ' | |
} | |
function get_network_mtu() { | |
ip link show "${1}" | head -n 1 | awk '{print $5}' | |
} | |
function get_docker_ip() { | |
docker inspect "${1}" | jq -r '.[].NetworkSettings.Networks | .[].IPAddress' | |
} | |
# get name of uplink lan interface | |
LANIFACE=$(get_route_device 1.1.1.1) | |
# get currently used MTU for uplink | |
MTU_LAN=$(get_network_mtu "${LANIFACE}") | |
echo "Uplink \"${LANIFACE}\" MTU ${MTU_LAN}" | |
RUNNING_CONTAINERS=$(docker ps --format '{{.Names}}') | |
for container in ${RUNNING_CONTAINERS}; do | |
container_ip=$(get_docker_ip "${container}") | |
container_network=$(get_route_device "${container_ip}") | |
network_mtu=$(get_network_mtu "${container_network}") | |
if [[ ${MTU_LAN} -ne ${network_mtu} ]]; then | |
echo "Container \"${container}\" is running in network \"${container_network}\" with MTU ${network_mtu}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment