Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 
share|improve this question
1  
The 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 Nov 21 '12 at 11:43
    
Do you receive incoming connections from outside your networks on both interfaces? Otherwise, I just second Paul's observation. –  pino42 Nov 21 '12 at 11:45
    
@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 Nov 21 '12 at 11:49
    
@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 Nov 21 '12 at 11:54
    
@rahul: I've edited that update into your question where it is easier to read. –  RedGrittyBrick Nov 21 '12 at 11:58

2 Answers 2

up vote 0 down vote accepted

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
share|improve this answer
    
ya, I have a router at 3.1 so i need to do a route add default gw 192.168.3.1? –  rahul Nov 21 '12 at 12:04
    
thanks. It worked. Ur commands was perfect –  rahul Nov 21 '12 at 13:14
    
@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 Nov 21 '12 at 15:52
    
Ya. noted. I have already made the required changes :) –  rahul Nov 23 '12 at 9:56
    
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 Nov 27 '12 at 3:51

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
share|improve this answer
    
thats right paul. Thanks for the help i got it with the help from RedGrittyBrick. Thanks for your help paul –  rahul Nov 21 '12 at 13:13
    
How can i set the incoming connection to go through my 192.168.1.X interface? Any help paul ? –  rahul Nov 27 '12 at 5:29
    
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 Nov 27 '12 at 9:47
    
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 Nov 27 '12 at 11:41
    
@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 Nov 27 '12 at 12:38

Your Answer

 
discard

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.