{"id":59,"date":"2006-11-27T02:28:10","date_gmt":"2006-11-27T01:28:10","guid":{"rendered":"http:\/\/blogs.igalia.com\/eocanha\/?p=59"},"modified":"2015-11-08T00:21:10","modified_gmt":"2015-11-07T23:21:10","slug":"my-own-flavour-of-network-config-automatic-choosing","status":"publish","type":"post","link":"https:\/\/eocanha.org\/blog\/2006\/11\/27\/my-own-flavour-of-network-config-automatic-choosing\/","title":{"rendered":"My own flavour of network config automatic choosing"},"content":{"rendered":"<p>Until a couple of days ago, I used to use Gnome network-admin&#8217;s ability of having multiple network profiles to configure my wifi card at work and at home. But yesterday, the program went crazy and started to crash without any logical reason and I decided to shift to another solution: logical network interface mapping.<\/p>\n<p>Interface mapping is a feature of ifupdown (\/etc\/network\/interfaces). You can define some logical interfaces and call a script in order to choose which one will be mapped to a physical interface. The \/etc\/network\/interfaces could be like this one (being HomeNET and WorkNET two existing ESSID network identifiers):<\/p>\n<blockquote><p>auto eth1<br \/>\nmapping eth1<br \/>\nscript \/root\/WIFI\/wldetect.sh<br \/>\nmap HomeNET HomeNET<br \/>\nmap WorkNET WorkNET<\/p>\n<p>iface HomeNET inet static<br \/>\naddress 192.168.1.2<br \/>\nnetmask 255.255.255.0<br \/>\ngateway 192.168.1.1<br \/>\nwireless-essid HomeNET<br \/>\nwireless-key s:mysecretpass1 open<br \/>\ndns-nameservers 127.0.0.1 192.168.1.1<\/p>\n<p>iface WorkNET inet dhcp<br \/>\nwireless-essid WorkNET<br \/>\nwireless-key s:mysecretpass2 open<br \/>\ndns-nameservers 127.0.0.1 192.168.100.1<\/p><\/blockquote>\n<p>I&#8217;m using resolvconf to activate the dns-nameservers directive in the interfaces file, and dnsmasq to take care of some dns issues with a couple of VPNs I use. That explains the first 127.0.0.1 entry.<\/p>\n<p>The script \/root\/WIFI\/wldetect.sh lists the available networks and chooses one of them being in a whitelist (HomeNET|WorkNET):<\/p>\n<blockquote><p>#!\/bin\/sh<\/p>\n<p># Config<br \/>\nWL_IFACE=`iwconfig 2&gt;\/dev\/null | { read A _; echo $A; };`<\/p>\n<p># Reset the interface<br \/>\nifconfig $WL_IFACE down<br \/>\nifconfig $WL_IFACE 0.0.0.0<br \/>\nifconfig $WL_IFACE up<\/p>\n<p># Search networks<br \/>\nNETWORKS=`iwlist $WL_IFACE scanning | grep ESSID | sed -e &#8216;s\/.*&#8221;(.*)&#8221;\/1\/&#8217;`<\/p>\n<p># Bring down the interface<br \/>\nifconfig $WL_IFACE down<\/p>\n<p># Select preferred networks<br \/>\nfor NET in $NETWORKS<br \/>\ndo<br \/>\ncase $NET in<br \/>\nHomeNEt|WorkNET)<br \/>\necho $NET;<br \/>\nexit 0;<br \/>\n;;<br \/>\nesac<br \/>\ndone<br \/>\nexit 1;<\/p><\/blockquote>\n<p>And that&#8217;s all! I hope that this configuration could be helpful for someone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Until a couple of days ago, I used to use Gnome network-admin&#8217;s ability of having multiple network profiles to configure my wifi card at work and at home. But yesterday, the program went crazy and started to crash without any logical reason and I decided to shift to another solution: logical network interface mapping. Interface &hellip; <a href=\"https:\/\/eocanha.org\/blog\/2006\/11\/27\/my-own-flavour-of-network-config-automatic-choosing\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">My own flavour of network config automatic choosing<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/posts\/59"}],"collection":[{"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":1,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":440,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions\/440"}],"wp:attachment":[{"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eocanha.org\/blog\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}