Is it possible to setup a linux box to act as a hub/switch between two interfaces? I have an ubuntu box connected wirelessly on wlan0. I'd like to connect up another machine to the ubuntu boxes eth0 and have the other machine use that connect AND be on the same network as the ubuntu box. Is this possible?
-
Similar questions here: serverfault.com/questions/35964/… and here: serverfault.com/questions/35307/how-to-forward-wlan0-to-eth0– Dennis WilliamsonJul 10, 2009 at 7:57
-
If you want some security while doing something like this, I would use pfSense.– Brad GilbertJul 10, 2009 at 16:04
3 Answers
Hello "unknown" Google-User,
what you want is to set up a bridge rather than a router, if you want to span the subnet over lan and wlan. This will make your two NICs to behave like a switch.
Under Debian/Ubuntu, install the bridge-utils
package. Then create a Bridge and add NICs to it:
brctl addbr br0
brctl addif br0 eth0 wlan0
HTH
Yes it is possible. What you describe is very simple:
echo 1 > /proc/sys/net/ipv4/ip_forward
Note that this will dissapear when you reboot the "router" box. If you want it to persist across reboots, then you will need to edit /etc/sysctl.conf
and either add or edit the following line to look like this
net.ipv4.ip_forward = 1
EDIT: As usual, security comes later. Note that by doing this, any wardriver will be able to connect to your local network, bypassing all firewalls. To get it to firewall, also run (as root)
iptables -t nat -A FORWARD -j CHAIN-OF-YOUR-CHOICE
CHAIN-OF-YOUR-CHOICE
might be INPUT, if you have a good chain set up. What I'd do instead is to do:
iptables -I INPUT -j USER_DEFINED_CHAIN
iptables -t nat -I FORWARD -j USER_DEFINED_CHAIN
iptables -I USER_DEFINED_CHAIN <rule definitions of choice>
As the question specifically says that they machines need to be on the same network, then IP forwarding or NAT/PAT isn't going to help.
What I think you want is to bridge the two interfaces. Maybe this "Ethernet Bridge + netfilter howto" can help.
IBM has also a nice guide how to build wireless access points in Linux