NanoKVM wiki: https://wiki.sipeed.com/hardware/zh/kvm/NanoKVM/network/frp.html
frp releases: https://github.com/fatedier/frp/releases
1. Create and configure instance in Oracle Cloud Infrastructure as frp server.
1a: add rules in virtual cloud network -> security -> security rules
1b: add iptables rules in ubuntu
example: (10001 as server port, 20001 as http port)
sudo iptables -I INPUT -p tcp -m tcp --dport 10001 -j ACCEPT
sudo iptables -I INPUT -p tcp -m tcp --dport 20001 -j ACCEPT
sudo netfilter-persistent save
sudo netfilter-persistent reload
1c: download and extract frp release:
wget <https link>
tar -xzvf <frp file name>
cd <dir name>
1d: modify configuration file:
vim frps.toml
==============================
bindPort = 10001
vhostHTTPPort = 20001
==============================
1e: test service
./frps -c frps.toml
2. Download frpc files in NanoKVM
2a: as NanoKVM cannot download https and extract gzip files, you need to download and extract riscv64 files from frp release page in your computer and build a http server.
example: HFS, a simple http file server
2b: login to NanoKVM, open terminal, download frpc files:
wget http://<HFS IP>:<HFS Port>/frpc
wget http://<HFS IP>:<HFS Port>/frpc.toml
2c: modify configuration file:
vim frps.toml
==============================
serverAddr = "<public ip of oci instance>"
serverPort = 10001
[[proxies]]
name = "nano-kvm"
type = "http"
localPort = 80
customDomains = ["<your domain or public ip of oci instance>"]
==============================
2d: test service
./frpc -c frpc.toml
2e: open browser and check with http://<your domain or public ip of oci instance>:20001
If you configure a domain, you'll not be able to login with IP
3. Configure frps as a system service to make frps run when system start
3a: create service file
vim /etc/systemd/system/frps.service
==============================
[Unit]
Description=autostartscript
[Service]
Type=simple
ExecStart=/home/ubuntu/frps/frps -c /home/ubuntu/frps/frps.toml
Restart=always
RestartSec=3s
[Install]
WantedBy=multi-user.target
==============================
systemctl daemon-reload
systemctl enable frps
3c: reboot the instance to see if service starts
systemctl status frps
ss -tulpn (see open ports)
4. Configure frpc as a system service to make frpc run when nanokvm start
4a: login to NanoKVM, open terminal
4b: create script
vim /etc/init.d/S99frpc
==============================
#!/bin/sh
case "$1" in
start)
/root/frpc/frpc -c /root/frpc/frpc.toml
echo "frpc started"
;;
stop)
killall frpc
echo "frpc stopped"
;;
restart)
killall frpc
sleep 1
/root/frpc/frpc -c /root/frpc/frpc.toml
echo "frpc restarted"
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
==============================
4c: change mode
chmod 755 /etc/init.d/S99frpc
4d: reboot and check if process is running
ps | grep frpc
4e: if the process is not running, you cna check if frpc is executable or not, if not change mode
cd /root/frpc/
ls -l
chmod +x frpc
5. Domain Name settings
5a: if you have a domain name, you can configure with your domain name in step 2c.
For example:
Type: A record
Host: kvm.your.domain
Answer: <public IP address of instance>
You will need to connect to http://kvm.your.domain:20001
5b: you can also configure additional url forwarding to make url simple
For example:
Host: kvm01.your.domain
Destination: kvm.your.domain:20001
HTTP redirect type: Masked
Include path: No
Wildcard forwarding: No
You can connect to http://kvm01.your.domain
In this case, the custom domain in step 2c. is still "kvm.your.domain"
6. Multiple NanoKVM with 1 frps server
6a: create multiple .toml files in frps (step 1d), don't forget to add iptables rules
vim frps20001.toml
==============================
bindPort = 10001
vhostHTTPPort = 20001
==============================
vim frps20002.toml
==============================
bindPort = 10002
vhostHTTPPort = 20002
==============================
vim frps20003.toml
==============================
bindPort = 10003
vhostHTTPPort = 20003
==============================
vim /etc/systemd/system/frps20001.service
==============================
[Unit]
Description=autostartscript
[Service]
Type=simple
ExecStart=/home/ubuntu/frps/frps -c /home/ubuntu/frps/frps20001.toml
Restart=always
RestartSec=3s
[Install]
WantedBy=multi-user.target
==============================
vim /etc/systemd/system/frps20002.service
==============================
[Unit]
Description=autostartscript
[Service]
Type=simple
ExecStart=/home/ubuntu/frps/frps -c /home/ubuntu/frps/frps20002.toml
Restart=always
RestartSec=3s
[Install]
WantedBy=multi-user.target
==============================
vim /etc/systemd/system/frps20003.service
==============================
[Unit]
Description=autostartscript
[Service]
Type=simple
ExecStart=/home/ubuntu/frps/frps -c /home/ubuntu/frps/frps20003.toml
Restart=always
RestartSec=3s
[Install]
WantedBy=multi-user.target
==============================
Host: kvm01.your.domain
Destination: kvm.your.domain:20001
Host: kvm02.your.domain
Destination: kvm.your.domain:20002
Host: kvm03.your.domain
Destination: kvm.your.domain:20003