We have multihomed servers. And to simplify things, I would like to know the dns of the interface trough which I'm logged in. (e.g. to set PS1 thus it can be used in scp commands)
My solution for that problems seems to be rather complicated. => is there a easier/simpler and more portable way?
ORIGIN_NAME=`who -m | cut -d\( -f2 | cut -d\) -f1`
ORIGIN_IP=`getent hosts $ORIGIN_NAME | awk '{ print $1; }'`
INTERFACE_NAME=`ip route get $ORIGIN_IP | grep dev | awk '{ print substr($0,index($0,"dev")+4,4); }'`
INTERFACE_IP=`ifconfig -a $INTERFACE_NAME | grep inet | awk ' { print $2; }' | cut -d: -f2`
getent hosts $INTERFACE_IP | awk '{ print $NF; }'