Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

up vote 4 down vote accepted

Add to your ~/.bashrc:

export myip="1.2.3.4"

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 1.2.3.4'
alias myssh='ssh user@1.2.3.4'
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

 
discard

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.