Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a VPS and an associated IP address for it. I'm doing a lot of work with it in my bash shell and I'm wondering if there's some way I can create either an alias or a environmental shortcut for the IP address to avoid having to type it every time. How would I do this?

share|improve this question
up vote 4 down vote accepted

Add to your ~/.bashrc:

export myip=""

Then you can use $myip on the command line after logging in or running source ~/.bashrc:

ping $myip

Aliases only work as commands, so you use it to replace commands which might include your IP:

alias myping='ping'
alias myssh='ssh user@'
share|improve this answer
Thanks! This is exactly what I was looking for – Casey Flynn Apr 27 '11 at 18:29

export somevarname="someIPaddress" should do what you want. after you do that, you should be able to use $somevarname instead. Note that the export should stay around for your current shell. If you log out, you'll have to set it again on login (or set it in your profile/bashrc)

share|improve this answer

Assuming you're connecting via ssh:

export foo=`echo $SSH_CONNECTION  | awk '{print $3}'`
echo $foo

This way you don't need to "preset" the IP for each machine. Put that in your .bashrc or .bash_profile or wherever you like.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.