【OpenWrt】维护

Posted by 西维蜀黍 on 2022-03-19, Last Modified on 2023-05-02

常用软件

$ opkg install vim curl git htop wget iperf3 tcpdump fdisk unzip git make gcc tar diffutils grep wget python3 bind-dig scapy

Golang

// TODO

Python

Refer to https://openwrt.org/docs/guide-user/services/python

Python 2.7

We are going to use opkg to install Python 2.7. Enter the following command to update your package manager:

opkg update

Now you can install python-light:

opkg install python-light

or the full version of python:

opkg install python

Python3

The light and full version of Python3 are also available via opkg. To install Python3, start by updating your package manager:

opkg update

Now you can install python3-light:

opkg install python3-light

or the full version of python3:

opkg install python3

安全性

Refer to https://swsmile.info/post/openWrt-security/

设置

市区

问题

无法 opkg install ...

try --force-depends or --nodeps

操作

查看OpenWrt版本

$ cat /etc/openwrt_release

更新固件

mtd

  • SSH to the device to flash OpenWrt
    • Open a SSH connection to root@192.168.31.1
    • Login using credentials provided by the SSH download website
  • Flash the latest firmware
    • Get the latest firmware, eg: # cd /tmp; wget <link to firmware-image as shown above>
    • Check the MTD layout: # cat /proc/mtd
    • If you find a line “OS1” go ahead with flashing: # mtd -r write <firmware-image you downloaded> OS1
  • After flashing is complete, the router will reboot. When finished you can login using telnet or web-interface on a LAN-connected client to host 192.168.1.1. User: root, no password.
  • SSH will be enabled after you set a password (using passwd or LuCI web interface), telnet will be disabled.

sysupgrade

$ opkg install curl
$ cd /tmp
$ curl -LO https://downloads.openwrt.org/snapshots/targets/ramips/mt7621/openwrt-ramips-mt7621-xiaomi_redmi-router-ac2100-squashfs-sysupgrade.bin
$ sysupgrade -F openwrt-ramips-mt7621-xiaomi_redmi-router-ac2100-squashfs-sysupgrade.bin

将OpenWrt设置为交换机(Switch)

Approach 1 - 不使用 WAN 口

将OpenWrt的 LAN 口的 IP 设置为静态IP(或 DHCP client):

当然,也可以直接修改配置文件(之后需要重启):

$ cat /etc/config/network

config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option packet_steering '1'
	option ula_prefix '...'

config interface 'lan'
	option type 'bridge'
	option ifname 'lan1 lan2 lan3'
	option proto 'static'
	option netmask '255.255.255.0'
	option ip6assign '60'
	option ipaddr '192.168.2.124'

config interface 'wan'
	option ifname 'wan'
	option proto 'dhcp'

config interface 'wan6'
	option ifname 'wan'
	option proto 'dhcpv6'
	
$ /etc/init.d/network restart

将外网网线插入任何一个LAN口。

关闭DHCP:

Approach 2 - 不使用 wan 口

Reference

Switch