I want to connect to two networks simultaneously using the Ethernet and in-built WiFi or to two WiFi networks by installing an additional WiFi adapter.

My requirement: I have two sets of devices (Group A and group B) that need to communicate with each other but not directly. There is no internet at the location. Group A devices are connected to WiFi router A and group B devices to WiFi router B (It is necessary that they should not be connected to the same router). I want the Linux device to connect to both router A and router B and act as an intermediary between the two groups. The Linux device should receive messages from Group A (through router A), process the information and send notification of the result to Group B (through router B) and vice versa.


  1. How do I setup Linux to connect to two networks simultaneously?
  2. How do I identify which network a message is from and handle that message accordingly?
  3. How do I specify the target network for my notification and send it to that network?

1 Answer 1


Ensure that each network has its own network range, e.g. wlan0 is and wlan1 is That answers your questions (2) and (3): check the source address of the "message" (what format is the message? UDP packet? How are you reading the message?) to identify what network the message came from, and you target a network by way of the IP address you're sending to. This is basic network routing...

Enable IP forwarding (echo 1 > /proc/sys/net/ipv4/ip_forward) to let devices on one network connect directly to devices on the other network; set the Linux system as the (default) gateway on those devices.

As to how to configure Linux to connect to two networks simultaneously: that depends on your distribution and what tools you're using. With Debian without networkmanager running you need to configure /etc/network/interfaces appropriately; with Red Hat you need to configure the files under /etc/sysconfig/networking/.

EDIT: Disable the DHCP server on the WiFi routers, assign the LAN interface a fixed IP in the correct network as I described above (one in, e.g. and on in, e.g. Give each router its own wireless ID (and of course each its own passwod).

Give the interfaces in Linux corresponding address but then ending in .1. (As you've ordered a new system for Linux, ensure it has two interfaces, you may need to order an extra network interface card (NIC) to accomplish this.) Connect the Linux system to the WiFi routers via a LAN port; don't use the WAN port, i.e. the WiFi router is only used as an access point, it doesn't route anything. We leave the routing to Linux. (It should not be necessary to use iptables as by default everything is permitted, and there's no need for NAT here. It may however be useful to use iptables at a later stage to limit what traffic is permitted.)

Install a DHCP server in Linux, and configure it to hand out addresses on both interfaces (there's plenty of documentation to be found on how to do that). Configure the DHCP server to give the Linux system IP as the default gateway.

  • Thanks @wurtel. I am new to networking and have a working knowledge of Linux. But I am willing to try whatever is necessary to make this work. I have been on this project for 6 months and networking the devices as described in my original post is my next (required) step. If you could give me pointers, I will work with them. I have ordered a Linux PC to work with and it will be delivered by the end of the month. I can try your suggestions to step 1 after that. Regarding 2 and 3, would I have to setup a server? I code in Python & Java, but can learn anything else, if it will get the job done. Jan 15, 2015 at 18:02
  • I still have to figure out how devices in group A & B will communicate with the Linux device. The devices in group A & B are tablets (iOS and Android). Group A are students and group B are staff. The devices communicate with each other within the group but interface through the Linux device to interact with the other group. Jan 15, 2015 at 18:03
  • If the comment avove is the behavior you want, your best bet would be to make the linux device act as a bridge.
    – eyoung100
    Jan 15, 2015 at 18:29
  • Requires iptables configuration as well
    – sandyp
    Jan 15, 2015 at 19:05
  • Edited my answer. Configuring network interfaces goes beyond the scope of this question I think (plenty of info to be found on the subject), also you still haven't said what Linux you're using. If you haven't decided yet, I recommend Debian :-)
    – wurtel
    Jan 16, 2015 at 7:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .