Emulating multiple nics with one - Networking

This is a discussion on Emulating multiple nics with one - Networking ; This is my existing setup: One computer with 3 nics, each with a unique mac address. All the nics are connected to a hub, which in turn is connected to my ISP's local area network. My ISP has a dhcp ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Emulating multiple nics with one

  1. Emulating multiple nics with one

    This is my existing setup:
    One computer with 3 nics, each with a unique mac address. All the nics
    are connected to a hub, which in turn is connected to my ISP's local
    area network. My ISP has a dhcp server (at 192.168.11.1), which
    assigns an ip address to each of the 3 nics based on their mac
    addresses. They are given ip's 192.168.10.172,173,174, all with
    gateway 192.168.10.1 and netmask 255.255.255.0. I've set up a custom
    routing table that routes all my outgoing traffic (web, downloads,
    etc) across the 3 lines based on a few rules. The reason is that each
    line has a specific bandwidth limit (say for example 10KB/s), and by
    using 3 I can get a greater bandwidth (by splitting my downloads).

    NOW I want to have the functionally same setup as above, but using
    only one physical nic instead of 3. I'm assuming I'll be setting up
    virtual nics (each with their own mac's cloned from the former
    physical nics), and they will use dhcp to get an ip. Then I can refer
    to the virtual nics in my routing tables.

    Is this possible? And how? I researched into using the dummy interface
    and bridging it with my physical nic, but I just couldn't get it
    working.

    Cheers,
    Loban


  2. Re: Emulating multiple nics with one

    Does anybody have an idea how to do what I am attempting?

    All I basically want to do is emulate multiple nic's (each with it's
    own mac address) using one nic. Then I can create routing tables that
    use these multiple emulated nics, but all traffic is routed through
    one nic. I can do the latter half (routing), but cannot figure out how
    to do the first part (emulating multiple nics using one).

    Cheers,
    Loban


    On Oct 11, 3:24 pm, Mambazo wrote:
    > This is my existing setup:
    > One computer with 3 nics, each with a unique mac address. All the nics
    > are connected to a hub, which in turn is connected to my ISP's local
    > area network. My ISP has a dhcp server (at 192.168.11.1), which
    > assigns an ip address to each of the 3 nics based on their mac
    > addresses. They are given ip's 192.168.10.172,173,174, all with
    > gateway 192.168.10.1 and netmask 255.255.255.0. I've set up a custom
    > routing table that routes all my outgoing traffic (web, downloads,
    > etc) across the 3 lines based on a few rules. The reason is that each
    > line has a specific bandwidth limit (say for example 10KB/s), and by
    > using 3 I can get a greater bandwidth (by splitting my downloads).
    >
    > NOW I want to have the functionally same setup as above, but using
    > only one physical nic instead of 3. I'm assuming I'll be setting up
    > virtual nics (each with their own mac's cloned from the former
    > physical nics), and they will use dhcp to get an ip. Then I can refer
    > to the virtual nics in my routing tables.
    >
    > Is this possible? And how? I researched into using the dummy interface
    > and bridging it with my physical nic, but I just couldn't get it
    > working.
    >
    > Cheers,
    > Loban




  3. Re: Emulating multiple nics with one

    Hello,

    Mambazo a écrit :
    > Does anybody have an idea how to do what I am attempting?
    >
    > All I basically want to do is emulate multiple nic's (each with it's
    > own mac address) using one nic.


    I know no "clean" way to do this, but I believe it could be done by
    bridging the ethernet interface with TAP interfaces using the tun
    driver. TAP interfaces are virtual ethernet interfaces which communicate
    with a userland program through /dev/net/tun. Here's the twisted plan.

    1) Create a bridge with brctl, say br0.
    2) Add the unconfigured ethernet interface, say eth0 to the bridge. The
    bridge interface br0 takes the MAC address of eth0.
    3) Configure br0 as you used to configure eth0.
    4) Run a program which creates a pair of TAP interfaces, say tap0 and
    tap1, and forwards trafic from an interface to the other interface. This
    behaves as a virtual ethernet link between tap0 and tap1.
    5) Add one of the TAP interfaces, say tap0, to the bridge. Leave it
    unconfigured.
    6) Configure the other TAP interface, tap1, as you used to configure an
    ethernet interface.

    network -- eth0(no IP) -- br0(DHCP) -- tap0(no IP) -- tap1(DHCP)

    If you need more than one additionnal virtual interface, you can either
    - create more TAP pairs and add them to the bridge ; this will behave as
    a virtual switch ;
    - or extend the TAP program so it creates more interfaces and forwards
    traffic from any interface to all other interfaces ; this will behave as
    a hub.

  4. Re: Emulating multiple nics with one

    Pascal Hambourg a écrit :
    >
    > Mambazo a écrit :
    >>
    >> All I basically want to do is emulate multiple nic's (each with it's
    >> own mac address) using one nic.

    >
    > I believe it could be done by
    > bridging the ethernet interface with TAP interfaces using the tun
    > driver.


    I made a quick test for fun and it seems to work. At least a DHCP client
    running on the TAP interface successfully obtained an IP address from
    the DHCP server running on the physical ethernet network.

  5. Re: Emulating multiple nics with one

    > > bridging the ethernet interface with TAP interfaces using the tun
    > > driver.

    >
    > I made a quick test for fun and it seems to work. At least a DHCP client
    > running on the TAP interface successfully obtained an IP address from
    > the DHCP server running on the physical ethernet network.


    That's awesome! I only just noticed your 2 replies today. Your
    "twisted plan" makes sense. I'm getting straight to work this
    weekend. If you could please forward you test code to me,
    I'll have a nice jump start on this crazy endeavor.

    Thanks again!

    Cheers,
    Loban


  6. Re: Emulating multiple nics with one

    Another quick question. This is probably because I'm a little clueless
    as to what exactly the "bridge" does. Why do I need a pair of tap
    devices? Can't I just have the tap device that's in the bridge have
    it's own mac address and get an ip using dhcp. Or is this because any
    device that is part of a nic can no longer have it's own identity?


  7. Re: Emulating multiple nics with one

    Mambazo a écrit :
    >
    > If you could please forward you test code to me,


    See attached files.
    DISCLAIMER : I am not a software developper. I just made this up from
    some sample code found here and there.

    /* taplink.c : direct link between multiple TAP interfaces (~hub) */
    /* 20/10/2007 */

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    /* uncomment to print debug messages */
    //#define DEBUG

    #define max(a, b) ((a)>(b) ? (a)b))

    /* nomber of TAP interfaces to create (minimum 2) */
    #define NBIF 3

    int main()
    {
    struct ifreq ifr[NBIF];
    int fd[NBIF], fm, len, err, i, j;
    char buf[2048];
    char *dev="";
    fd_set fds;

    FD_ZERO(&fds);
    fm = 0;

    /* create the TAP interfaces */
    for (i=0; i {
    fd[i] = open("/dev/net/tun", O_RDWR);
    if (fd[i] < 0)
    {
    printf("cannot open /dev/net/tun for interface #%d\n", i);
    return -1;
    }
    fm = max(fm, fd[i]);
    FD_SET(fd[i], &fds);

    memset(&ifr[i], 0, sizeof(struct ifreq));
    /* Flags: IFF_TUN - TUN device (no Ethernet headers)
    * IFF_TAP - TAP device
    *
    * IFF_NO_PI - Do not provide packet information
    */
    ifr[i].ifr_flags = IFF_TAP;
    if (*dev)
    {
    strncpy(ifr[i].ifr_name, dev, IFNAMSIZ);
    }

    err = ioctl(fd[i], TUNSETIFF, (void *)&(ifr[i]));
    if (err < 0)
    {
    printf("ioctl SETIFF error on interface #%d\n", i);
    return -1;
    }
    #ifdef DEBUG
    printf("file descriptor : %d, ", fd[i]);
    #endif
    printf("interface #%d is : %s\n", i, ifr[i].ifr_name);

    err = ioctl(fd[i], TUNSETNOCSUM, 1);
    if (err < 0)
    {
    printf("ioctl SETNOCSUM error on interface #%d\n", i);
    return -1;
    }
    }
    fm++;
    #ifdef DEBUG
    printf("fm = %d\n",fm);
    #endif

    /* transmit frames from one interface to the others */
    while (1)
    {
    select(fm, &fds, NULL, NULL, NULL);
    #ifdef DEBUG
    printf("select :");
    #endif
    for (i=0 ; i {
    if (FD_ISSET(fd[i], &fds))
    {
    #ifdef DEBUG
    printf(" %s", ifr[i].ifr_name);
    #endif
    len = read(fd[i], buf, sizeof(buf));
    for (j=0; j {
    if (j != i)
    {
    write(fd[j], buf, len);
    }
    }
    }
    else
    {
    FD_SET(fd[i], &fds);
    }
    }
    #ifdef DEBUG
    printf("\n");
    #endif
    }
    }

    # Bridge a group of TAP interfaces with an ethernet interface

    # assumptions :
    # the ethernet interface is eth0
    # the TAP interfaces are tap0, tap1 & tap2
    # the bridge interface is br0

    # create a bridge
    brctl addbr br0

    # add the ethernet interface to the bridge
    # the ethernet interface must not have any IP address (nor aliases eth0:Y)
    # run "ifconfig eth0 0.0.0.0" to remove the primary IP address if necessary
    # it must not be bound to a DHCP client either
    # kill the DHCP client or disable the interface with the high level command
    # (e.g. ifdown eth0 on Debian-like systems) if necessary
    brctl addif br0 eth0

    # create the TAP interface group (virtual hub)
    /path/to/taplink &

    # add one TAP interface to the bridge
    brctl addif br0 tap0

    # enable all the interfaces
    # and if required, change the TAP interfaces MAC addresses
    ifconfig eth0 up
    ifconfig br0 up
    ifconfig tap0 up
    ifconfig tap1 up hw ether 00:11:11:11:11:11
    ifconfig tap2 up hw ether 00:22:22:22:22:22

    # wait a few seconds until the bridge enters forwarding state
    sleep 5

    # configure the bridge interface with DHCP
    dhclient br0

    # configure the TAP interface(s) not in the bridge with DHCP
    dhclient tap1
    dhclient tap2

  8. Re: Emulating multiple nics with one

    Mambazo a écrit :
    > Another quick question. This is probably because I'm a little clueless
    > as to what exactly the "bridge" does.


    The bridge can be seen as a virtual ethernet switch whose ports are the
    bridged interfaces and the bridge interface itself.

    For example, when bridging eth0, eth1 and eth2 into br0 you would
    functionnaly get this :

    network stack (TCP/IP...)
    |
    br0 (bridge virtual interface)
    |
    ethernet bridge
    | | |
    eth0 eth1 eth2

    br0 takes the MAC address of the first bridged interface.

    > Why do I need a pair of tap
    > devices? Can't I just have the tap device that's in the bridge have
    > it's own mac address and get an ip using dhcp.


    I haven't tried this, but I don't think it would work well.

    > Or is this because any
    > device that is part of a nic can no longer have it's own identity?


    I guess you mean "part of a bridge". Yes, it becomes a port of the bridge.

+ Reply to Thread