29
Aug
2015

Ubuntu Server 15.04: Bridging Two Connections!

I have covered setting up a personal hotspot in this post, but how do you do the opposite? That is, to send your wireless connection down through your ethernet connection to another PC or a switch. In this episode, I will cover this!

I am using Ubuntu Server 15.04 to do this, but under Ubuntu Desktop, it is very simple. All you have to do is connect to WiFi and set your ethernet connection as “Shared to other computers“.

Under Server, you have to make a couple of changes.

Firstly, make sure you have bridge-utils installed:

sudo apt-get install bridge-utils

Open your /etc/network/interfaces file and add the following to the bottom:

# Bridge
iface br0 inet static
address 192.168.1.1
netmask 255.255.255.0
bridge_ports eth0
bridge_fd 0
bridge_maxwait 0
post-up iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

That will initialize the bridge from eth0 (or whatever your ethernet interface is). Change wlan0 in the bottom line to whatever your wireless interface is. The address line needs to be different from the network that your wireless is running on. If your existing network uses 192.168.1.xxx then use 192.168.2.1, etc. Mine uses 192.168.0.xxx.

So that’s the bridging and firewall done. That last line allows packets to be transferred between wlan0 and br0, which is bridged to eth0. Now, we need to make sure that whatever gets connected to the ethernet jack gets an IP address from DHCP. To do that, we need to use isc-dhcp-server:

sudo apt-get install isc-dhcp-server

This will install the DHCP server. We need to make sure this runs on eth0 and nothing else. Edit /etc/default/isc-dhcp-server and make sure it only has the following line:

INTERFACES=br0

This will let the DHCP server run on the bridge (which is bridged to eth0). Next, we need to configure the server to hand out IP’s. Edit /etc/dhcp/dhcpd.conf and add the following to the bottom:

option routers 192.168.1.1;
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option domain-name-servers 8.8.8.8;
# Bridge
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
}

This will set up the DHCP server on the 192.168.1.0 network (the same network that br0 is running on). I have it configured to assign between .10 and .100, but you can put anything between .2 and .254 in the range line. You can use whatever DNS server you like, I just used Google for simplicity. Look here to enable your server to cache NSave and close the file.

Now, reboot the server. This should apply all of the settings we have changed. Your connected system should receive an IP and have full internet access. This is great for stopping your WiFi becoming cluttered if you have multiple systems in close proximity.

And that’s it! I have ran 1 gigabit through a bridge and the CPU usage is very low since the overhead is minimal. You can connect to your connected devices from the wireless network just by using the IP that they were given. Happy bridging!

PowerLine Networking: Good house wiring matters! (Ft. TP-Link AV500)
Find me on Mixcloud!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.