linux routing with 2 nics

Discussion in 'OT Technology' started by GOGZILLA, Apr 17, 2009.

  1. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    Hey dudes. On my new PC I have two ethernet ports. I don't want to use them both at the same time for anything but would like to have it working if I ever did want to and also understand wtf is going on right now. I have been doing a bit of reading and it appears that they have to be on different subnets. This is going to probably be really stupid and easy but im just starting out with networking stuff. My router is address 192.168.1.1. I am trying to have both eth interfaces come up with seperate IP addresses but have the option to plug either one of them into the router.:

    /etc/network/interfaces:
    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1

    auto eth1
    iface eth1 inet static
    address 192.168.2.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    *************************************

    With that interfaces file when i do "/etc/init.d/networking restart" eth1 fails to come up:

    [email protected]:~$ sudo /etc/init.d/networking restart
    * Reconfiguring network interfaces... RTNETLINK answers: No such process
    SIOCDELRT: No such process
    * if-up.d/mountnfs[eth0]: waiting for interface eth1 before doing NFS mounts
    SIOCADDRT: No such process
    Failed to bring up eth1.
    [ OK ]

    At this point internet works on eth0 which is great but I would like to be able to have the option of using either. If i change the gateway of eth1 to 192.168.2.1 both interfaces come up but internet does not work (not able to connect to router). Any ideas? This is my "route -n" for internet working configuration btw:

    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
    192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
    169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
    0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 eth0
    0.0.0.0 192.168.2.1 0.0.0.0 UG 100 0 0 eth1
     
  2. AbortionSurvivor

    AbortionSurvivor Active Member

    Joined:
    Jun 5, 2002
    Messages:
    3,016
    Likes Received:
    0
    Location:
    Nor. Cal
    For two subnets to work you need two gateways.
    Think of a gateway as a door to other rooms in your house.
    Gateway is the route taken when the destination host is not on your local subnet.

    You need a gateway address on 192.168.2.x to make this work.
     
  3. AbortionSurvivor

    AbortionSurvivor Active Member

    Joined:
    Jun 5, 2002
    Messages:
    3,016
    Likes Received:
    0
    Location:
    Nor. Cal
    btw...I don't think you need two subnets.

    Put eth1 on DHCP and it should work (assuming you have DHCP configured on your home router).
     
  4. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    alright cool dude I was thinking something like that. My router at home is static ip only. I just disabled eth1 for the time being since I've got no use for it and it was just causing problems. What you said makes sense though thanks alot.
     
  5. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,454
    Likes Received:
    12
    couple things, if you want to channel, trunk, netrain, bond, whatever the interfaces on the machine, the switch has to support it as well... you can look up bonding for linux to give it a shot. decent guide here: http://www.linuxfoundation.org/en/Net:Bonding

    you're eth1 will never work because it can't see past the 192.168.2 lan since your mask is 255.255.255.0

    if you want to multi-home, you need specific route entries for both.. a default router for one and a different one for the other.....
     
  6. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL

    I need a little more work on understanding subnetting and IP in general. I understand that I can't connect both to the same router. Bonding is really going to do anything for me but thanks for the link anyway. What subnet would I need to use to get 192.168.2 lan to work?
     

Share This Page