Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 03-18-2011, 03:06 PM   #1
Registered: Mar 2009
Posts: 41

Rep: Reputation: 15
route all system traffic to localhost

I just installed a fresh copy of debian (no GUI). I want all my traffic on bash (such as when I do ping or dig or wget, basically whatever) to be sent to localhost:8080. How can I do that? I've a ssh port forward setup that will forward all traffic arriving at my localhost:8080 to another server. Thanks guys
Old 03-18-2011, 06:08 PM   #2
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Have you thought of using iptables? The following, I believe, should redirect all TCP traffic to localhost:8080, by adding a rule to the OUTPUT chain of the network address translation table:

iptables -t nat -A OUTPUT -p tcp -j DNAT --to-destination

However, I'm trying to get my head round the concept of redirecting pings to a port... not sure that this is a meaningful thing to do, as ports are part of TCP/UDP, not ICMP as used by ping echo request/reply packets. On the other hand, iptables does accept the rule:

iptables -t nat -A OUTPUT -p icmp -j DNAT --to-destination

Another thing to think about is that ports are used to distinguish different connections. If all traffic is going to be sent over a single tunnel, how is it going to be re-constituted at the other end? It might be necessary to think about which types of traffic you are going to need to forward, and establish a separate tunnel for each one.

Last edited by Robhogg; 03-18-2011 at 06:17 PM.
Old 03-21-2011, 10:34 AM   #3
Registered: Mar 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Hi Robhogg
Thank you for getting back to me. Sorry I wasn't available over the weekend to try and reply to your proposed answer. So I tried what you said. I checked with
iptables -t nat -L
and saw the entry there. I also did a
ssh -D 8080 user@otherserver
to do a dynamic port forward
And then i did a test by running
wget http://someexternalsite/logo.png
Apparently, it was still trying to connect to a proxy that the system is set to use. What I had hoped is that it would send my wget request over to localhost:8080 and through the tunnel to the otherserver. The otherserver (it's another server on the local lan) would serve my request and give me back the results.
The reason I'm trying to do this is to avoid the proxy server that the system is set to use. I hope I'm making sense. Thanks again.
Old 03-23-2011, 07:40 AM   #4
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
By "to a proxy that the system is set to use" do you mean some device between your computer and the Internet? A fresh install of Debian is not set up to use a proxy.

iptables does not affect IPv6 traffic (ip6tables doe that), either your connections are over IPv6 or the iptables rules are set-up wrongly; however that approach is completely wrong. When used with the -D option is a SOCKS server and needs to be used with a SOCKS client, for example socksify, however that will only support TCP connections.

To do what you want you need a VPN, OpenSSH provide basic support with the -w option, but is likely to be slow due to the poor performance of TCP over TCP.
Old 03-24-2011, 03:39 PM   #5
Registered: Mar 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks for your input TimothyEBaldwin. Appreciate your help



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
route locally generated traffic to ip:port to localhost:port maenho Linux - Software 2 03-11-2005 05:08 AM
Can traffic be forwarded to localhost? silence Linux - Networking 3 08-10-2004 03:42 PM
route any traffic between two NICs thirumala Linux - Networking 0 03-24-2004 06:54 PM
Route traffic like a hub atlesn Linux - Networking 2 03-21-2004 05:51 PM
no localhost route when eth0 is not used jmlleung Linux - Networking 1 03-04-2004 03:56 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:47 PM.

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