setting-up-game-server-rout.../README.md
2024-12-07 23:44:07 +05:30

251 lines
5.6 KiB
Markdown

![image.png](https://git.hhf.technology/hhf/setting-up-game-server-routing-with-unraid-and-vps/raw/branch/main/image.png/image.png)
```
_____ _ _ ____ _ ____ _ _
|_ _|_ _(_) / ___| ___ __ _| | ___ / ___|| |_ __ _ ___| | __
| |/ _` | | \___ \ / __/ _` | |/ _ \ \___ \| __/ _` |/ __| |/ /
| | (_| | | |___) | (_| (_| | | __/ ___) | || (_| | (__| <
|_|\__,_|_|_|____/ \___\__,_|_|\___| |____/ \__\__,_|\___|_|\_\
```
## Prerequisites
Before starting, ensure you have:
- An Unraid server
- A VPS
- Tailscale installed on both Unraid and VPS
- Root/sudo access on both machines
- Basic command line knowledge
## Part 1: Initial Setup
### On Both Machines
1. First, install Tailscale if you haven't already:
- On Unraid: Install from Community Applications
- On VPS: Follow installation guide at [Tailscale's website](https://tailscale.com/download)
2. Log into Tailscale on both machines:
```bash
tailscale up
```
3. Note down the Tailscale IPs:
```bash
tailscale ip -4
```
Save both IPs - you'll need them later.
## Part 2: Unraid Configuration
### Step 1: Create the Configuration Script
1. SSH into your Unraid server or use the terminal from the web interface.
2. Create a new directory for our scripts:
```bash
mkdir -p /boot/custom/scripts
cd /boot/custom/scripts
```
3. Create the configuration script:
```bash
nano unraid-config.sh
```
4. Copy the Unraid script from above into this file.
### Step 2: Configure the Script
1. Modify these variables in the script:
```bash
VPS_IP="your.vps.ip.address" Use the public IP address of your VPS (not the Tailscale IP)
GAME_SUBNET="172.16.0.0/24" # Adjust if your subnet is different [Use the subnet where your game server containers are running in Unraid (typically your Docker network subnet, which you can find in Unraid's Docker settings)]
```
2. Make the script executable:
```bash
chmod +x unraid-config.sh
```
### Step 3: Run the Configuration
1. Execute the script:
```bash
./unraid-config.sh
```
2. Watch for any error messages in green or red text.
### Step 4: Make Configuration Persistent
1. Create a startup script:
```bash
nano /boot/config/go
```
2. Add this line:
```bash
/boot/custom/scripts/unraid-config.sh
```
3. Make it executable:
```bash
chmod +x /boot/config/go
```
## Part 3: VPS Configuration
### Step 1: Initial VPS Setup
1. SSH into your VPS:
```bash
ssh username@your.vps.ip
```
2. Create a directory for the script:
```bash
mkdir ~/scripts
cd ~/scripts
```
### Step 2: Create the Configuration Script
1. Create the script file:
```bash
nano vps-config.sh
```
2. Copy the VPS script from above into this file.
### Step 3: Configure the Script
1. Modify these variables:
```bash
UNRAID_TAILSCALE_IP="your.unraid.tailscale.ip"
WAN_INTERFACE="eth0" # Change if your interface is different
```
For these variables:
`UNRAID_TAILSCALE_IP` = Use your Unraid's Tailscale IP (get it by running `tailscale ip -4` on Unraid)
`WAN_INTERFACE` = This is your VPS's main network interface, usually `eth0` (verify with `ip a` on VPS)
Example:
```bash
UNRAID_TAILSCALE_IP="100.x.y.z" # Your Unraid's Tailscale IP
WAN_INTERFACE="eth0" # Usually eth0 on most VPS providers
```
To quickly get your Unraid's Tailscale IP, SSH into Unraid and run:
```bash
tailscale ip -4
```
2. Make the script executable:
```bash
chmod +x vps-config.sh
```
### Step 4: Run the Configuration
1. Execute the script:
```bash
sudo ./vps-config.sh
```
2. Check for any error messages.
## Part 4: Verification and Testing
### Step 1: Check Connectivity
1. From your Unraid server, ping the VPS through Tailscale:
```bash
ping your.vps.tailscale.ip
```
2. From the VPS, ping your Unraid server:
```bash
ping your.unraid.tailscale.ip
```
### Step 2: Test Game Server Ports
1. Check if the ports are open:
```bash
# On VPS
sudo netstat -tulpn | grep LISTEN
```
2. Test UDP ports (8766, 8767, 16261, 19132):
```bash
# From another machine
nc -uvz your.vps.ip 8766
```
3. Test TCP port ranges (16262, 27015-27050, 25500-25600):
```bash
nc -vz your.vps.ip 27015
```
## Common Issues and Troubleshooting
### Issue 1: Ports Not Forwarding
- Check iptables rules:
```bash
sudo iptables -L -n -v
sudo iptables -t nat -L -n -v
```
- Verify IP forwarding is enabled:
```bash
cat /proc/sys/net/ipv4/ip_forward
```
### Issue 2: Tailscale Connectivity
- Check Tailscale status:
```bash
tailscale status
```
- Verify routes:
```bash
ip route show
```
### Issue 3: Game Server Can't Connect
- Check server logs
- Verify firewall rules
- Ensure correct IP forwarding
- Check Tailscale ACLs
## Maintenance
### Regular Checks
1. Monitor system logs:
```bash
journalctl -f
```
2. Check iptables rules periodically:
```bash
sudo iptables-save > rules-backup.txt
```
3. Keep Tailscale updated on both machines.
## Security Considerations
1. Keep SSH ports secured and use key-based authentication
2. Regularly update both Unraid and VPS systems
3. Monitor traffic patterns for unusual activity
4. Keep backups of your configuration files
5. Use strong passwords for all services
## Conclusion
Your game server routing setup should now be complete and working. This configuration provides:
- Secure routing through Tailscale
- Proper traffic separation
- Optimized game server connectivity
- Persistent configuration across reboots
Remember to test thoroughly before deploying game servers, and always keep backups of your configurations.