Link to home
Start Free TrialLog in
Avatar of bachra04
bachra04Flag for Canada

asked on

route 2 traffic streams on single NIC

I had this question after viewing Linux as a middle box.

Now I have the following problem my linux box has two External Nic ( the wifi and the ethernet both with public IPs)
and one internal NIC card only

Internal IP : 192.168.2.1 (NIC CARD 0)

External
eth1 : public IP (NIC CARD 1)

wlan1: public IP (WIFI CARD 2)

since I have only one internal NIC card I need to add another virtual IP using the same NIC.

The reason I am doing that is because I have an internal box with two processes , the first process is sending data on one IP
and the second process is sending the data on the other IP.



Internal box ( No internet access and one ethernet address 192.168.2.2)  ---  sends first traffic to Linux box --> on IP 192.168.2.1
the linux box performs the NAT and send the traffic to the internet over NIC  CARD 1
similarly , internal box second process sends the traffic to the virtual IP that I have added ( let's say 192.168.2.2) to the linux box which does the same thing
I mean route the traffic over WLAN after NATTing it.

My question is the following , what are the linux commands that allows to achieve that ? i.e add second interface and IP address on the same internal NIC
and at the same time NAT the traffic based on the interface that received it. ?

I found the following two links on the internet:

https://www.ostechnix.com/how-to-assign-multiple-ip-addresses-to-single-network-card-in-linux/
https://www.youtube.com/watch?v=OyJQUZPhUpM


But someone told me that I can be using linux network bridging https://linux.die.net/man/8/brctl
Can someone elaborate more on this ? how to achieve the same result using linux network bridging ???
Is there a difference between the two approaches ?

Thanks
Avatar of noci
noci

if the source IP is the same you cannot differentiate on IP address. Possibly the portnumber can be used....
Ports are not considered during routing,  the destination address is used for that.

There is an option to route based on source address not a prefered way.

Anyway the processes on the originating box need to use different addresses and the interface needs an alias to support that.

The middle box can then route....
here is a description:
http://tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.rpdb.simple.html
if the private NIC is eth0 add an eth0.1 with the secondary IP
Avatar of bachra04

ASKER

So if I understand correctly I have first to create additional virtual interface then create two IP addresses.
The nest step will be to create two bridges for each incoming traffic ( on each IP) and map it to the external interface.
e.g. traffic coming on IP1 will be bridged to external interface 1
traffic coming on IP2 will be bridged to external interface 2.
Is it fair to say that ?
not bridge but NAT.

Bridging is something different :)

you will need to look at policy based routing as well

http://tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.rpdb.simple.html
http://blog.scottlowe.org/2013/05/29/a-quick-introduction-to-linux-policy-routing/

good luck
Thanks.
So if I correctly understood this time :)
- add virtual interfaces with new IP something like eth0:1
- use policy based routing to routes the different streams back and fourth.
- Will the NAT be done automatically as part of  policy based routing or I have to make it explicitly ?
ASKER CERTIFIED SOLUTION
Avatar of J Spoor
J Spoor
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial