{"id":119,"date":"2014-02-08T12:35:02","date_gmt":"2014-02-08T11:35:02","guid":{"rendered":"https:\/\/overdespotiet.dk\/blog\/?p=119"},"modified":"2024-06-19T13:34:51","modified_gmt":"2024-06-19T11:34:51","slug":"static-fixed-and-wifi-ips-on-raspberry-pi","status":"publish","type":"post","link":"https:\/\/overdespotiet.dk\/blog\/?p=119","title":{"rendered":"Static fixed and wifi IPs on Raspberry Pi"},"content":{"rendered":"<p>When coding to and configuring ones Raspberry Pi, it is convenient to have it on a wired connection, but when it is being deployed in the field, it is much easier to have it on wifi.<\/p>\n<p>Still, it can be immensely useful to have it&#8217;s IPs always be fixed, making surveillance etc a breeze (or more breezely, to be exact) and thus here&#8217;s a quick guide to making that happen. There are other tutorials on this, but most are about fixed IP for <em>either<\/em> eth0 or wlan0.<!--more--><\/p>\n<p>Without further ado, on to <strong><em>\/etc\/network\/interfaces<\/em><\/strong>:<\/p>\n<pre>iface eth0 inet static\r\n\u00a0\u00a0\u00a0 address 192.168.1.173\r\n\u00a0\u00a0\u00a0 netmask 255.255.255.0\r\n\u00a0\u00a0\u00a0 network 192.168.1.0\r\n\u00a0\u00a0\u00a0 broadcast 192.168.1.255\r\n\u00a0\u00a0\u00a0 gateway 192.168.1.1\r\n\r\nallow-hotplug wlan0\r\niface wlan0 inet manual\r\nwpa-roam \/etc\/wpa_supplicant\/wpa_supplicant.conf\r\n    address 192.168.1.172\r\n    netmask 255.255.255.0\r\n    network 192.168.1.0\r\n    broadcast 192.168.1.255\r\n    gateway 192.168.1.1\r\niface default inet static\r\n\u00a0\u00a0\u00a0 address 192.168.1.172\r\n\u00a0\u00a0\u00a0 netmask 255.255.255.0\r\n\u00a0\u00a0\u00a0 gateway 192.168.1.1<\/pre>\n<p>The &#8220;trick&#8221; is to set a static IP for <em><strong>eth0<\/strong><\/em>, configure <em><strong>wlan0<\/strong><\/em> and set a default overall static IP, which will apply to <em><strong>wlan0<\/strong><\/em> since there already is an explicit static IP for <em><strong>eth0<\/strong>.\u00a0<\/em>It should be possible to reference the <strong><em>wlan0<\/em><\/strong> blurb via using\u00a0<strong><em>id_str=&#8221;wlan0&#8243;<\/em><\/strong> in\u00a0<strong>wpa_supplicant.conf<\/strong>, but alas, that doesn&#8217;t work for me.<\/p>\n<p>Add the necessary <em><strong>network={&#8230; <\/strong><\/em>blurb to <em><strong>\/etc\/wpa_supplicant\/wpa_supplicant.conf<\/strong><\/em> and you&#8217;re good to go:<\/p>\n<pre>ctrl_interface=DIR=\/var\/run\/wpa_supplicant GROUP=netdev\r\nupdate_config=1\r\n\r\nnetwork={\r\n  ssid=\"your SSID\"\r\n  psk=\"yourpassword\"\r\n\r\n  # Protocol type can be: RSN (for WP2) and WPA (for WPA1)\r\n  proto=RSN\r\n\r\n  # Key management type can be: WPA-PSK or \r\n  # WPA-EAP (Pre-Shared or Enterprise)\r\n  key_mgmt=WPA-PSK\r\n\r\n  # Pairwise can be CCMP or TKIP (for WPA2 or WPA1)\r\n  pairwise=TKIP\r\n\r\n  # Authorization option should be OPEN for both WPA1\/WPA2 (in less \r\n  # commonly used are SHARED and LEAP)\r\n  auth_alg=OPEN\r\n}<\/pre>\n<p>Issue a quick<\/p>\n<pre>pi@raspberrypi ~ $ sudo ifup wlan0<\/pre>\n<p>And verify with<\/p>\n<pre>pi@raspberrypi ~ $ ifconfig\r\neth0\u00a0\u00a0\u00a0\u00a0\u00a0 Link encap:Ethernet\u00a0 HWaddr b8:27:eb:95:ca:9e\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 inet addr:192.168.1.173\u00a0 Bcast:192.168.1.255\u00a0 Mask:255.255.255.0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ...\r\n\r\nwlan0\u00a0\u00a0\u00a0\u00a0 Link encap:Ethernet\u00a0 HWaddr 4c:60:de:5d:7e:6a\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 inet addr:192.168.1.172\u00a0 Bcast:192.168.1.255\u00a0 Mask:255.255.255.0\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ...<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When coding to and configuring ones Raspberry Pi, it is convenient to have it on a wired connection, but when it is being deployed in the field, it is much easier to have it on wifi. Still, it can be &hellip; <a href=\"https:\/\/overdespotiet.dk\/blog\/?p=119\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,18,28],"tags":[],"class_list":["post-119","post","type-post","status-publish","format-standard","hentry","category-linux","category-networking","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=119"}],"version-history":[{"count":9,"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/119\/revisions"}],"predecessor-version":[{"id":244,"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/119\/revisions\/244"}],"wp:attachment":[{"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/overdespotiet.dk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}