Detailed Explanation of Open-Source Router Operating System OpenWrt
OpenWrt is a Linux-based operating system primarily used for embedded devices such as routers. Unlike traditional router firmware, it provides a fully writable file system with package management. This allows users to customize their router's functionality by installing specific application packages, and frees users from vendor restrictions. OpenWrt also typically supports devices longer than original firmware and provides a large, helpful community.
Here are some main aspects of OpenWrt:
Installation and Basic Configuration¶
- Hardware Requirements: When choosing a new router for OpenWrt, it is recommended to look for devices with "more than 8MB of flash memory and more than 64MB of RAM" to ensure full functionality of the operating system and GUI.
- Firmware Selection: The correct firmware file must be selected for the router's specific model and hardware version (for example, "WR841N" hardware version "8"), as using the wrong file may "brick" the device. The correct firmware file will end with "factory.bin".
- Flashing Process: Flashing is done through the router's web interface, users should connect using an Ethernet cable, and must go to "System Tools" -> "Firmware Upgrade" page.
- Initial Access: After installation, access OpenWrt through the web interface LuCI via the router's IP address (usually 192.168.1.1).
- Security Hardening: The first step after installation should be setting a root password to improve security, and setting the device as a Wi-Fi access point.
- Wireless Settings: By default, wireless is disabled and must be manually enabled in the LuCI interface for wireless access point functionality to work properly.
- Basic Network Configuration: OpenWrt allows configuration of DHCP leases, network interfaces, and port forwarding settings.
- Changing LAN IP Address: The tutorial demonstrates how to change the router's default LAN IP address (for example, changing to 192.168.9.1). However, DHCP settings must be manually edited to prevent conflicts.
Advanced Configuration and Features¶
- Wireless Client Mode (AP Client): OpenWrt can be configured as a wireless client to connect to an existing network, then redistribute that connection to devices on the LAN, this feature is useful for extending existing network coverage.
- System Logs: OpenWrt stores comprehensive logs that can provide real-time information about network operation, such as which devices have received IP addresses and regular activity. These logs provide a good overview of the current network configuration.
- LuCI Applications: The tutorial introduces the installation of luci-app-statistics, which provides "good views of router historical data charts", such as CPU, RAM, ping times, and system uptime.
- Configuration Files: OpenWrt's configuration files use section and option/value structures, and are located in /etc/config/.
- The general syntax is config
[" "] for sections, option " " for options. These files are parsed by shell.
- The general syntax is config
- Network Configuration: Network interface configurations are stored in /etc/config/network. These can be set to "none", "static", "dhcp", or "pppoe" protocols. When using static method, ipaddr and netmask options are mandatory.
- Switch Configuration: OpenWrt supports switch configuration for setting up VLANs.
- Switch configuration is stored in /etc/config/network.
- On Broadcom hardware, the section name needs to be eth0.
- Each VLAN needs to have name vlan
, where n is the VLAN number. These values can include: * (for setting default VLAN), u (untagged) and t (tagged). CPU port on Broadcom hardware is port 5.
- Wireless Configuration: WiFi settings are configured in /etc/config/wireless, each wireless driver has a configuration file in /lib/wifi/
.sh. - Some options you can set for wifi devices include: distance, mode, diversity, rxantenna, txantenna, txpower.
- Options for wifi interfaces include: network, device, mode, ssid, and bssid.
- Supported modes include: access point, client, ad-hoc, monitor, and WDS point-to-point.
- 802.1x Authentication: OpenWrt supports 802.1x authentication (client and access point configuration), with EAP types of TLS, TTLS, or PEAP.
Development and Customization¶
- Build System: The OpenWrt build system enables developers to create custom firmware images using a cross-compilation process.
- Source Code: OpenWrt is available through Subversion repository. Main directories include tools, toolchain, package, and target.
- Building Images: The command make menuconfig is used to configure the build process, including selecting platform, toolchain, and required packages.
- Packages: Almost everything in OpenWrt firmware is a package (.ipk). These packages can be added to firmware to provide new features, or removed to save space.
- Build Environment: OpenWrt provides a method to build images for multiple configurations using the command ./scripts/env.
- Creating Packages: Create a package by creating a makefile that will automatically appear in the menu the next time make menuconfig is run.
- Some options you can configure are: PKG_NAME, PKG_VERSION, PKG_RELEASE, PKG_SOURCE, PKG_SOURCE_URL, PKG_MD5SUM, PKG_CAT, PKG_BUILD_DIR.
- You can also add information such as DEPENDS, BUILDONLY Package/
/conffiles. - You also need to define Build/Compile, Build/Install, and Package/
/install options.
- Creating Kernel Module Packages: Packages can be created for modules provided with the mainline kernel as well as external kernel modules by defining KernelPackage sections.
- Configurable options include TITLE, DESCRIPTION, SUBMENU, KCONFIG, FILES, and AUTOLOAD.
- Troubleshooting: The command TOPDIR=$PWD make -C package/
DUMP=1 V=99 can help diagnose if a package is correctly displayed in menuconfig. You can also use commands like make package/ /clean V=99 or make package/ /install V=99 to clean or install specific packages. - Adding Platform Support: Many devices run Linux operating systems even if firmware is not open to consumers. OpenWrt can be ported to these devices by discovering if they are already running Linux and looking for developer toolkits.
- Useful techniques for checking this include: OS fingerprinting, port scanning, analyzing binary firmware images, checking flash amounts, and inserting serial ports.
- After finding the developer toolkit, kernel patches and binary drivers can be adjusted for OpenWrt, and new flash mapping drivers and firmware build tools can be developed.
- Reporting Bugs: OpenWrt uses the Trac system for bug reporting.
- Reporters can open tickets for bugs, new packages, or requested features.
- Developers can close, accept, and fix tickets.
Other Information¶
- SSH: Command-line access to OpenWrt is usually done using SSH.
- Text Editors: vi and vim can be used to edit text files in the command line. Common shortcuts can be found in the FAQ.
- Windows Management Tools: Tools like cmder, SmarTTY, PuTTY, and WinSCP can be used to manage OpenWrt from Windows.
- WAN and WAN6 Interfaces: WAN and WAN6 interfaces are used for IPv4 and IPv6 connections on the upstream side of the network respectively. LAN interfaces handle IPv4 and IPv6 on the downstream side, eliminating the need for separate LAN6 interfaces.
- Hotplug: OpenWrt can be dynamically configured based on events through hotplug, hotplug is configured using scripts.
- Init Scripts: All init scripts need to be installed as /etc/init.d/name and use /etc/rc.common as a wrapper. These scripts are used to start system services.
- Network Scripts: Network scripts can be accessed by including /lib/network. These scripts help manage interfaces and have functions such as find_config and setup_interface.

