NeuroAgent

Setting up OpenWrt in Proxmox on Raspberry Pi 4

Complete guide to setting up internet access with OpenWrt in a Proxmox virtual machine on Raspberry Pi 4. Learn how to properly configure network bridging and traffic forwarding.

Question

Is it possible to set up internet access with OpenWrt running in a Proxmox virtual machine on a Raspberry Pi 4?

Details: I have one computer connected via LAN to a Raspberry Pi 4 with OpenWrt installed. From this Pi, I get internet via Wi-Fi. If I install Proxmox on the Raspberry Pi 4 and then create a virtual machine with OpenWrt inside it, will I be able to configure network forwarding to provide internet access from the main computer?

NeuroAgent

Yes, this is quite possible to set up. You can install Proxmox on a Raspberry Pi 4, create a virtual machine with OpenWrt inside it, and properly configure the network bridge to provide internet access from the main computer through your Wi-Fi network. For this, you will need to properly configure network interfaces in Proxmox, set up the virtual bridge, and specify the correct network settings in the OpenWrt VM.

Contents

Setting up Proxmox on Raspberry Pi 4

First, you need to install Proxmox VE on your Raspberry Pi 4. The installation process includes several important steps:

  1. System Preparation: Make sure you have the latest version of Raspberry Pi OS (64-bit for better performance) installed
  2. Proxmox Installation: Follow the official instructions for installing Proxmox on ARM architecture
  3. System Update: After installation, update all packages to the latest versions

Important: Proxmox on Raspberry Pi 4 requires sufficient RAM (minimum 4GB recommended, 8GB better) and an SSD drive for stable operation.

After installing Proxmox, you will need to configure the network interfaces. It’s important to correctly identify which interface is physical (e.g., eth0 for LAN) and which will be used for Proxmox management.

Creating an OpenWrt Virtual Machine

Creating an OpenWrt virtual machine in Proxmox includes the following steps:

  1. Download OpenWrt Image: Download the latest OpenWrt image for x86_64 architecture
  2. Create VM: In the Proxmox web interface, select “Create VM”
  3. Configure Parameters:
    • Type: QEMU/KVM Virtual Machine
    • OS: Linux 5.x - 2.6 (64-bit)
    • RAM: 512MB-1GB (depending on your needs)
    • CPU: 1-2 cores
    • Disk: 4-8GB
    • Network: Configure the first network adapter
bash
# Example command for creating VM via command line
qm create 100 --memory 512 --cores 2 --net0 virtio,bridge=vmbr0
qm set 100 --scsi0 local-lvm:vm-100-disk-0,4G
qm importdisk 100 /path/to/openwrt.img local-lvm

Network Configuration in Proxmox

Proper network configuration is a key aspect for providing internet access. Here are the main steps:

Setting up the Network Bridge

Open the network configuration file:

bash
nano /etc/network/interfaces

Add the following configuration for the bridge:

auto vmbr0
iface vmbr0 inet static
        address 192.168.1.1/24
        gateway 192.168.1.254
        bridge-ports eth0
        bridge-stp off
        bridge-fd 0

where:

  • eth0 is your physical network interface
  • 192.168.1.1/24 is the bridge IP address
  • 192.168.1.254 is your main router/Gateway

Setting up NAT for Internet Access

If your main computer gets internet via Wi-Fi, you need to configure NAT:

bash
# Install iptables
apt install iptables

# Configure NAT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i vmbr0 -o wlan0 -j ACCEPT
iptables -A FORWARD -i wlan0 -o vmbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT

# Save rules
iptables-save > /etc/iptables/rules.v4

OpenWrt VM Configuration

After creating the VM and booting OpenWrt, you need to configure the network inside the virtual machine:

  1. Connect to the VM via console or SSH
  2. Open the network configuration file:
bash
nano /etc/config/network
  1. Configure interfaces:
config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option type 'bridge'
        option ifname 'br-lan'
        option proto 'static'
        option ipaddr '192.168.100.1'
        option netmask '255.255.255.0'
        option gateway '192.168.1.1'
        option dns '8.8.8.8 8.8.4.4'
  1. Restart the network:
bash
/etc/init.d/network restart

Internet Forwarding from the Main Computer

To provide internet access from your main computer through your configuration:

  1. Configure the main computer to use a static IP address in the same subnet as the OpenWrt VM
  2. Specify the gateway as the OpenWrt VM IP address (192.168.100.1)
  3. Configure DNS servers (you can use the same ones as in OpenWrt)

Example configuration on the main computer (Linux):

bash
ip addr add 192.168.100.100/24 dev eth0
ip route add default via 192.168.100.1
echo "nameserver 192.168.100.1" > /etc/resolv.conf

Additional Settings

If you need a more complex scenario with routing between networks:

bash
# Enable packet forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Configure routing in OpenWrt
uci add dhcp host
uci set dhcp.@host[-1].ip='192.168.100.100'
uci set dhcp.@host[-1].mac='MAC_OF_YOUR_COMPUTER'
uci set dhcp.@host[-1].name='main-pc'
uci commit dhcp

Testing and Troubleshooting

Connection Testing

  1. Test OpenWrt VM availability from the main computer:
bash
ping 192.168.100.1
  1. Test internet access from the OpenWrt VM:
bash
ping 8.8.8.8
curl google.com
  1. Test internet access from the main computer:
bash
ping 8.8.8.8
curl google.com

Common Issues

  1. No internet access:

    • Check NAT settings in Proxmox
    • Make sure forwarding is enabled: cat /proc/sys/net/ipv4/ip_forward
    • Check routing: ip route show
  2. No connection to OpenWrt VM:

    • Check subnet IP addresses
    • Make sure the vmbr0 bridge is properly configured
    • Check firewall in Proxmox and OpenWrt
  3. Performance issues:

    • Increase allocated RAM for the VM
    • Use an SSD drive
    • Optimize Wi-Fi settings

Tip: For network monitoring, use iftop and nethogs to track traffic and identify bottlenecks.

Sources

  1. Proxmox VE Documentation - Network Configuration
  2. OpenWrt Documentation - Network Configuration
  3. Raspberry Pi 4 Proxmox Installation Guide
  4. Linux IP Forwarding and NAT Configuration
  5. Virtual Bridging with Proxmox

Conclusion

Setting up internet access with OpenWrt running in a Proxmox virtual machine on a Raspberry Pi 4 is quite feasible and provides flexible network management capabilities. Key points for successful setup include:

  • Proper network bridge configuration in Proxmox
  • Setting up NAT for traffic forwarding through Wi-Fi
  • Correct network configuration inside the OpenWrt VM
  • Thorough testing of all network connections

To get started, install Proxmox on your Raspberry Pi 4, create a VM with OpenWrt, and gradually configure network parameters, testing each stage. If problems arise, use diagnostic tools to identify and resolve issues.

This configuration will allow you to use your Raspberry Pi 4 as a flexible network node with virtualization capabilities, opening up additional opportunities for experimenting and developing your networking skills.