Friday, 9 July 2010

Bridge Wireless and Wired Network Adapters in Linux

In this blog post I shall describe how to bridge your wired connection to your wireless adapter. To be more specific the wireless (called wlan0 from now) is where the master device is receiving it's network (i.e. internet) connection; the wired connection (called eth0 from now on) is what you are going to share the connection via.

First things first you need to know how to compile a custom kernel. If you don't, stop here and find out how to. If you do no how you need to add the following entries to your.config file:

CONFIG_NF_CONNTRACK=y
CONFIG_NF_CT_ACCT=y
CONFIG_NF_CONNTRACK_MARK=y
CONFIG_NF_CONNTRACK_ZONES=y
CONFIG_NF_CONNTRACK_EVENTS=y
CONFIG_NF_CT_PROTO_DCCP=y
CONFIG_NF_CT_PROTO_GRE=y
CONFIG_NF_CT_PROTO_SCTP=y
CONFIG_NF_CT_PROTO_UDPLITE=y
CONFIG_NF_CONNTRACK_AMANDA=y
CONFIG_NF_CONNTRACK_FTP=y
CONFIG_NF_CONNTRACK_H323=y
CONFIG_NF_CONNTRACK_IRC=y
CONFIG_NF_CONNTRACK_NETBIOS_NS=y
CONFIG_NF_CONNTRACK_PPTP=y
CONFIG_NF_CONNTRACK_SANE=y
CONFIG_NF_CONNTRACK_SIP=y
CONFIG_NF_CONNTRACK_TFTP=y
CONFIG_NF_CT_NETLINK=y
CONFIG_NF_DEFRAG_IPV4=y
CONFIG_NF_CONNTRACK_IPV4=y
CONFIG_NF_CONNTRACK_PROC_COMPAT=y
CONFIG_NF_NAT=y
CONFIG_NF_NAT_NEEDED=y
CONFIG_NF_NAT_SNMP_BASIC=y
CONFIG_NF_NAT_PROTO_DCCP=y
CONFIG_NF_NAT_PROTO_GRE=y
CONFIG_NF_NAT_PROTO_UDPLITE=y
CONFIG_NF_NAT_PROTO_SCTP=y
CONFIG_NF_NAT_FTP=y
CONFIG_NF_NAT_IRC=y
CONFIG_NF_NAT_TFTP=y
CONFIG_NF_NAT_AMANDA=y
CONFIG_NF_NAT_PPTP=y
CONFIG_NF_NAT_H323=y
CONFIG_NF_NAT_SIP=y
CONFIG_NF_CONNTRACK_IPV6=y

You'll need to build a new kernel and boot of it.

Next you'll need dnsmasq. Set that up to serve ip addresses to eth0 ranging from 192.168.1.69.2 to 100. For me I edited /etc/dnsmasq.conf and added (I have no idea what 12h means. Maybe 12 hosts in the range 2-100):
dhcp-range=192.168.69.2,192.168.69.100,12h
interface=eth0

eth0's address needs to made 192.168.69.1
ifconfig eth0 192.168.69.1

If iptables is not there install it and then run:
iptables -t nat -A POSTROUTING -s 192.168.69.0/24 -d 0/0 -j MASQUERADE
Make the kernel to allow forwarding:
 echo "1" > /proc/sys/net/ipv4/ip_forward
Run dnsmasq:
/etc/init.d/dnsmasq start

All done.


NB. This was done on Funtoo

No comments:

Post a Comment