My question is similar to this one, but I'm looking for something slightly different. I have a notebook PC that I use to access Linux machines on a network in two different scenarios:
I have a direct, wired connection to the network.
I have an indirect connection to the network. There is a gateway machine on the network exposed to the Internet, which I can use to establish SSH tunnels to hosts on the network. This is obviously a much slower, higher-latency connection.
My home directory is network-accessible from all machines, so they share a copy of my .bashrc
. I would like to add functionality to .bashrc
to detect which of the two scenarios I'm in and act accordingly (technically, there would be three scenarios, where the third is that I'm logging into my local machine, but that should be easily handled). I would like to do things like:
alias ssh ssh -X
when I'm on the local network, but I don't want to use X forwarding over the Internet.export EDITOR=gvim
when I'm on the local network, butexport EDITOR=vim
when I'm remote.
And so on. Based on the previous answer, it looks like I should be able to accomplish something like this by checking the contents of SSH_CLIENT
(if it exists) and seeing if the client IP address matches one of the network adapters on my local machine. I thought I would see if there is a slicker or more robust way to accomplish this.