Say I have a device connected by IP over USB to my computer (running Ubuntu), that connects to I configured my Ubuntu's Wifi over USB so that my computer's IP on that connection is, but I would actually like to redirect all traffic (on all ports) to another server, and just use my computer as a proxy.

I played around with some solutions, but my lack of familiarity with network concepts is slowing me down (I spend too much time looking stuff up, and the documentation is often a bit lacking). I'm not even sure if I want to set up a proxy, a firewall (I don't think so), or use the routing tables. What I want to do sounds pretty simple ("redirect anything coming from IP over USB to that server over there"). So is there a standard way of doing that? iptables? squid? ufw?

migrated from serverfault.com Aug 12 '13 at 15:03

This question came from our site for system and network administrators.

  • 3
    For this use case, forget about USB. The network device driver presents the hardware in exactly the same way as any other network device. So if you find a generic solution, it will work for this, or any other Ethernet device. – EEAA Aug 12 '13 at 14:19

What you are asking for is known as a NAT, a Network Address Translation. There are a number of tools that can provide NAT functionality, but at the IP address level it is probably easiest with iptables:

 iptables -t nat -I PREROUTING -d --j DNAT --to 10.x.x.x

in the special nat table of iptables -t nat, insert at the first rule on the PREROUTING chain (-I PREROUTING), providing a destination nat -j DNAT where the incoming destination IP is to (-d over to the host 10.x.x.x (--to 10.x.x.x).

You may also need enable IP Fowarding, so your host acts as a network router with:

sysctl -w net.ipv4.ip_forward=1

And that should be it! (Just as simple as you thought it might be!)

Oh and both of these need to be ran as the root user, or via sudo (if you have access to run those commands via sudo!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.