OpenWrt - Setup

Posted on October 2, 2012
Tags: hackhard

1 Overview

we just use the openwrt to wireless connect to the router as a dhcp client via WAN then share that internet to the LAN.
LAN must have a different IP subnet from WAN meaning WAN will connect as 192.168.1.51 but LAN must be 192.168.2.XX BUT we can use this configuration for temporary internet access on the router.

2 Setup from commandline

  1. hold button to reset router
  2. use ethernet cable to connect router to laptop
  3. ssh to root@192.168.1.1

2.1 change static ip

vi /etc/config/network

config interface 'lan'
        option type 'mac80211'
        option hwmode '11g'
        option proto 'static'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option ipaddr '192.168.1.51'
        option gateway '192.168.1.0'
        list dns '192.168.1.1'
        option delegate '0'
service network reload

2.2 Temporarily add internet

The mesh option wont give you internet since you still need to install a package then REBOOT.
So how do we get internet?

  1. Change the static IP of your LAN group interface to 192.168.2.XX along with the gateway.
  • LAN 192.168.2.XX must be different subnet from WAN 192.168.1.XX
  • Since the WAN is connecting to the internet router via 192.168.1.1, WAN must take the 192.168.1.XX static IP address.
  1. Network >> Interfaces >> Radio1 >> Scan
  • Join Network
  • Choose LAN

Then click Save, a new form pre-filled will pop up, DO NOT MODIFY IT, just click Save again.
Then ssh into your openwrt, and run the commands below.

2.2.1 with terminal

vi /etc/config/network

config interface 'lan'
  #some options here...
  option ipaddr '192.168.2.1' #we changed from 192.168.1.1 to 192.168.2.1
  option gateway '192.168.2.0' #we changed from 192.168.1.0 to 192.168.2.0
vi /etc/config/wireless


config wifi-device 'radio0'
  #some default options...
  #option disabled '0' #MAKE SURE TO COMMENT/REMOVE THE LINE OUT, DONT JUST CHANGE VALUE
  option country 'US' #IMPORTANT TO ADD THIS LINE!

config wifi-iface 'default_radio0'
  option device 'radio0'
  option network 'wan'
  option mode 'sta'
  option encryption 'psk2'
  option key 'yourwifipassword'
  option ssid 'yourwifiname'
wifi
ip addr

# 1: lo : <LOOPBACK, UP, LOWER_UP> mtu 65536 ...
# 2: eth0: <BROADCAST, MULTICAST, UP_LOWERUP> mtu 1500 ...
# 3: eth1: ...
# 15: phy1-ap0: ...
# 16: phy0-sta0: ... #<-- THIS IS THE NAME YOU NEED FOR THE NEXT STEP, IT ENDS WITH 'sta'
# 17: br-lan: ...
vi /etc/config/network

config interface 'wan'
  option device 'phy0-sta0' #this is the name you got from the last step
  option proto 'dhcp'
  option type 'bridge'

2.3 Getting back luci

https://openwrt.org/docs/guide-user/luci/luci.essentials

opkg update --no-check-certificate
opkg install luci

3 Setup emergency AP

In your wireless >> “OpenWrt5Ghz”, select Network: “wan” (this binds the wifi to the network).

4 Custom image

https://firmware-selector.openwrt.org/?version=23.05.2&target=ath79%2Fgeneric&id=tplink_archer-c7-v2

after building click the sysupgrade option to download the firmware

Below are Installed Packages you need to add in addition to whatever already is default

  luci-ssl luci openvpn-openssl luci-app-openvpn kmod-usb-net-rndis

4.1 Script to run on first boot (uci-defaults)

4.1.1 Option 1 - simple

The below two lines for the simplest openwrt setup

#this turns on both radios 2.5ghz and 5ghz
uci set wireless.@wifi-device[0].disabled="0"
uci set wireless.@wifi-device[1].disabled="0"
uci set wireless.@wifi-device[0].country="US"
uci set wireless.@wifi-device[1].country="US"

use below to change lan ip to 192.168.1.0/24 to 192.168.2.0/24 typically useful if you want to use wan as a client that connects to a prexisting wifi with internet

uci set wireless.@wifi-device[0].disabled="0"
uci set wireless.@wifi-device[1].disabled="0"
uci set wireless.@wifi-device[0].country="US"
uci set wireless.@wifi-device[1].country="US"

uci set wireless.@wifi-iface[0].ssid="OpenWrt98e1"
uci set wireless.@wifi-iface[0].key="changemeplox"
uci set wireless.@wifi-iface[0].encryption="psk2"

uci set wireless.@wifi-iface[1].ssid="OpenWrtfr34"
uci set wireless.@wifi-iface[1].key="changemeplox"
uci set wireless.@wifi-iface[1].encryption="psk2"

uci commit wireless

uci set network.lan=interface
uci set network.lan.proto='static'
uci set network.lan.ipaddr='192.168.2.1'
uci set network.lan.netmask='255.255.255.0'
uci set network.lan.gateway='192.168.2.0'
uci set network.lan.device='br-lan'
uci commit network

4.1.2 Option 2

#this creates the network interface 
uci set network.altlan=interface
uci set network.altlan.proto='static'
uci set network.altlan.ipaddr='192.168.3.54'
uci set network.altlan.netmask='255.255.255.0'
uci set network.altlan.gateway='192.168.3.0'
uci set network.altlan.device='wlan0'
uci commit network
#this attaches a dhcp server to the network interface above
uci set dhcp.altlan=dhcp
uci set dhcp.altlan.interface='altlan'
uci set dhcp.altlan.start='4'
uci set dhcp.altlan.limit='200'
uci set dhcp.altlan.leasetime='12h'
uci set dhcp.altlan.dhcpv4='server'
uci set dhcp.altlan.ra='server'
uci set dhcp.altlan.ra_slaac='1'
uci set dhcp.altlan.ra_flags="managed-config other-config"
uci commit dhcp

#this turns on both radios 2.5ghz and 5ghz
uci set wireless.@wifi-device[0].disabled="0"
uci set wireless.@wifi-device[1].disabled="0"

#this creates a WiFi SSID and attaches to the network interface
uci set wireless.openwrt192168354="wifi-iface"
uci set wireless.openwrt192168354.mode="ap"
uci set wireless.openwrt192168354.ssid="openwrt192168354"
uci set wireless.openwrt192168354.key="changemeplox"
uci set wireless.openwrt192168354.encryption="psk2"
uci set wireless.openwrt192168354.device='radio0'
uci set wireless.openwrt192168354.network='altlan'
uci commit wireless

Add the below script for turning on 192.168.1.54, (you can use both the above and below script)

uci set network.lan.ipaddr="192.168.1.54"
uci commit network
uci set wireless.@wifi-device[0].disabled="0"
uci set wireless.@wifi-iface[0].disabled="0"
uci set wireless.@wifi-iface[0].ssid="OpenWrt"
uci set wireless.@wifi-iface[0].key="changemeplox"
uci set wireless.@wifi-iface[0].encryption="psk2"
uci commit wireless

Below is for diagnostic purposes and helping to build your own uci set .. commands via extrapolation

uci -N show network.lan
# network.lan=interface
# network.lan.device='br-lan'
# network.lan.proto='static'
# network.lan.netmask='255.255.255.0'
# network.lan.ip6assign='60'
# network.lan.ipaddr='192.168.1.51'
# network.lan.gateway='192.168.1.1'
# network.lan.dns='192.168.1.1'
# network.lan.delegate='0'
uci -N show dhcp.@dhcp[0]
# dhcp.lan=dhcp
# dhcp.lan.interface='lan'
# dhcp.lan.limit='150'
# dhcp.lan.leasetime='12h'
# dhcp.lan.dhcpv4='server'
# dhcp.lan.dhcpv6='server'
# dhcp.lan.ra='server'
# dhcp.lan.ra_slaac='1'
# dhcp.lan.ra_flags='managed-config' 'other-config'
# dhcp.lan.start='4'
uci -N show dhcp.@dhcp[1]
# dhcp.wan=dhcp
# dhcp.wan.interface='wan'
# dhcp.wan.ignore='1'

uci -N show wireless.@wifi-device[0]
# wireless.radio0=wifi-device
# wireless.radio0.type='mac80211'
# wireless.radio0.path='platform/soc/a000000.wifi'
# wireless.radio0.channel='4'
# wireless.radio0.hwmode='11g'
# wireless.radio0.band='2g'
# wireless.radio0.cell_density='0'
# wireless.radio0.htmode='HT40'
# wireless.radio0.country='US'

uci show wireless.@wifi-iface[1]
# wireless.default_radio1=wifi-iface
# wireless.default_radio1.device='radio1'
# wireless.default_radio1.network='lan'
# wireless.default_radio1.mode='ap'
# wireless.default_radio1.ssid='OpenWrt'
# wireless.default_radio1.encryption='none'

uci -N show wireless.@wifi-iface[0]
# wireless.wifinet3=wifi-iface
# wireless.wifinet3.device='radio0'
# wireless.wifinet3.mode='mesh'
# wireless.wifinet3.mesh_id='test'
# wireless.wifinet3.mesh_fwding='1'
# wireless.wifinet3.mesh_rssi_threshold='0'
# wireless.wifinet3.network='lan'
# wireless.wifinet3.key='blehblehblehbleh'
# wireless.wifinet3.encryption='sae'