LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-18-2014, 12:30 PM   #1
twoprop
LQ Newbie
 
Registered: Jan 2011
Posts: 14

Rep: Reputation: 0
configuring a router where ethernet and wifi share a subnet


I have configured a router using Ubuntu 12.04 server. One ethernet port (eth0) connects to the WAN. There is a second port (eth1) with its own local subnet (192.168.137.1/24). There is a WiFi card (wlan0) on 192.168.138.1/24. I use isc-dhcp-server for DHCP and iptables to provide NAT on eth0. Everything works flawlessly, so there don't appear to be any problems with the WiFi or NIC drivers nor configuration of the drivers, DHCP, or iptables.

The problem is that I would like wlan0 and eth1 to be on the same subnet, as I have a number of devices (wired and wifi) that want to be on the same LAN.

My current /etc/network/interfaces:
Code:
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp
        post-up iptables-restore < /etc/iptables.up.rules

# The local subnet
auto eth1
iface eth1 inet static
        address 192.168.137.1
        netmask 255.255.255.0
        broadcast 192.168.137.255
        network 192.168.137.0

auto wlan0
iface wlan0 inet static
        address 192.168.138.1
        netmask 255.255.255.0
        broadcast 192.168.138.255
        network 192.168.138.0
What I tried (/etc/network/interfaces):
Code:
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp
	post-up iptables-restore < /etc/iptables.up.rules

# Bridge between eth1 and wlan0
auto br0
iface br0 inet static
  address 192.168.137.1
  netmask 255.255.255.0
  broadcast 192.168.137.255
  network 192.168.137.0
  pre-up ip link set eth1 down
  pre-up ip link set wlan0 down
  pre-up brctl addbr br0
  pre-up brctl addif br0 eth1 wlan0
  pre-up ip addr flush dev eth1
  pre-up ip addr flush dev wlan0
  post-down ip link set eth1 down
  post-down ip link set wlan0 down
  post-down ip link set br0 down
  post-down brctl delif br0 eth1 wlan0
  post-down brctl delbr br0
On reboot, wlan0 doesn't activate nor show up with brctl show. I can manually add wlan0 to br0 and bring up wlan0, but nothing routes to or from wlan0.

Anyone know of a good tutorial on this kind of bridging? When I've searched, I've found a lot of "kids! here's how you can share your internet connection" or descriptions of how to bridge two ethernet NICs, but nothing about bridging an ethernet and wifi interface.

Any clues would be welcome.

--twoprops
 
Old 05-18-2014, 04:12 PM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Did you read the Ubuntu wireless router manual?
 
Old 05-18-2014, 05:59 PM   #3
twoprop
LQ Newbie
 
Registered: Jan 2011
Posts: 14

Original Poster
Rep: Reputation: 0
I took a nap and woke up with the solution staring me in the face.

First, hostapd.conf needs this line:
Code:
bridge=br0
Second, I'd tried that before but I had cleverly forgotten to tell the dhcp server to listen on br0.

Hope this helps the next guy.

--twoprops
 
Old 05-18-2014, 07:34 PM   #4
twoprop
LQ Newbie
 
Registered: Jan 2011
Posts: 14

Original Poster
Rep: Reputation: 0
In the end, I couldn't get it to start with just the /etc/network/interfaces script. There's some sensitive timing that I'm too impaired to track down right now. In the mean time, if you take the eth1 and wlan0 configuration out of interfaces, you can run this script as root:
Code:
#!/bin/bash
# start the router

# Assumes that hostapd has been started as a service; I couldn't get it
# to work starting hostapd at the end of the script. It has to be running
# when you start the script, then re-started at the end. It seems to have
# to do with hostapd wanting to create the bridge.

# clear any addresses if /etc/network/interfaces isn't clean
ifconfig eth1 down
ifconfig eth1 0.0.0.0
ifconfig wlan0 down
ifconfig wlan0 0.0.0.0

# create the bridge
#brctl addbr br0 ## has already been done by hostapd
#brctl addif br0 wlan0 ## has already been done by hostapd
brctl addif br0 eth1

# bring it all up
ifconfig br0 up
ifconfig br0 192.168.137.1
ifconfig br0 netmask 255.255.255.0
ifconfig br0 broadcast 192.168.137.255
ifconfig eth1 up
ifconfig wlan0 up

# things seem to need a kick in the pants after messing with the interfaces
service hostapd restart
service isc-dhcp-server restart
Make sure you have IP forwarding enabled (echo 1 > /proc/sys/net/ipv4/ip_forward until you are ready to do it right). Be sure dhcp is set to listen on br0.

It's working like a charm here.

--twoprops
 
  


Reply

Tags
bridge, router, wifi



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] share 3g usb connection with wifi router thaiiceland LinuxQuestions.org Member Success Stories 0 01-18-2014 05:52 PM
[SOLVED] Add second subnet on eth0 to configure new wifi router rshepard Slackware 1 08-11-2013 03:58 PM
Want to share wifi over ethernet connection Adol Linux - Newbie 8 10-02-2012 08:32 AM
issues with configuring ethernet/wifi and ext monitor on eeepc (1005HA) katesfb Linux - Laptop and Netbook 3 08-14-2009 04:28 PM
wifi adhoc without router can't share internet can ping fani Linux - Wireless Networking 3 05-28-2007 06:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration