Skip to content

Instantly share code, notes, and snippets.

@guedressel
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guedressel/9565506 to your computer and use it in GitHub Desktop.
Save guedressel/9565506 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo
echo
DEVS=($(cat /proc/net/dev | tail -n+3 | cut -d: -f1 | tr -d " "))
for i in "${DEVS[@]}"
do
ip link show $i | grep -q "state DOWN" # check interface status
if (( $? == 1 ))
then
# interface is up
echo "$i:"
ipv4=$(ip addr show $i | grep -o -P "inet ([0-9\.]+)" | cut -d' ' -f2)
ipv6=$(ip addr show $i | grep "inet6 " | sed -n 's/.*inet6 \(.*\)\/.*/\1/p')
if [[ "$ipv4" != "" ]]
then
echo " IPv4 $ipv4"
fi
if [[ "$ipv6" != "" ]]
then
echo " IPv6 $ipv6"
fi
else
# interface is down
#echo "$i (is down)"
do=nothing
fi
done
DEFAULT_ROUTE=$(ip route | grep default | sed -n 's/default via \(.*\) dev.*/\1/p')
DEFAULT_ROUTE_DEV=$(ip route | grep default | sed -n 's/default via .* dev \([^ ]*\) .*/\1/p')
echo "default route: $DEFAULT_ROUTE (over $DEFAULT_ROUTE_DEV)"
echo
echo
@guedressel
Copy link
Author

have a look at http://askubuntu.com/questions/265072/ubuntu-linux-12-10-message-of-the-day to see how to put it into the message-of-the-day in ubuntu systems

@guedressel
Copy link
Author

call the script in /etc/rc.local to adjust the /etc/issue file on system start:

/usr/local/bin/show_network_config.sh >> /etc/issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment