{"id":1791,"date":"2022-06-21T09:44:53","date_gmt":"2022-06-21T07:44:53","guid":{"rendered":"https:\/\/devpath.pro\/?p=1791"},"modified":"2023-08-29T20:59:41","modified_gmt":"2023-08-29T20:59:41","slug":"server-rack-pet-project-switch","status":"publish","type":"post","link":"https:\/\/fabiocicerchia.it\/sys-admin\/server-rack-pet-project-switch","title":{"rendered":"Server Rack Pet-Project: Switch"},"content":{"rendered":"

After having done a little tweak<\/a> to the rack, I started tackling the networking side.<\/p>\n

I bought a network switch, I have already 2 Raspberry Pi, so finally, I can connect them to the network, then let them do something (not yet sure what though).<\/p>\n

Because those Pis without connection they’ll be useless.<\/p>\n

<\/p>\n

I have opted for an unmanaged switch, I know it is less cool than a managed one, but they are cheaper ?<\/p>\n

I stumbled upon a 16-Port 10\/100BASE-TX Fast Ethernet Switch (FNSW-1601).<\/a> Even though I have only 2 Raspberry and an 8-ports would be more than enough, this one gives me a few extra ports in case I need them, better to have some free slots than to buy a bigger one later.<\/p>\n

\"\"
my little new friend just arrived<\/figcaption><\/figure>\n
\"\"
16 ports would be enough, right?<\/figcaption><\/figure>\n
\"\"
there’s still plenty of room in there<\/figcaption><\/figure>\n
\"\"
wow, I managed to mangle everything even with just a handful of cables<\/figcaption><\/figure>\n
\"\"
look at those nice green lights turned on!<\/figcaption><\/figure>\n
\"\"
road test: ssh connection works!<\/figcaption><\/figure>\n

At the moment there is a “nice” networking setup. The Raspberry A has a WiFi dongle + ethernet connected to the switch, so I can also share its own connection to the Raspberry B. This is great because if I don’t connect the main ethernet line, they can still access the Internet via WiFi shared connectivity.<\/p>\n

Finally, those Raspberries have found a new place and they can be used for something else than collecting dust.<\/p>\n

Bonus: Implementation Details<\/h2>\n

Here is the trick to enable forwarding the packets across 2 network interfaces:<\/p>\n

# sysctl -w net.ipv4.ip_forward=1<\/pre>\n

More details here: Share the WiFi connection to the Wired interface in CLI<\/a><\/p>\n

Enable the WiFi connection, by editing \/etc\/wpa_supplicant\/wpa_supplicant.conf<\/code>:<\/p>\n

ctrl_interface=DIR=\/var\/run\/wpa_supplicant GROUP=netdev\nap_scan=1\n\nupdate_config=1\n\n# main router\nnetwork={\n\tssid=\"OPERATOR-SSID\"\n\tpsk=\"PASSWORD\"\n\tkey_mgmt=WPA-PSK\n\tid_str=\"wl0\"\n}\n\n# extender (optional)\nnetwork={\n\tssid=\"OPERATOR-SSID2\"\n\tpsk=\"PASSWORD\"\n\tkey_mgmt=WPA-PSK\n\tid_str=\"wl1\"\n}\n<\/pre>\n

Enable the WiFi connection, by editing \/etc\/network\/interfaces.d\/wlan<\/code>:<\/p>\n

allow-hotplug wlan0\nauto wlan0\niface wlan0 inet manual\n  wpa-roam \/etc\/wpa_supplicant\/wpa_supplicant.conf\n\n# main router\niface wl0 inet static\n  address 192.168.1.100\n  netmask 255.255.255.0\n  gateway 192.168.1.254\n  post-up iptables -A FORWARD -i w0 -o eth0 -j ACCEPT\n  post-up iptables -A FORWARD -i eth0 -o w0 -j ACCEPT\n  post-up iptables -t nat -A POSTROUTING -o w0 -j MASQUERADE\n\n# extender (optional)\niface wl1 inet static\n  address 192.168.2.100\n  netmask 255.255.255.0\n  gateway 192.168.1.254\n  post-up iptables -A FORWARD -i wl1 -o eth0 -j ACCEPT\n  post-up iptables -A FORWARD -i eth0 -o wl1 -j ACCEPT\n  post-up iptables -t nat -A POSTROUTING -o wl1 -j MASQUERADE\n<\/pre>\n

It connects just fine to the Internet:<\/p>\n

$ ping 8.8.8.8\nPING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.\n64 bytes from 8.8.8.8: icmp_seq=1 ttl=117 time=19.3 ms\n64 bytes from 8.8.8.8: icmp_seq=2 ttl=117 time=23.2 ms\n64 bytes from 8.8.8.8: icmp_seq=3 ttl=117 time=23.5 ms\n^C\n--- 8.8.8.8 ping statistics ---\n3 packets transmitted, 3 received, 0% packet loss, time 2005ms\nrtt min\/avg\/max\/mdev = 19.316\/22.015\/23.542\/1.914 ms\n<\/pre>\n

Then, the other Pi B (10.0.1.102) needs to set up its network gateway to Pi A (10.0.1.101):<\/p>\n

$ cat \/etc\/network\/interfaces.d\/eth \nauto eth0\niface eth0 inet static\n  address 10.0.1.102\n  netmask 255.255.255.0\n  gateway 10.0.1.101\n  post-up ip route add default via 10.0.1.101 dev eth0<\/pre>\n

And now it can connect to the Internet!<\/p>\n

$ ping 8.8.8.8\nPING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.\n64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=28.9 ms\n64 bytes from 8.8.8.8: icmp_seq=2 ttl=116 time=22.9 ms\n64 bytes from 8.8.8.8: icmp_seq=3 ttl=116 time=23.5 ms\n^C\n--- 8.8.8.8 ping statistics ---\n3 packets transmitted, 3 received, 0% packet loss, time 2002ms\nrtt min\/avg\/max\/mdev = 22.874\/25.088\/28.917\/2.718 ms\n<\/pre>\n

And if I set this on my laptop after plugging in the main ethernet line sudo ifconfig eth0:1 10.0.1.105 netmask 255.255.55.0 up<\/code>,\u00a0I’m in the same network as the 2 Pis \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"

After having done a little tweak to the rack, I started tackling the networking side. I bought a network switch, I have already 2 Raspberry Pi, so finally, I can connect them to the network, then let them do something (not yet sure what though). Because those Pis without connection they’ll be useless.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","footnotes":""},"categories":[6],"tags":[],"aioseo_notices":[],"author_meta":{"display_name":"fabio","author_link":"https:\/\/fabiocicerchia.it\/author\/fabio"},"featured_img":null,"coauthors":[],"tax_additional":{"categories":{"linked":["Sys Admin<\/a>"],"unlinked":["Sys Admin<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 2 years ago","modified":"Updated 7 months ago"},"absolute_dates":{"created":"Posted on June 21, 2022","modified":"Updated on August 29, 2023"},"absolute_dates_time":{"created":"Posted on June 21, 2022 9:44 am","modified":"Updated on August 29, 2023 8:59 pm"},"featured_img_caption":"","series_order":"","_links":{"self":[{"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/posts\/1791"}],"collection":[{"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/comments?post=1791"}],"version-history":[{"count":1,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/posts\/1791\/revisions"}],"predecessor-version":[{"id":2147,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/posts\/1791\/revisions\/2147"}],"wp:attachment":[{"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/media?parent=1791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/categories?post=1791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fabiocicerchia.it\/wp-json\/wp\/v2\/tags?post=1791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}