# 记录将旧笔记本作为服务器


## 背景

大学时候用的笔记本已经很旧了, 所以将它作为服务器。因为我有自己的 vps 和域名, 所以使用 frp 作为穿透工具。目的是, 可以通过外网 ssh, 还有可以作为 web 服务器使用。

## 安装 debian 13 之后, 安装无线网卡驱动, 并连接 wifi

安装 NetworkManager (个人爱好):

```sh
apt install cockpit-networkmanager
```

查看网卡型号:

```sh
# Broadcom Inc. and subsidiaries BCM43142 802.11b/g/n (rev 01)
lspci | grep -i network
```

因为 `BCM43142` 需要 `broadcom-sta-dkms`, 所以:

1. /etc/apt/sources.list 添加:

```
deb http://deb.debian.org/debian/ trixie contrib main non-free-firmware non-free
deb-src http://deb.debian.org/debian/ trixie contrib main non-free-firmware non-free
```

2. 安装:

```ssh
apt update

apt install linux-headers-$(uname -r)
apt install broadcom-sta-dkms
modprobe wl
systemctl restart NetworkManager
```

连接 wifi:

```ssh
nmtui
```

## 配置笔记本合上盒子不睡眠

/etc/systemd/logind.conf:

```
HandleLidSwitch=suspend
HandleLidSwitchExternalPower=lock
```

```sh
systemctl status systemd-logind
```

## 配置 ssh

See [禁用SSH密码认证并启用密钥认证](https://johanchane.github.io/my-blog/posts/ssh%E5%85%B3%E9%97%AD%E5%AF%86%E7%A0%81%E5%90%AF%E7%94%A8%E5%AF%86%E9%92%A5%E8%AE%A4%E8%AF%81/)

## 配置 frp

### vps

```sh
wget https://github.com/fatedier/frp/releases/download/v0.69.1/frp_0.69.1_linux_amd64.tar.gz
```

/opt/frps:

```
/opt/frps/
├── frps
└── frps.toml
```

frps.toml:

```toml
bindPort = 7000
vhostHTTPSPort = 8443   # 因为 nginx 占用了 443, 所以直接用 8443 算了

[auth]
method = "token"
token = "xxx"

# Web 管理界面（可选）
[webServer]
addr = "0.0.0.0"
port = 7500
user = "xxx"
password = "@xxx"

# 日志配置
[log]
to = "./frps.log"
level = "info"
maxDays = 7
```

/etc/systemd/system/frpc.servie:

```
[Unit]
# Service name, customizable
Description = frp server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
# Command to start frps, modify to your frps installation path
ExecStart = /opt/frps/frps -c /opt/frps/frps.toml

[Install]
WantedBy = multi-user.target
```

Enable and start the `frps` service:

```sh
systemctl daemon-reload
systemctl start frps
systemctl enable frps
```

### 旧笔记本


```sh
wget https://github.com/fatedier/frp/releases/download/v0.69.1/frp_0.69.1_linux_amd64.tar.gz
```

/opt/frps:

```
/opt/frpc/
├── frpc
└── frpc.toml
```

frpc.toml:

```toml
serverAddr = "foo.domain.com"
serverPort = 7000
auth.token = "xxx"    # 和 server 的一样

[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000

[[proxies]]
name = "test_htts2http"
type = "https"
customDomains = ["foo.domain.com"]

[proxies.plugin]
type = "https2http"
localAddr = "127.0.0.1:8443"

# HTTPS certificate related configuration
crtPath = "xxx/fullchain.pem"
keyPath = "xxx/private.pem"
hostHeaderRewrite = "127.0.0.1"
requestHeaders.set.x-from-where = "frp"
```

/etc/systemd/system/frpc.servie:

```
[Unit]
Description = frp client
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
ExecStart = /opt/frpc/frpc -c /opt/frpc/frpc.toml

[Install]
WantedBy = multi-user.target
```

Enable and start the `frpc` service:

```sh
systemctl daemon-reload
systemctl start frpc
systemctl enable frpc
```

在 nginx 中配置 domain 的 website. /etc/nginx/site-available/foo.domain.com:

```
server {
    listen 127.0.0.1:8443;
    listen [::1]:8443;

    root /var/www/foo.domain.com/html;

    access_log /var/log/nginx/foo.domain.com.access.log;
    error_log /var/log/nginx/foo.domain.com.error.log;
}
```

```sh
ln -sf /etc/nginx/site-availables/foo.domain.com /etc/nginx/site-enable/foo.domain.com
nginx -t
systemctl relod nginx
```

acme + cloudflare 申请证书的工具: [acme-cloudflare](https://github.com/JohanChane/server-utils/tree/main/acme-cloudflare)

记得在 cloudflare 添加 domain 的 dns 记录。

验证:

```sh
ssh ...
curl https://foo.domain.com:8443
```

## References

-   [Debian 13: How to Fix: “No Wi-Fi Adapter Found” - Lenovo Z50-70](https://itsfoss.community/t/debian-13-how-to-fix-no-wi-fi-adapter-found-lenovo-z50-70/15332)
-   [frp 内网穿透完整指南：从入门到实战](https://zhuanlan.zhihu.com/p/1913504354721333378?share_code=D9EaRqQTqfBL&utm_psn=1983799156490388420)
-   [frp docs](https://gofrp.org/en/docs/setup/)


---

> 作者: [JohanChane](https://github.com/johanchane)  
> URL: https://johanchane.github.io/my-blog/posts/%E8%AE%B0%E5%BD%95%E5%B0%86%E6%97%A7%E7%AC%94%E8%AE%B0%E6%9C%AC%E4%BD%9C%E4%B8%BA%E6%9C%8D%E5%8A%A1%E5%99%A8/  

