Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to use tsocks (to tunnel an ssh connection through an ssh tunnel to reach given machines), but there is a problem. There are two servers that has the same IP address (that I need to reach through ssh tunnels). So the config for this situation would look like this:

cat /etc/tsocks.conf
path {
    reaches = 10.1.1.2/255.255.255.255
    server = 127.0.0.1
    server_port = 3000
}

path {
    reaches = 10.1.1.2/255.255.255.255
    server = 127.0.0.1
    server_port = 2000
}

How can I resolve this problem?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You'll need two tsocks.conf, one for each SOCKS server and then use them as:

TSOCKS_CONF_FILE=~/.tsocks-A.conf tsocks some-cmd 10.1.1.2

and

TSOCKS_CONF_FILE=~/.tsocks-B.conf tsocks some-cmd 10.1.1.2

Alternatively, if the SOCKS servers support SOCKS4A or SOCKS5, you could use dante's socksify instead of tsocks and use host names if they have different host name on the remote ends (and specify which SOCKS server to use based on host names or domain names in dante.conf).

share|improve this answer
    
I can't use hostnames in tsocks? –  gasko peter Nov 5 '12 at 11:28
    
@gaskopeter. You can use hostnames, but they will be resolved locally, not on the remote end, and all tsocks will ever see is the IP address that those hostnames resolve to (contrary to dante, tsocks doesn't hijack the hostname resolving functions) –  Stéphane Chazelas Nov 5 '12 at 11:37
    
thanks for the info –  gasko peter Nov 5 '12 at 11:54

Firstly, you may be able to do everything, all of it through SSH config files. This is especially true if you're just SSHing to the end machines. See the SSH multihop config. With appropriately established SSH configs you could just assign destination names and type ssh servera or ssh serverb, instead of having to set up an SSH tunnel and then type tsocks ssh servera.

Tsocks really can't differentiate what you want. One approach would be to set up two config files and issue commands to swap configs for each network

eg:

$ chmod +x /usr/local/bin/tsocksa.sh

$ cat /usr/local/bin/tsocksa.sh
#!/bin/bash  
#
#Swaps for Network A
#See /etc/tsocs.conf.main and /etc/tsocks.conf.dest_a
#
sudo cat /etc/tsocks.conf{.main,.dest_a} > /etc/tsocks.conf

and

$ chmod +x /usr/local/bin/tsockss.sh

$ cat /usr/local/bin/tsockss.sh  
#!/bin/bash  
#
#Swaps for Network S
#See /etc/tsocks.conf.main and /etc/tsocks.conf.dest_s
#
sudo cat /etc/tsocks.conf{.main,.dest_s} > /etc/tsocks.conf

Now you would put your network-swap specific commands into /etc/tsocks.conf.dest_n and put your generic networks into /etc/tsocks.conf.master

You could also use Bash aliases for the same commands, or further simplify the Bash script into a function you can source in your bashrc.

share|improve this answer
    
Thank you thanks :) –  gasko peter Nov 5 '12 at 11:55

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.