如何将旧手机改装成网络服务器
How to repurpose your old phone into a web server

原始链接: https://far.computer/how-to/

## 让你的旧手机焕发新生:迷你家庭服务器 本教程将指导你如何将旧安卓手机(例如Fairphone 2)改造成一个小型、实用的家庭服务器——减少电子垃圾并延长设备的使用寿命。你需要一部未使用的手机、充电器、WiFi和一台Linux电脑。 这个过程涉及安装 **postmarketos**,一个适用于手机的Linux发行版。这使用 `pmbootstrap` 完成——安装镜像、将其刷入你的设备并启动它。postmarketos 运行后,你将使用默认凭据(user/147147)通过SSH连接,并连接到你的WiFi网络。 教程随后演示了提供一个简单的网页。它包括创建目录、添加HTML文件、配置防火墙规则和启动一个基本的Web服务器。然后,你可以通过手机的IP地址从本地网络上的任何设备访问此网页。 最后,它建议使用VPN进行安全的远程访问,而不是直接暴露SSH。定期更新通过 `apk update` 和 `apk upgrade` 实现。进一步的开发将包括设置域名、HTTPS和持久服务器运行。

## 将旧手机用作Web服务器:Hacker News讨论 Hacker News上的一场讨论集中在将旧智能手机变成Web服务器。虽然可行,但对话强调了关键挑战。**内核支持至关重要**:运行现代Linux发行版(如通过PostmarketOS的Arch ARM)是理想选择,但许多旧手机停留在过时且不受支持的内核上,存在安全风险。 电池寿命和安全性也是主要问题。让手机24/7运行可能导致电池膨胀和潜在故障。讨论的解决方案包括移除电池(在现代手机上很困难)或尝试用电容“模拟”电池。 关于互联网访问,用户建议使用Cloudflare tunnels或廉价VPS等服务,以避免直接暴露和潜在的ISP问题。虽然ISP *可能* 会监控带宽,但加密流量使得难以确定活动。 最终,实用性存在争议——许多人认为,专用低功耗服务器是更可靠和安全的解决方案,尤其是在已经可用时。然而,内置电池提供了一种潜在的UPS优势。
相关文章

原文

back to home


this webpage is hosted on a drawer-bound fairphone 2 from 2015, running postmarketos

in this tutorial you will be guided through the steps taken to get there

you will end up with a small home server, able to run basic services

we aim to reduce e-waste, encourage reuse and give a second life to forgotten chips

you will need

  • an unused android phone
  • a charger and power source
  • a wifi connection
  • a computer running linux (natively or in a virtual machine)

step 1: installing postmarketos

first step is installing postmarketos on your phone

find your device in the devices page and verify that your device is properly supported

keep that page open throughout the installation

install pmbootstrap, the main command-line application for postmarketos

we'll first generate the image, then flash it to the device

generate the image

update the ports and initialize your device information:

$ pmbootstrap pull
$ pmbootstrap init

when asked for the codename for your device, provide the one listed in your device's page you opened above

when asked for which user interface to use, you can choose console (which should be the most minimal option) or fbkeyboard to have a minimal keyboard on-screen (which you shouldn't have to use thanks to ssh, but just in case, it's fun)

generate the image:

$ pmbootstrap install

flash the image

check your device's page for how to boot your device in flash mode

usually this means powering the device on with the "volume down" button pressed

connect the phone into your computer and boot it in flash mode

next, check the Installation section of the page and follow any instructions listed there

finally, if you have not already, flash the image to the device:

$ pmbootstrap flasher flash_rootfs

then, reboot the device and verify that postmarketos starts-up correctly


step 2: setting up your server

now that your phone is postmarketos'ed, let's log into it

the default postmarketos username/password combination is user/147147

keep the phone connected to your computer and ssh into it:

$ ssh [email protected]

connect the phone to your wifi network:

$ nmcli device wifi connect your_wifi_network --ask

congrats, you now officially have a little local phone server

running this command should show you the phone's local ip address:

$ ip -4 addr show wlan0 | grep inet | awk '{print $2}' | cut -d'/' -f1

on a typical home router it will have the form 192.168.1.x

you can now plug the phone somewhere safe and connect to it via wifi:

ssh [email protected]

step 3: serving a web page

create the /var/www/html/ directory:

sudo mkdir -p /var/www/html/

write a simple hello world html file:

$ sudo sh -c 'echo "<h1>hello world</h1>" > /var/www/html/index.html'

add a nftables rule to allow incoming packets on port 80, in /etc/nftables.d/99_http.nft:

inet filter input tcp dport 80 ct state new accept

then restart nftables:

$ sudo systemctl restart nftables

run the following to launch your webserver:

$ httpd -h /var/www/html/

test out the server by curling the website from your computer:

$ curl 192.168.1.x

you should see the <h1>hello world</h1> text from above

now type the ip address in the web browser of any device connected to the same wifi network, and marvel at your own tiny local digital garden

note that this http server will not be automatically restarted if your phone reboots for any reason


extra: remote access

as a preemptive security measure, i would recommend not to open port 22 (used for ssh) to the wider internet

instead you should set up a vpn access to your router box (most support this on their web interfaces) if you need remote access

once you are connected to your local network, access the phone using ssh as before

if you know what you are doing and still want to open up port 22 to the internet, remember to disable password login and set up ssh keys


extra: maintenance

to update the packages on your server, run:

$ sudo apk update
$ sudo apk upgrade

next steps

In the advanced part of this tutorial (still under construction), you will learn how to:

  • setup a domain and https
  • make the http server persist after reboot

built by louis merlin under the cc by-nc-sa 4.0 license

联系我们 contact @ memedata.com