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'ma bit of a network newbie, so apologies for the inaccurate vocabulary.

Say I have a device connected by IP over USB to my computer (running Ubuntu), that connects to 10.0.0.1. I configured my Ubuntu's Wifi over USB so that my computer's IP on that connection is 10.0.0.1, 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?

share|improve this question

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

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

2  
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

1 Answer 1

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 10.0.0.1 --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 10.0.0.1 (-d 10.0.0.1) 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!)

share|improve this answer

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.