LoginSignup
1
1

OpenWrt システム初期設定

Last updated at Posted at 2023-08-11

:warning:Japanese notation

こちらに統合しました

はじめに

初心者対応構成

  • スクリプトでの自動設定
  • UCIとLuCi及びWinSCPにて比較しながら作業がおススメ

PowerShellSSHアクセス

ssh root@192.168.1.1
ssh root@192.168.1.1のショートカット作成(デスクトップ)
powershell
$DESKTOP = ([Environment]::GetFolderPath("Desktop") + "\192.168.1.1.lnk")
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$DESKTOP")
$Shortcut.TargetPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.Arguments = '-windowstyle hidden -ExecutionPolicy RemoteSigned "Start-Process ssh root@192.168.1.1"'
$Shortcut.IconLocation = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe,0"
$Shortcut.WorkingDirectory = "."
$Shortcut.Save()

  • 強制的に貼り付け
  • yes

SSHログイン出来ない場合:exclamation:

known_hostsクリア

  • C:\Users\yourusername\.ssh\known_hosts ※Windows隠しファイル
powershell
Clear-Content .ssh\known_hosts -Force


OpenSSHのインストール
※Windows 10 Fall Creators Update(1709)以降標準搭載

  • 機能の確認
powershell
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

  • 機能のインストール
powershell
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0


最初にやる事

デバイス情報確認

ディストリビューション
cat /etc/openwrt_release

cat /etc/openwrt_version

cat /etc/os-release

uname -a

uname -r


システム情報

システム情報

CPU

cat /proc/cpuinfo

MTD

cat /proc/mtd

MODULES

cat /proc/modules

devices

cat /proc/devices

free

free

meminfo

cat /proc/meminfo

iomem

cat /proc/iomem

ps

ps

ifconfig

ifconfig

dmesg

dmesg

プロセス数の上限

sysctl kern.maxproc kern.maxprocperuid 

sysctl kernel.threads-max


LuCi 確認

※リリースビルドのみ

ROOTパスワード

passwd

Changing password for root
New password:

passwd:入力モード
任意のパスワード

Retype password:

passwd:入力モード
再入力

passwd: password for root changed by root

exit

SSHアクセスインターフェース

※WAN側からアクセスする場合不要

uci set dropbear.@dropbear[0].Interface='lan'
uci commit dropbear

設定

config(設定ファイル)は /etc/config/以下に格納
※以下設定は、新規インストール用

システム

# 設定値
HOSTNAME='openwrt' # ルーター名
DESCRIPTION=`cat /etc/openwrt_version` # 説明
NOTES=`date` # 備考
# システム
uci set system.@system[0]=system
uci set system.@system[0].hostname=${HOSTNAME}
uci set system.@system[0].description="${DESCRIPTION}"
uci set system.@system[0].timezone='JST-9'
uci set system.@system[0].zonename='Asia/Tokyo'
uci set system.@system[0].conloglevel='6' # ログ出力レベル:注意
uci set system.@system[0].cronloglevel='9' # Cronログレベル:警告
# NTPサーバー
uci set system.ntp.enable_server='1'
uci set system.ntp.use_dhcp='0'
uci set system.ntp.interface='lan'
uci delete system.ntp.server
uci add_list system.ntp.server='0.jp.pool.ntp.org'
uci add_list system.ntp.server='1.jp.pool.ntp.org'
uci add_list system.ntp.server='2.jp.pool.ntp.org' 
uci add_list system.ntp.server='3.jp.pool.ntp.org'
uci commit system
/etc/init.d/system reload
/etc/init.d/sysntpd restart
# note
uci set system.@system[0].notes="${NOTES}"
uci commit system
/etc/init.d/system reload

LED

利用可能LED確認

ls /sys/class/leds/ 

参考

# POWER:WHITE:OFF
uci add system led
uci set system.@led[-1].name='WHITE-OFF'
uci set system.@led[-1].sysfs='white:power'
uci set system.@led[-1].trigger='none'
uci set system.@led[-1].default='0'
# POWER:RED:ON
uci add system led
uci set system.@led[-1].name='POWER-RED'
uci set system.@led[-1].sysfs='red:powe
r'
uci set system.@led[-1].trigger='default-on'
# set
uci commit system
/etc/init.d/led restart

オフロード

  • ソフトウェア フローオフロード
uci set firewall.@defaults[0].flow_offloading='1'
uci commit firewall
/etc/init.d/firewall restart

  • ハードウェア フローオフロード
    ※ハードウェア NAT サポートが必要です。 mt7621 のみにおいて実装されています。
    ※MT7986B / WSR-600AX8 において有効
    ※MT7986A / BPI-R3 において有効
uci set firewall.@defaults[0].flow_offloading_hw='1'
uci commit firewall
/etc/init.d/firewall restart

パケットステアリング

uci set network.globals.packet_steering='1'
uci commit network

カスタムDNS

# delete
uci -q delete dhcp.lan.dhcp_option
uci -q delete dhcp.lan.dns
# IPV4
uci add_list dhcp.lan.dhcp_option="6,1.1.1.1,8.8.8.8"
uci add_list dhcp.lan.dhcp_option="6,1.0.0.1,8.8.4.4"
# IPV6
uci add_list dhcp.lan.dns="2606:4700:4700::1111"
uci add_list dhcp.lan.dns="2001:4860:4860::8888"
uci add_list dhcp.lan.dns="2606:4700:4700::1001"
uci add_list dhcp.lan.dns="2001:4860:4860::8844"
# set
uci commit dhcp
/etc/init.d/dnsmasq restart
/etc/init.d/odhcpd restart

確認

Wi-Fi

※W53、W56はDFSにて起動遅延60秒

設定値

# Aチャンネル
SSID_A='SSID_A'
PASSWORD_A='password'
# Bチャンネル
SSID_B='SSID_B'
PASSWORD_B='password'

設定
※Random Mac AddressはRC2以降
※トライバンドはradio2 default_radio2を追加

# Aチャンネル
uci set wireless.radio0.country='JP'
uci set wireless.radio0.txpower='10'
uci set wireless.radio0.noscan='1'
uci set wireless.radio0.frag='2347'
uci set wireless.radio0.rts='2346'
uci set wireless.default_radio0.encryption='sae-mixed'
uci set wireless.default_radio0.ssid=${SSID_A}
uci set wireless.default_radio0.key=${PASSWORD_A}
uci set wireless.default_radio0.multicast_to_unicast='1'
uci set wireless.default_radio0.isolate='1'
# uci set wireless.default_radio0.macaddr='random' # Random Mac Address
# uci set wireless.default_radio0.wpa_disable_eapol_key_retries='1'
# Bチャンネル
uci set wireless.radio1.country='JP'
uci set wireless.radio1.txpower='10'
uci set wireless.radio1.noscan='1'
uci set wireless.radio1.frag='2347'
uci set wireless.radio1.rts='2346'
uci set wireless.default_radio1.encryption='sae-mixed'
uci set wireless.default_radio1.ssid=${SSID_B}
uci set wireless.default_radio1.key=${PASSWORD_B}
uci set wireless.default_radio1.multicast_to_unicast='1'
uci set wireless.default_radio1.isolate='1'
# uci set wireless.default_radio1.macaddr='random' # Random Mac Address
# uci set wireless.default_radio1.wpa_disable_eapol_key_retries='1'
# set
uci delete wireless.radio0.disabled
uci delete wireless.radio1.disabled
uci commit wireless
/etc/init.d/network restart

  • Target Wake Time (TWT)
    ※Only WiFi6 (ax)
    参考:Linux Hostpad
    • he_twt_required: Whether TWT is required
      0 = not required (default)
      1 = required
      he_twt_required=0 or 1
    • he_twt_responder: Whether TWT (HE) responder is enabled
      0 = disabled
      1 = enabled if supported by the driver (default)
      he_twt_responder=0 or 1
ON
sed -i -e "s/he_twt_required:0/he_twt_required:1/g" /lib/netifd/wireless/mac80211.sh
uci add_list wireless.radio0.hostapd_options='he_twt_responder=1'
uci add_list wireless.radio1.hostapd_options='he_twt_responder=1'
uci commit wireless

OFF
sed -i -e "s/he_twt_required:1/he_twt_required:0/g" /lib/netifd/wireless/mac80211.sh
uci del_list wireless.radio0.hostapd_options='he_twt_responder=0'
uci del_list wireless.radio1.hostapd_options='he_twt_responder=0'
uci commit wireless

確認

他設定

バンドステアリング

設定値

BANDSTEERING='バンドステアリング' # 2Gと5GのSSIDを統一
PASSWORD='password' # 2Gと5Gのパスワードを統一

設定

# opkg update
opkg install dawn
opkg install luci-app-dawn
uci set dawn.@network[0].broadcast_ip='192.168.1.255'
uci set dawn.@metric[0].kicking=1
# 5G
uci set wireless.default_radio0.ssid=${BANDSTEERING}
uci set wireless.default_radio0.key=${PASSWORD}
uci set wireless.default_radio0.ieee80211r '1'
uci set wireless.default_radio0.ieee80211k='1'
uci set wireless.default_radio0.ieee80211v='1'
uci set wireless.default_radio0.ft_over_ds='1'
# 2G
uci set wireless.default_radio1.ssid=${BANDSTEERING}
uci set wireless.default_radio1.key=${PASSWORD}
uci set wireless.default_radio1.ieee80211r '1'
uci set wireless.default_radio1.ieee80211k='1'
uci set wireless.default_radio1.ieee80211v='1'
uci set wireless.default_radio1.ft_over_ds='1'
# set
uci commit dawn
uci commit wireless
/etc/init.d/dawn restart
/etc/init.d/network restart
# reboot

wpad(full)は入らないので書かない事
option bss_transition '1'
option wnm_sleep_mode '1'
option time_advertisement '2'
option time_zone 'GMT0'
option rrm_neighbor_report '1'
option rrm_beacon_report '1'

PING宛先

uci set luci.diag.dns='one.one.one.one'
uci set luci.diag.ping='one.one.one.one'
uci set luci.diag.route='one.one.one.one'
uci commit luci
/etc/init.d/rpcd reload

確認

CRON(スケジュール)

参考

# 再起動 06:00
echo "00 06 * * * sleep 70 && touch /etc/banner && reboot" >> /etc/crontabs/root
# WiFi A OFF 00:00
echo "00 00 * * * uci set wireless.default_radio0.disabled=1; uci commit; wifi" >> /etc/crontabs/root
# WiFi A ON 08:00
echo "00 08 * * * uci set wireless.default_radio0.disabled=0; uci commit; wifi" >> /etc/crontabs/root
# LED 夜間 OFF 00:00 ※再起動で設定値復旧
echo "00 00 * * * echo "none" > /sys/class/leds/white:power/trigger" >> /etc/crontabs/root
/etc/init.d/cron restart

参考:CPUパフォーマンスCRONスケジュールその1
CPUパフォーマンスインストール必須
※00:00 ~ 08:00 ローパフォーマンス

# opkg update
# opkg install cpu-perf
uci set cpu-perf.config.enabled=1
uci set cpu-perf.cpu0.scaling_governor='schedutil'
uci set cpu-perf.cpu0.scaling_max_freq='1017600'
uci set cpu-perf.cpu1.scaling_governor='schedutil'
uci set cpu-perf.cpu1.scaling_max_freq='1017600'
uci set cpu-perf.cpu2.scaling_governor='schedutil'
uci set cpu-perf.cpu2.scaling_max_freq='1017600'
uci set cpu-perf.cpu3.scaling_governor='schedutil'
uci set cpu-perf.cpu3.scaling_max_freq='1017600'
uci commit uhttpd
/etc/config/uhttpd reload
uci commit cpu-perf
/etc/init.d/cpu-perf start

# CPU パフォーマンス
echo "00 00 * * * /etc/init.d/cpu-perf start" >> /etc/crontabs/root
echo "00 08 * * * /etc/init.d/cpu-perf stop" >> /etc/crontabs/root

参考:CPUパフォーマンスCRONスケジュールその2
CPUパフォーマンスインストール必須
※00:00 ~ 08:00 ローパフォーマンス

# opkg update
# opkg install cpu-perf
/etc/init.d/cpu-perf start
uci set cpu-perf.config.enabled=1
uci commit cpu-perf
# CPU-PERF 1017600
echo "00 00 * * * uci set cpu-perf.cpu0.scaling_max_freq='1017600'; uci commit; cpu-perf" >> /etc/crontabs/root
echo "00 00 * * * uci set cpu-perf.cpu1.scaling_max_freq='1017600'; uci commit; cpu-perf" >> /etc/crontabs/root
echo "00 00 * * * uci set cpu-perf.cpu2.scaling_max_freq='1017600'; uci commit; cpu-perf" >> /etc/crontabs/root
echo "00 00 * * * uci set cpu-perf.cpu3.scaling_max_freq='1017600'; uci commit; cpu-perf" >> /etc/crontabs/root
echo "00 08 * * * /etc/init.d/cpu-perf reload" >> /etc/crontabs/root
# CPU-PERF 2208000
echo "00 08 * * * uci set cpu-perf.cpu0.scaling_max_freq='2208000'; uci commit; cpu-perf" >> /etc/crontabs/root
echo "00 08 * * * uci set cpu-perf.cpu1.scaling_max_freq='2208000'; uci commit; cpu-perf" >> /etc/crontabs/root
echo "00 08 * * * uci set cpu-perf.cpu2.scaling_max_freq='2208000'; uci commit; cpu-perf" >> /etc/crontabs/root
echo "00 08 * * * uci set cpu-perf.cpu3.scaling_max_freq='2208000'; uci commit; cpu-perf" >> /etc/crontabs/root
echo "00 08 * * * /etc/init.d/cpu-perf reload" >> /etc/crontabs/root

スケジュール確認

crontab -l

他デバイス設定

USB

WAN

選択型インターネット接続自動設定

階層
※それぞれの階層に設定とその復元がある
※一度設定すると、そのバックアップを取るので、復元が出来る仕様

  • OCNバーチャルコネクト
    • ニチバン対策のみ
  • V6プラス・IPv6オプション
    • ニチバン対策のみ
  • トランジックス
  • クロスパス
  • v6 コネクト
  • ひかりone系・他PPPoE
  • アクセスポイント
  • 終了

初期化

ファクトリーリセット(初期化)

# 要注意
firstboot && reboot now

This will erase all settings and remove any installed packages. Are you sure? [N/y]

  • y

デバイスリセットボタン

デバイスのリセットボタンを5秒押し続ける

あとがき

参考資料(感謝:relaxed:

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1