need to route the traffic through a specific network card
13,657
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
Related videos on Youtube
Author by
rahul
Updated on September 18, 2022Comments
-
rahul over 1 year
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 OPKernel 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
-
Paul over 11 yearsThe 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?
-
pino42 over 11 yearsDo you receive incoming connections from outside your networks on both interfaces? Otherwise, I just second Paul's observation.
-
rahul over 11 years@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 over 11 years@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
-
user5249203 over 11 years@rahul: I've edited that update into your question where it is easier to read.
-
Paul over 11 yearsRahul, 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?
-
rahul over 11 years@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 over 11 years@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 over 11 yearsya, I have a router at 3.1 so i need to do a route add default gw 192.168.3.1?
-
rahul over 11 yearsthats right paul. Thanks for the help i got it with the help from RedGrittyBrick. Thanks for your help paul
-
user5249203 over 11 years@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. -
rahul over 11 yearsYa. noted. I have already made the required changes :)
-
rahul over 11 yearsNow 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 over 11 yearsHow can i set the incoming connection to go through my 192.168.1.X interface? Any help paul ?
-
user5249203 over 11 yearsIf 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).
-
Paul over 11 yearsWhat 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.
-
rahul over 11 yearseverything 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 over 11 yearsCan i have a setup like this, all answers to traffic coming in on a particular interface get answered from that interface
-
Paul over 11 years@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.
-
rahul over 11 yearshey i got that done. Followed the procedures here lartc.org/howto/lartc.rpdb.multiple-links.html