Bash: Always knowing tun0 address

When studying for OSCP I found that I was always forgetting what my tun0 IP was.
Can’t send them shells back to yourself, if you don’t know your IP, right?

I put a lil’ tweak into my ~/.bash_aliases
When you open a new tab/window/shell, it looks like this:

In this example, I’m not on a VPN, therefore there’s no tun0.

And if I connect using my VPN (to HTB/THM/etc):

And it will do that every time you open a shell in your Kali.

To add this to your Kali.
open up ~/.bash_aliases (create, if it doesn’t exist) in the editor of your choice. And enter:

# Display IP of eth0
ifconfig eth0 | grep 'inet ' | awk '{print "eth0: "$2}'
# Display IP of tun0 (if present)
if [[ ! -d /sys/class/net/tun0 ]]
then
    echo 'No tun0'
else
    ifconfig tun0 | grep 'inet ' | awk '{print "tun0: "$2;}'
fi

Disclaimer: No warranty given, or implied. It worked for me. If it doesn’t work for you, well, it’s pretty simple. Maybe you can fix it yourself?

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *