LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-16-2010, 03:32 PM   #1
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Rep: Reputation: 36
tunneling HTTP with SSH


Hi,

I am pretty new to the ssh tunneling concept,and i wanted to know if i was doing anything wrong as i am getting the following error message:

Code:
channel 2: open failed: connect failed: Connection refused
channel 2: open failed: connect failed: Connection refused
I am on hostA trying to forward my http traffic out via SSH through hostB. hostA and hostB are in the same network.

hostA====(ssh)====HostB------->Internet

Code:
hostA> ssh -L 80:127.0.0.1:9999 user@hostB -N
In firefox i selected SOCKS V5,with SOCKS host as 127.0.0.1 and port as 9999.


Thanks !
 
Old 12-16-2010, 03:38 PM   #2
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Code:
ssh -D9999 user@hostB -N
That should do it. Then set SOCKS host (V5) proxy in Firefox to localhost port 9999.
 
Old 12-16-2010, 03:50 PM   #3
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
Still i get the same error. Do i need to check for anything in sshd config file on hostB?
 
Old 12-16-2010, 04:04 PM   #4
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by kdelover View Post
Still i get the same error. Do i need to check for anything in sshd config file on hostB?
If you get connected to hostB, it's mostly OK. But you could check for any options that would disable forwarding.

But sure the previous ssh command using -L has been killed before trying to use pwc101's ssh command using -D. Otherwise the new command cannot bind to port 9999. Or use a different port number.

Can you run tcpdump (need root access) on hostB to see what actual network traffic is being attempted?

Just to be sure, this is all about using Firefox on hostA, with all the traffic going out of hostA being through the SSH connection from hostA to hostB, and the traffic going to various internet sites going out of hostB. So if these hosts have static IP addresses without translation to the internet, web sites will see the HTTP(S) requests coming from hostB.
 
Old 12-16-2010, 04:28 PM   #5
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
@Skaperen

I am exactly trying to do what you just said.

netstat from hostA

Code:
hostA>tcp        0      0 127.0.0.1:9999          0.0.0.0:*               LISTEN      29761/ssh
Code:
hostB>tcpdump -i eth0 dst port 22

03:50:19.401146 IP hostA.51842 > hostB.ssh: S 1320164285:1320164285(0) win 5840 <mss 1460,sackOK,timestamp 160938463 0,nop,wscale 7>
03:50:19.401402 IP hostA.51842 > hostB.ssh: . ack 380061965 win 46 <nop,nop,timestamp 160938463 156729199>
03:50:19.407065 IP hostA.51842 > hostB.ssh: . ack 22 win 46 <nop,nop,timestamp 160938464 156729200>

shouldn't hostAs source port be 9999 instead of 51842? Also,in the sshd.conf file i see that allowTCPforwarding is commented out on hostA and B. When i did a wireshark on hostA,and captured few packets,i could see the ssh encrypted packets.

Last edited by kdelover; 12-16-2010 at 04:31 PM.
 
Old 12-16-2010, 05:01 PM   #6
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by kdelover View Post
Also,in the sshd.conf file i see that allowTCPforwarding is commented out on hostA and B.
No, that's fine as is: I have the same line commented out and am perfectly able to forward the relevant ports from home.

Try a killall ssh as a normal user on the remote SSH server (host B in your example) to kill all existing ssh connections from host A. Then, try sshing in again from host A.

If you still get nowhere, turn up the verbosity on the ssh commands with -vvv to see what's happening as it connects, and look out for any error messages or warnings.
 
Old 12-16-2010, 05:19 PM   #7
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
Thanks for the help,may be i'll try it at home today.

Well i just tried my luck with mysql tunneling ,where mysql is running on hostC

Code:
hostA> ssh -L 3306:localhost:3306 user@hostB
Code:
hostA> mysql -h 127.0.0.1 -D mybackup
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0


hostBs /var/log/messages has

Code:
sshd[3960]: error: connect_to localhost port 3306: failed.
sshd[3960]: error: connect_to localhost port 3306: failed.
sshd[3960]: error: connect_to localhost port 3306: failed.
sshd[3960]: error: connect_to localhost port 3306: failed.
also i still get the connection refused error,same as the http one.More over my /etc/hosts.allow looks fine as well,every line in there is commented.

Last edited by kdelover; 12-16-2010 at 05:22 PM.
 
Old 12-17-2010, 10:38 AM   #8
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by kdelover View Post
@Skaperen

I am exactly trying to do what you just said.

netstat from hostA

Code:
hostA>tcp        0      0 127.0.0.1:9999          0.0.0.0:*               LISTEN      29761/ssh
Code:
hostB>tcpdump -i eth0 dst port 22

03:50:19.401146 IP hostA.51842 > hostB.ssh: S 1320164285:1320164285(0) win 5840 <mss 1460,sackOK,timestamp 160938463 0,nop,wscale 7>
03:50:19.401402 IP hostA.51842 > hostB.ssh: . ack 380061965 win 46 <nop,nop,timestamp 160938463 156729199>
03:50:19.407065 IP hostA.51842 > hostB.ssh: . ack 22 win 46 <nop,nop,timestamp 160938464 156729200>

shouldn't hostAs source port be 9999 instead of 51842? Also,in the sshd.conf file i see that allowTCPforwarding is commented out on hostA and B. When i did a wireshark on hostA,and captured few packets,i could see the ssh encrypted packets.
For hostB the file /etc/ssh/sshd_config is what matters, since it is the server end.

It looks like you have ssh listening to port 9999 as it should. All connections from the browser in SOCKS5 mode should go to port 9999 on hostA, both ends being with address 127.0.0.1. But, in hostB, you should see connections originating from an sshd process, with arbitrary source ports, and appropriate source addresses depending on the destination, going to the designated destination address and port. Doing tcpdump on hostB is what is telling. The traffic between hostA and hostB over ssh does not matter beyond making sure there is an appropriate volume of traffic. So on hostB do this:
Code:
tcpdump -i any not port 22
Or better yet:
Code:
tcpdump -i any dst port 80
and visit a web server at the standard port 80. If you don't see any traffic in hostB going to the visited destination, then check the /etc/sshd/sshd_config file to see if it is set to disable any forwarding. If it is OK, the next thing to check is iptables.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP Tunneling or VPN Tunneling Teomari Linux - Networking 3 04-09-2007 07:52 PM
Proxy tunneling SSH over HTTP Gibsonist Linux - Networking 0 12-05-2005 03:43 AM
SSH Tunneling IRC Bouncer/HTTP nistelrooy Linux - Software 1 10-30-2005 01:58 PM
Information on Tunneling through HTTP for SSH jrbush82 Linux - Networking 1 05-03-2005 10:56 AM
HTTP tunneling NNP Linux - Networking 2 11-18-2004 07:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration