-
Login to the Orange PI (non root user)
-
orangepi/orangepi
-
We'll change the password later to key authentication
-
Create the folder for the update script:
-
cd ~
-
mkdir dynudns
-
cd dynudns
-
Create update script (don't miss the hyphen at the end):
-
nano dynu.sh
-
echo url="https://api.dynu.com/nic/update?hostname=HOSTNAME&password=MD5PASSWORD" | curl -k -o ~/dynudns/dynu.log -K -
-
Fill in the username with your service login for Dynu.com
-
The password can be the hashed client password
-
CTRL + X then Y to save and exit.
-
Make "dynu.sh" executable:
-
chmod 700 dynu.sh
-
Use a cron job to make the script run every 5 minutes:
-
crontab -e
-
Add the following to the bottom of the crontab:
-
*/5 * * * * ~/dynudns/dynu.sh >/dev/null 2>&1
-
Reboot the Orange PI:
-
sudo reboot
-
Refresh Dynu.com and verify IP address has updated.
-
Done.
Initial setup of the OPZ3 - Get Connected:
Titles not marked with a star are mandatory!
1. Burn "Orangepizero3_1.0.2_debian_bookworm_server_linux6.1.31.img" to a MicroSD card using Win32DiskImager.
1a. Included in the ZIP file is a SHA256 hash of the included IMG file. In Win32DiskImager import the IMG file first, then press "generate". This will create a hash from the imported IMG file so you can verify it against the included SHA file. Once verified, burn "Orangepizero3_1.0.2_debian_bookworm_server_linux6.1.31.img" to a MicroSD card.
2. Hook into the serial port using PuTTY or Terminal with a serial to UART adapter.
-
115,200/8/1, NO FLOW CONTROL
3. Enable VT100
4. Attach ethernet and boot it up. You should see something similar to...
-
$ means you're logged in as a normal user, you can use "su" to obtain root
-
# means you're logged in as root
Change the repo source list from China to USA:
To view the default source list run:
cat /etc/apt/sources.list
The default sources for the Orange PI Debian image are as follows:
deb http://repo.huaweicloud.com/debian bookworm main contrib non-free non-free-firmware
#deb-src http://repo.huaweicloud.com/debian bookworm main contrib non-free non-free-firmware
deb http://repo.huaweicloud.com/debian bookworm-updates main contrib non-free non-free-firmware
#deb-src http://repo.huaweicloud.com/debian bookworm-updates main contrib non-free non-free-firmware
deb http://repo.huaweicloud.com/debian bookworm-backports main contrib non-free non-free-firmware
#deb-src http://repo.huaweicloud.com/debian bookworm-backports main contrib non-free non-free-firmware
The Debian list of sources by country are listed here:
Lets change this from Huawei Cloud to the default Debian mirrors as it's on the official source list (from what I understand deb.debian.org is load balanced ny Fastly CDN):
Commenting out sources as they're not needed for our purposes.
deb http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
# deb-src http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
deb http://deb.debian.org/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src http://deb.debian.org/debian/ bookworm-updates main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
# deb-src http://security.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
# Disable Backports
#
# deb http://deb.debian.org/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src http://deb.debian.org/debian/ bookworm-backports main contrib non-free non-free-firmware
Update the docker source list as well:
sudo nano /etc/apt/sources.list.d/docker.list
Change this:
deb [arch=arm64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian bookworm stable
to this:
deb [arch=arm64] https://download.docker.com/linux/debian/ bookworm stable
To update the new source list in the system, run:
Create a priority file for source repos:
Change the root and default users password:
The default password for both the "root" and "orangepi" accounts are "orangepi".
1. Change the password for the "root" account:
2. Change the password for the user "orangepi":
Disable users from automatically logging in upon reboot:
Refer to the prior image and above the login banner you can see "orangepizero3 login: orangepi (automatic login)" displayed.
When the pi reboots or is manually power cycled the default user "orangepi" will automatically be logged into a session. We don't want this because that means anyone with physical serial access can connect and automatically gain access to that user's shell. If you didn't change the root password at this point then all it takes is "sudo login root", type in the default password twice and you're in.
1. Disable automatic login and reboot to view changes:
sudo auto_login_cli.sh -d
sudo reboot
**Highly suggested against, but if you want a user to automatically be logged in at boot time (replace USERNAME with either "root" or "orangepi") and reboot:
sudo auto_login_cli.sh USERNAME
sudo reboot
Change SSH Port:
The default port is 22 and we will change it to 2222 for this example.
I'm seeing two locations on this Debian installation:
sudo find / -name "sshd_config" -print
-
/etc/ssh/sshd_config
-
/usr/share/openssh/sshd_config
Number one is system wide so we're going to edit that one only.
sudo nano /etc/ssh/sshd_config
Uncomment the line "Port 22" and change it to "Port 2222" so it looks like the image below:
If disabling root login which is highly suggested, leave this window open and continue on. If not save and exit.
Disable root Login via SSH:
We should also disable root login while we're in here.
1. Page down and look for "PermitRootLogin yes" and change "yes" to "no".
2. CTRL + X then Y then Enter to save and quit nano. Reboot when finished.
-
You can get to elevated root by typing "su" before a command and typing the password for the "orangepi" user.
-
You can login directly as root via serial access but not via SSH.
*To view connected users:
*To continuously watch for connected users:
CTRL + C to quit this screen.
Install netdiscover:
Need to find an IP that's on a different subnet? Does not discover VLANS.
-
sudo apt install netdiscover
-
netdiscover -r 192.168.0.0/16
sudo apt update
sudo apt upgrade
sudo apt install netdiscover
sudo netdiscover -r 192.168.0.0/16
Install Screen (already included with image):
sudo apt update
sudo apt upgrade
sudo apt install screen
# To start
screen
# To reattach
screen -r
Disable Password Based Authentication & Enable Public Key Authentication:
1. Open PuTTY Key Generator.
2. Bottom right change 2048 bits to 4096 bits.
3. Press "Generate" above and move the mouse to generate randomness.
4. Insert a "key passphrase" and confirm it again. The passphrase is used to encrypt the private key.
|
Test Keys Used |
5. Save the private key to your computer as "rsa-key-SERVERNAME.ppk".
6. On the pi in the orangepi user's home folder, create a folder called ".ssh" using mkdir.
-
mkdir /home/orangepi/.ssh/
8. Create a new file using nano in the ".ssh" folder called "authorized_keys" and paste in the contents of the public key from the key generator into the file. Save and exit nano.
-
nano /home/orangepi/.ssh/authorized_keys
9. Check and make sure the "authorized_keys" file looks like this (needs to be on one line):
-
ssh-rsa
THEACTUALKEY
rsa-key-SERVERNAME
10. Change the file permissions:
-
chmod 700 /home/orangepi/.ssh
-
chmod 600 /home/orangepi/.ssh/authorized_keys
11. Configure the SSH server details:
-
sudo nano /etc/ssh/sshd_config
-
Change "PubkeyAuthentication" from NO to YES.
-
Change "PasswordAuthentication" to NO.
-
Change "UsePAM" from YES to NO.
12. Restart the ssh service
-
sudo systemctl restart ssh
13. Open PuTTY --> Connection --> SSH --> Auth --> select "rsa-key-SERVERNAME.ppk" (private key).
14. Go back to the session tab and give the PuTTY profile an IP address, port, name, and save.
15. Now when connecting PuTTY will ask for the username and passphrase.
Install UFW (Uncomplicated Firewall):
This will be the front end for iptables.
sudo apt update
sudo apt upgrade
sudo apt install ufw
UFW is disabled by default and you need to open the ports you want before enabling it or you'll lock yourself out.
Allow port 2222 TCP for SSH:
sudo ufw allow 2222/tcp comment 'SSH'
Show Firewall Rules Currently Enabled:
Enable / Disable UFW:
sudo ufw enable
sudo ufw disable
View the status of the firewall:
Disable IPv6 on the Orange PI Zero 3 (optional):
Pull up the config:
1. Select "Network".
2. Select "IPV6" to disable IPv6. When done it should say "Enable IPv6 for APT and system".
Remove Unnecessary Features:
1. Remove "IR Support".
2. Remove "Bluetooth Support".
3. Set a static IP of 192.168.1.250, 10.0.0.250, or 10.1.10.250 (the adapter name is "end0").
4. Set a DHCP reservation in the router as well and while there, port forward your WireGuard UDP port. You'll chose them when we do the PiVPN setup later.
Extra Settings:
1. Configure timezone.
2. Change hostname.
3. Pi-hole (will add to this article at a later date)
Pi-hole:
Pi-hole is a dns sinkhole to protect devices from unwanted content on the web.
By this point you should have the OP3 up and running with UFW installed. We're going to install Pi-hole in this section.
W'll install Pi-hole first as the PiVPN script (heavily adapted from Pi-hole) can detect if Pi-Hole is already installed and will offer to use it as DNS for the VPN clients.
curl -sSL https://install.pi-hole.net | bash
Make sure the Orange PI has a static IP address before continuing!
Pick "end0" as this is the wired interface.
Choose upstream DNS provider (after filtering by Pi-hole who do we send DNS requests to):
We need a visual way to manage Pi-hole. Select "Yes" to install the Admin Web Interface.
Install "lighttpd" web server and required PHP modules.
Using privacy levels you can specify which level of detail you want to see in your Pi-hole statistics. The privacy level may be changed at any time without having to restart the DNS resolver. Note that queries with (partially) hidden details cannot be disclosed with a subsequent reduction of the privacy level. They can be changed either from the Settings page on the dashboard or in FTL's config file.
Choose "0" to hide nothing. All statistics are available.
The script will install required packages at this point.
๐คธ♂️ - Picture not included
When the installation is complete you will be given the following 3 pieces of information:
- The IP address of the device to use as a DNS server
- The link to access the web interface
- The admin web page login password.
Press "OK" to bring you back to the command prompt. Remember you're elevated as root "#". Type "exit" to return to the user prompt "$".
Pi-hole Web Interface:
At this point you can call up the admin web interface to manage Pi-hole using the above addresses. "http://pi.hole/admin" probably won't work since the device already had the host name changed earlier to "orangepizero3".
Use the password given to you at the end of the installation to login.
Web Interface:
This is the main interface. From here you can view total queries, client activity, top domains, top clients, etc. Settings are on the left side.
Change the admin web password:
Assuming you still have the SSH connection to the pi open...
Set a new password for the web interface:
Change Celsius in the web interface to Fahrenheit:
Moar Commands:
Admin Commands:
If you recall during the set up phase the installer suggested we use "StevenBlack's Unified Hosts List (with base extensions)" to get started blocking ads and what not. "This hosts file is a merged collection of hosts from reputable sources with a dash of crowd sourcing via GitHub". As of the time of writing this list contains 154,802 entries.
Adding Additional Ad Lists:
Pi-hole --> Adlists --> Add (right side)
You may want to spend some time on Steven Blacks site and read, read, read before adding more lists to make sure you are targeting the correct audience.
In the image above you'd add that URL to the address section, give the list the following description "SB - Unified Hosts + fake news + gambling + porn + social" and hit add.
Disable the original Unified Hosts list since we've already got it included in the new link.
Notice the question mark to the left of our new list. Click it and you'll see the list has not been downloaded yet.
You'll need to update your gravity list after modifying the adlists.
This can be achieved by either running the command below or by going to "Tools --> Update Gravity". This will go out and retrieve the new list(s) and load them in.
Add UFW Allow Rule for Admin Web Interface:
Pi-hole doesn't seem to modify UFW to allow access to the admin web interface after it's install. Add the following rule to allow traffic to the admin web interface of Pi-hole:
sudo ufw allow 80 comment 'Pi-hole Web Interface'
http://192.168.2.226/ - Displays LightTPD
Using Pi-hole DNS on Workstations:
Now all you need to do is point your devices or router to "orangepizero3" or "192.168.2.226" in this example to start taking advantage of this dns server.
We'll setup PiVPN next to take advantage of this new DNS sinkhole server for remote clients. UFW will check to see if Pi-hole is installed and will offer to use it.
Pi-hole Auto Updates?
PiVPN Set Up (openvpn & wireguard):
Make sure UFW is enabled and your SSH port is forwarded since this script will makes changes that can potentially break UFW at the moment.
curl -L https://install.pivpn.io | bash
|
Initial Screen
|
|
Static IP Warning |
|
IPv6 Leak Warning |
|
Static IP Non-Raspberry PI Warning |
|
Choose local user info screen |
|
Pick the "orangepi" user |
|
Type in password for "orangepi" user. |
|
Select WireGuard or OpenVPN
Pick WireGuard or OpenVPN here to be taken to the appropriate instructions. |
OpenVPN Set Up (client does not require elevated privileges) (slower throughput than wireguard):
- OpenVPN uses UDP port 1194 and TCP port 443 by default.
- It's recommended to change the UDP port to something in the dynamic port range of 49152–65535.
- In our example we'll use the default port for OpenVPN.
*So far we should have UFW installed and enabled and Pi-hole installed and configured.
If Pi-hole is detected it will use that as the VPN DNS. If you select "No" it will send you to the DNS Provider page.
Uninstalling PiVPN will uninstall UFW.
su
curl -L https://install.pivpn.io | bash
UFW needs to be installed and enabled prior to running PiVPN.
sudo apt install ufw.
WireGuard Set Up (client requires elevated privileges!!) (faster throughput than OpenVPN):
-
WireGuard uses port 51820 by default.
-
It's recommended to change this to something in the dynamic port range of 49152–65535.
-
In our example we'll use the default port for WireGuard.
|
For the example we'll use the default port of 51820. |
|
Verify the port number. |
|
Choose DNS resolver for VPN clients (scroll for more). |
There are multiple choices here and only one can be picked. If Pi-hole is already installed the PiVPN installer will ask if you want to use this as the DNS server.
If you pick one then change your mind, cancel and rerun the installer.
As per the install script this is the full list (10/2023):
Quad9
|
9.9.9.9
|
149.112.112.112
|
OpenDNS
|
208.67.222.222
|
208.67.220.220
|
Level3
|
209.244.0.3
|
209.244.0.4
|
DNS.WATCH
|
84.200.69.80
|
84.200.70.40
|
Norton
|
199.85.126.10
|
199.85.127.10
|
FamilyShield
|
208.67.222.123
|
208.67.220.123
|
CloudFlare
|
1.1.1.1
|
1.0.0.1
|
Google
|
8.8.8.8
|
8.8.4.4
|
PiVPN-is-local-DNS
|
|
|
Custom
|
Allow multiple IPs |
Separate by comma and space |
|
We're going to use a subdomain to connect clients to. |
If using Dynu at this point for DDNS then create a DNS entry for the PiVPN server.
|
Choose DDNS address. |
|
Confirm DDNS name choice. |
|
Enter password for "orangepi" user to backup configuration. |
|
Server Keys generation notification. |
Remember when I was talking about making sure UFW was installed and active? Immediately after the msg above, this will appear...
|
UFW Configuration |
** This is how UFW looks after completing the WireGuard installation process. If you don't enable it prior to the installation, you'll experience errors at the browser level that mimic DNS issues. I address this at the end where you can make manual edits to get it working again. Or you could uninstall pivpn and UFW and start fresh. Editing the firewall will be easier once you see the issue.
|
Unattended Upgrades Notification
|
|
Enable Unattended Upgrades |
|
Enter password to enable unattended upgrades. |
|
Installation Complete |
|
Reboot Necessary |
|
Reboot Confirmation |
Adding Users to the WireGuard Server:
1. Log back in as "orangepi".
Notice now there's a virtual adapter for the WireGuard clients below the banner:
|
Virtual Adapter - 10.137.64.1 |
|
ifconfig output - Virtual Adapter - wg0 |
Type "pivpn" to get a list of available commands.
|
PiVPN Available Commands |
2. Type " pivpn -a" to begin adding a client.
-
Enter the user's name as the Client Name, i.e. " john.doe".
The client's config file is generated and placed in " /home/orangepi/configs/".
-
To generate a QR Code for the mobile app run " pivpn -qr".
Generate a new client config for each user!
3. WinSCP into "/home/orangepi/configs/" and download config file to the client machine with the WireGuard client installed.
WinSCP Retrieve User Config File:
Remember you now need to feed WinSCP the private key before connecting!
1. Open WinSCP and click on the word " Advanced..." not the drop down.
2. Click on SSH --> Authentication.
3. Browse for and select your private key file from earlier (rsa-key-orangepi.ppk).
|
rsa-key-orangepi.ppk |
4. Click "OK" and login to your orangepi.
5. Type in private key passphrase.
6. Navigate to " /home/orangepi/configs/" and copy the client config ( john.doe.conf) to the client machine.
Install
WireGuard
Client (Windows 7, 8.1, 10, 11, 2008R2, 2012R2, 2016, 2019, 2022):
-
MSI files are available here.
This installation will cover v0.5.3 for Windows.
2. Literally run "wireguard-installer.exe" and when the installation is done the main window will open.
3. Click "Import tunnel(s) from file" and point it to your config file. In this example we used "john.doe.conf".
4. Click "Activate" to connect.
*You can view the logs on the other tab to verify the handshake process has completed.
*If you see handshake errors over and over again make sure the port is forwarded on the router.
Managing Certificates on the WireGuard Server
:
List active client certificates:
Add a client:
Display the qrcode for a particular client (for mobile adding):
Remove a client:
Disable a client but keep the certificate on the server:
Enable a client that was previously disabled:
View currently connected clients:
Troubleshooting (if you didn't heed my warning about UFW):
No comments:
Post a Comment