need to route the traffic through a specific network card

1

0

I have two network cards and they both have a different network. I need the outgoing connections to go only through a specific network card. Any help ?

Update:

I ran a route -n command and got this OP

  Kernel IP routing table 
  Destination  Gateway        Genmask        Flags Metric Ref Use Iface
  0.0.0.0      192.168.1.100  0.0.0.0        UG    0      0   0   eth1 
  169.254.0.0  0.0.0.0        255.255.0.0    U     1000   0   0   eth0 
  192.168.1.0  0.0.0.0        255.255.255.0  U     1      0   0   eth1 
  192.168.3.0  0.0.0.0        255.255.255.0  U     1      0   0   eth0 

rahul

Posted 2012-11-21T11:29:40.027

Reputation: 116

1The default gateway defines which next hop will be used for outgoing connections that are not otherwise routed, so this dictates which network interface they will exit given your two nics are on different networks. Is there more to this question? – Paul – 2012-11-21T11:43:22.213

Do you receive incoming connections from outside your networks on both interfaces? Otherwise, I just second Paul's observation. – pino42 – 2012-11-21T11:45:44.423

@paul thanks for the quick reply paul. I dont have not much knowledge on this stuff. i ran a route -n command and got this OP Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.100 0.0.0.0 UG 0 0 0 eth1 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1 192.168.3.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0 – rahul – 2012-11-21T11:49:27.567

@Paul any help this time ? i want all the traffic to go via the card that has the 3.0/24 address --thanks in advance – rahul – 2012-11-21T11:54:39.477

@rahul: I've edited that update into your question where it is easier to read. – RedGrittyBrick – 2012-11-21T11:58:01.240

Rahul, are your network cards statically addressed or are they getting addresses via dhcp? Which network do you want the connections to go out of? What is IP of the router you want the connections to go out of? – Paul – 2012-11-21T12:05:54.947

@Paul the nics are static. I want the connections goin out to go through 3.0 network. (now it is goin through 1.0 network) – rahul – 2012-11-21T12:43:25.947

@Paul im stuck up at another issue now. The incoming connections need to go through the 192.168.1.X connection. Any help on this ? – rahul – 2012-11-27T06:10:22.083

Answers

1

All your Internet traffic will go out through eth1 as that is connected to your router.

If you want to route traffic via eth0 and have a router on that subnet (192.168.3.nnn), you can change the default route accordingly. See man route

 route del default 
 route add default gw 192.168.3.254

RedGrittyBrick

Posted 2012-11-21T11:29:40.027

Reputation: 70 632

ya, I have a router at 3.1 so i need to do a route add default gw 192.168.3.1? – rahul – 2012-11-21T12:04:55.837

@rahul: Note: the route comands change things temporarily, at reboot it will revert to the settings in /etc/network/interfaces/ so to make the changes permanent, edit that file. – RedGrittyBrick – 2012-11-21T15:52:19.330

Ya. noted. I have already made the required changes :) – rahul – 2012-11-23T09:56:38.320

Now a new issue comes, I was planning to give out side access to the same machine, using port forwarding on my router. The forwarding process is fine, but im not able to access it from outside. The forwarding is done to the 1.x IP , I doubt whether 3.X being my default gateway is the problem. – rahul – 2012-11-27T03:51:37.073

If the routers use NAT (as they probably do) you can't have the return traffic via a differrent router than the inbound traffic because the return traffic gets it's from-address rewritten and no longer matches the connection quadruplet (client-IP + client-port + server-IP + server-port). – RedGrittyBrick – 2012-11-27T09:25:40.367

Can i have a setup like this, all answers to traffic coming in on a particular interface get answered from that interface – rahul – 2012-11-27T11:50:54.147

0

Your /etc/network/interfaces file looks something like this:

auto eth0 eth1
iface eth0 inet static
        address 192.168.1.x
        netmask 255.255.255.0
        gateway 192.168.1.100

iface eth1 inet static
        address 192.168.3.x
        netmask 255.255.255.0

The gateway directive lets the system know where connections should go out. You want to change it to the other interface, with the router IP that is there:

auto eth0 eth1
iface eth0 inet static
        address 192.168.1.x
        netmask 255.255.255.0

iface eth1 inet static
        address 192.168.3.x
        netmask 255.255.255.0
        gateway 192.168.3.1

Paul

Posted 2012-11-21T11:29:40.027

Reputation: 52 173

thats right paul. Thanks for the help i got it with the help from RedGrittyBrick. Thanks for your help paul – rahul – 2012-11-21T13:13:39.397

How can i set the incoming connection to go through my 192.168.1.X interface? Any help paul ? – rahul – 2012-11-27T05:29:21.203

What do you mean? Incoming connections arrive at a public IP address, and will be NATted to a private address, so you just need to publish the right public IP for whatever services you allow incoming. – Paul – 2012-11-27T09:47:29.000

everything seems to be fine paul. But its not possible to access. when i run a wireshark , i can see the incoming requests. But the remote person is not able to access.
One thing i would like to add is , forwarding can only be done to a 192.168.1.X network at my side. So i forward to the 1.X card of the machine, But the default route through which the packets or the response go back is 3.X. I don't know if that's the problem, Any help is appreciated.
– rahul – 2012-11-27T11:41:20.383

@rahul that is exactly right, your routing is asymmetric and so response packets are seen coming from a different address that they were sent to and discarded by the remote client. Please can you edit your question and add more details about what you are doing. – Paul – 2012-11-27T12:38:49.300

hey i got that done. Followed the procedures here

http://lartc.org/howto/lartc.rpdb.multiple-links.html

– rahul – 2012-11-29T04:48:19.527