{"id":1198,"date":"2016-02-06T23:36:54","date_gmt":"2016-02-07T04:36:54","guid":{"rendered":"http:\/\/blog.jonesling.us\/?p=1198"},"modified":"2016-02-06T23:48:25","modified_gmt":"2016-02-07T04:48:25","slug":"bridging-wired-and-wireless-networks-gentoo-style","status":"publish","type":"post","link":"https:\/\/blog.jonesling.us\/?p=1198","title":{"rendered":"Bridging Wired and Wireless Networks, Gentoo-style"},"content":{"rendered":"<p>I want my wired and wireless networks to share a single <code>192.168.1.x<\/code> address space (instead of separate <code>192.168.0.x<\/code> and <code>192.168.1.x<\/code> addresses).<\/p>\n<p>In order to do that, we need to set up a bridge to merge disparate networks into a single space.<\/p>\n<h2>Part 1: The Basic Configuration<\/h2>\n<p>ADMtek NC100 (uses tulip driver)<br \/>\nRalink RT61 PCI (uses\u00a0rt61pci driver)<br \/>\nhostapd<br \/>\nlinux 4.1.15-gentoo-r1<br \/>\nnet-misc\/bridge-utils 1.5<br \/>\nnet-wireless\/iw 3.17<\/p>\n<h2>Part 2: Making It Work<\/h2>\n<p>I started out creating a basic bridge, using the <a href=\"https:\/\/wiki.gentoo.org\/wiki\/Handbook:X86\/Full\/Networking#Bridging_.28802.1d_support.29\" target=\"_blank\">Gentoo Wiki<\/a> as a guide:<\/p>\n<pre>cd \/etc\/init.d\nln -s net.lo net.br0\n\n\/etc\/init.d\/net.br0 start<\/pre>\n<p>There&#8217;s no need to change how hostapd starts; it still talks to <code>wlan0<\/code> (not <code>br0<\/code>).<\/p>\n<pre># \/etc\/conf.d\/net\n\nmodules_wlan0=\"!iwconfig !wpa_supplicant\"\nconfig_wlan0=\"null\"\nconfig_eth0=\"null\"\nconfig_br0=\"192.168.1.1\/24\"\nbrctl_br0=\"setfd 0\nsethello 10\nstp off\"\nbridge_br0=\"eth0 wlan0\"<\/pre>\n<h3>The Problem<\/h3>\n<p>The above config is naive and doesn&#8217;t work right.\u00a0 I got this error:<\/p>\n<pre>Can't add wlan0 to bridge br0: Operation not supported<\/pre>\n<p>Huh.\u00a0 There&#8217;s nothing indicative in <code>dmesg<\/code> about the error, the last entry shows the bridge being created on the wired card and then being taken down.\u00a0 Just to be sure, I created a bridge with just <code>eth0<\/code> and it worked:<\/p>\n<pre>$ brctl show\nbridge name   bridge id           STP enabled   interfaces\nbr0           8000.00045a42a698   no            eth0<\/pre>\n<p>After casting about a bit, I found a <a href=\"http:\/\/serverfault.com\/questions\/152363\/bridging-wlan0-to-eth0\/554663#554663\" target=\"_blank\">serverfault.com page<\/a> that pointed to this fix:<\/p>\n<pre>$ iw dev wlan0 set 4addr on\n$ brctl addif br0 wlan0<\/pre>\n<p>That works, but that won&#8217;t do me much good as a long-term solution.\u00a0 I would need to pay a visit to the basement after every planned reboot and unplanned power outage, or else nobody can get onto the network.<\/p>\n<p>( More about the 4addr option <a href=\"https:\/\/wireless.wiki.kernel.org\/en\/users\/documentation\/iw#using_4-address_for_ap_and_client_mode\" target=\"_blank\">here<\/a>. )<\/p>\n<p>You can&#8217;t just add the option to <code>modules_wlan0<\/code>, it doesn&#8217;t work that way.\u00a0 A quick visit back to the wiki suggested the solution, though, which is to define a <code>preup<\/code> function where we can execute arbitrary commands.<\/p>\n<h2>The Working Config<\/h2>\n<p>These statements are in addition to the WAN interface config:<\/p>\n<pre># \/etc\/conf.d\/net\nmodules_wlan0=\"!iwconfig !wpa_supplicant\"\nconfig_wlan0=\"null\"\nconfig_eth0=\"null\"\nconfig_br0=\"192.168.1.1\/24\"\nbrctl_br0=\"setfd 0\nsethello 10\nstp off\"\nbridge_br0=\"eth0 wlan0\"\n\npreup() {\n    # br0 uses wlan0, and wlan0 needs to set the\n    # 4addr option before being used on a bridge\n\u00a0\u00a0\u00a0 if echo \"${IFACE}\" | grep -q 'br0' ; then\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/usr\/sbin\/iw dev wlan0 set 4addr on\n\u00a0\u00a0\u00a0 fi\n\n\u00a0\u00a0\u00a0 return 0\n}<\/pre>\n<p>Then do all the accounting to clean up:<\/p>\n<pre>rc-update add net.br0 default\nrc-update del net.eth0 default\nrc-update del net.wlan0 default<\/pre>\n<p>I also had to update my iptables config to refer to <code>br0<\/code> instead of <code>eth0<\/code> and <code>wlan0<\/code>.<\/p>\n<p>Finally, a reboot to test that everything starts properly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want my wired and wireless networks to share a single 192.168.1.x address space (instead of separate 192.168.0.x and 192.168.1.x addresses). In order to do that, we need to set up a bridge to merge disparate networks into a single space. Part 1: The Basic Configuration ADMtek NC100 (uses tulip driver) Ralink RT61 PCI (uses\u00a0rt61pci &hellip; <a href=\"https:\/\/blog.jonesling.us\/?p=1198\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Bridging Wired and Wireless Networks, Gentoo-style&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","wprm-recipe-roundup-name":"","wprm-recipe-roundup-description":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[260,145,83,159,261],"class_list":["post-1198","post","type-post","status-publish","format-standard","hentry","category-linux","tag-bridge","tag-gentoo","tag-linux","tag-networking","tag-wireless"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4o3FW-jk","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=\/wp\/v2\/posts\/1198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1198"}],"version-history":[{"count":7,"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=\/wp\/v2\/posts\/1198\/revisions"}],"predecessor-version":[{"id":1205,"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=\/wp\/v2\/posts\/1198\/revisions\/1205"}],"wp:attachment":[{"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jonesling.us\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}