Skip to content

Instantly share code, notes, and snippets.

@eric-glb
Last active February 14, 2023 20:21
Show Gist options
  • Save eric-glb/72460d8051cd0176c90729656000605f to your computer and use it in GitHub Desktop.
Save eric-glb/72460d8051cd0176c90729656000605f to your computer and use it in GitHub Desktop.
One-liner to find the gateway from a running minimal container, using /proc/net/route
GW=$(</proc/net/route awk 'NR==2 {print $3}' | sed -E 's/(..)/\1 /g' | if read a b c d; then printf '%d.%d.%d.%d' 0x$d 0x$c 0x$b 0x$a; fi)
#!Usr/bin/env bash
GATEWWAY=$( </proc/net/route awk 'NR==2 {print $3}' |
sed -E 's/(..)/\1 /g' |
if read a b c d; then
printf '%d.%d.%d.%d' 0x$d 0x$c 0x$b 0x$a
fi
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment