Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to Share a connection on Ubuntu Server without NAT

eth0: eth1:

I am creating a Cache Server with TPROXY (squid 3.1), but in my network will not use nat as to deliver IP publicos all machines. In all the tutorials that were always observe the configuration of Ubuntu Server always used nat. But need this model:

eth1 (> It receives the data and passes it to eth0 ( Internet)

Squid does its processing and returns the data to the network!

This works with Nat, but do not want to use NAT because the Squid configuration is with TPROXY (Transparent> Ip Client that should appear on the Internet and not Squid "would NAT")

share|improve this question
@AbrahamVanHelpsing This is possible with the right routing tables and forwarding rules. Without NAT, as these are already private RFC1918 addresses. If you make sure both the current NAT device and the PC sharing know about the network, then it's just a IPv4 routing question/answer. – gertvdijk Jan 24 '13 at 11:49
@gertvdijk, Thanks for noticing that. I'll remove it. – saji89 Jan 24 '13 at 12:00
Your question changed from a routing/networking question to a Squid HTTP proxy question. This is totally different. I think you'll need a bit more basic IPv4 knowledge here. :) – gertvdijk Jan 24 '13 at 12:48

Very general answer

There's very little information given in the question, so I'm assuming the following:

  • Your network is already NATed.
  • You have access on this NAT (router) device.
  • It is capable of adding manual static routes.
  • No firewalls running.
  • Your networks are of size /24 (= subnet mask


In the steps below it makes all devices aware of the different networks and the routes, all done by regular IPv4 networking and using the Linux routing table. It's needed to enable forwarding on the PC sharing, as it will prevent you from doing this by default (security reasons).

Detailed steps

Then follow these (general) steps:

  1. On the current NAT (router), add a static route: via I don't know what device you have, so I can't provide instructions for doing this. Read the manual of it.

    In case this router is running Ubuntu already, just add the route like this:

    route add -net gw
  2. On the PC you want to share the network, make sure it will forward the traffic:

    sysctl -w net.ipv4.ip_forward=1

    More info in this answer.

  3. On the client PC make the route to the network known by adding it to the route table:

    route add -net gw
share|improve this answer
Ok, In this Case: Computer (Connected on Eth1 of ubuntu) don't ping on, and ( is a gateway on may MK whith internet connection. What Client don't ping on ? – Tom Junqueira Jan 24 '13 at 12:21
@TomJunqueira I've tried re-reading your comment several times, and I am confused as to what you're trying to tell/ask in it. Update your question with your attempts and results instead. This site is not a discussion forum, but a Q&A site. – gertvdijk Jan 24 '13 at 12:28
Post Edited for more details – Tom Junqueira Jan 24 '13 at 12:40

By principle, what you want to do is a NAT. The action of taking inside network requests to the internet and convert it to a single external IP, for requesting to you internet provider, is a NAT function.

I think what you want is not have to use iptables, and its not nice, due to security reasions. At least a masquerade you need to use.

on /etc/init.d/rc.local add the code:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE

this may help you without too much codes.

share|improve this answer
OP doesn't want NAT. – Louis Matthijssen Apr 26 '14 at 12:49
Louis Matthijssen, take a better look on the answer. What he wants is NAT. He just don't know what is a NAT. – novaisjp Apr 26 '14 at 12:53

Your Answer


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.