I have 3 interfaces: eth0
eth1
eth2
:
eth0
is directly connected to the Internet.eth1
andeth2
are connected to an external switch with no Internet connectivity.
My goal was to connect eth1
and eth2
through the external switch and forward traffic between the two interface through the swith. So I created two namespaces ns1
and ns2
and assigned eth1
and eth2
to each respectively.
Each interface has its own IPv4 network assigned to it.eth1
has 10.1.0.10/24
and eth2
has 10.2.0.10/24
and I can forward traffic between these two interfaces through the switch with no problem.
Now I want to forward traffic received on eth2
to the Internet, such that applications in ns1
can reach the Internet through the switch (note that only eth1
and eth2
are connected to the switch and the switch has no Internet connectivity and the only Internet connectivity is through eth0
(which is currently not part of any namespace).
There is probably a way to use veth
or TUN
interface pairs to forward traffic from ns2
to eth0
, but I'm wondering if there is an easier way to achieve this.
Here's how my setup looks like:
.--------.eth1 .--------. eth2.--------.
| ns1 |------------| switch |------------| ns2 |
'--------' '--------' '--------'
.--------.eth0 .--------.
| default|------------|Internet|
'--------' '--------'