If there are multiple IP addresses public, private, backup, etc are in use on linux server it takes a bit more of time to scroll down through the output of 'ifconfig' command and find the IP address assigned to it.
I have created a shell script nic.sh which list all the Ethernet interfaces and IP address assigned to them on Linux server.
#!/bin/bash
nic=$(ifconfig | cut -d" " -f1 | sed '/^$/d' | awk -vORS=',' '{ print $1}' | sed -e s/,$//g)
OFS=IFS
IFS=','
read -ra i <<< "$nic"
for i in "${i[@]}"; do
echo "$i ---> $(ifconfig | grep -A 1 -i $i | sed -n '2p' | awk -F" " '{ print $2 }' | cut -d":" -f2)"
done
root@localhost:/root>./nic.sh
eth0 ---> 192.168.1.19
lo ---> 127.0.0.1
No comments:
Post a Comment