openwrt编译,自定义时区,用户名,密码,wan口,lan口,pppoe

科学上网:自备

环境搭建

Debian/Ubuntu

sudo apt update
sudo apt install build-essential clang flex bison g++ gawk \
gcc-multilib g++-multilib gettext git libncurses5-dev libssl-dev \
python3-setuptools rsync swig unzip zlib1g-dev file wget
pacman -S --needed base-devel autoconf automake bash binutils bison \
bzip2 fakeroot file findutils flex gawk gcc gettext git grep groff \
gzip libelf libtool libxslt m4 make ncurses openssl patch pkgconf \
python python-distutils-extra rsync sed texinfo time unzip util-linux wget which zlib \
asciidoc help2man intltool perl-extutils-makemaker swig
sudo dnf --setopt install_weak_deps=False --skip-broken install \
bash-completion bzip2 gcc gcc-c++ git make ncurses-devel patch \
rsync tar unzip wget which diffutils python2 python3 perl-base \
perl-Data-Dumper perl-File-Compare perl-File-Copy perl-FindBin \
perl-IPC-Cmd perl-JSON-PP perl-Thread-Queue perl-Time-Piece

克隆及修改源码

git clone https://github.com/openwrt/openwrt.git
cd openwrt

切换版本

git branch -a
git branch remotes/origin/openwrt-23.05 && git branch remotes/origin/openwrt-24.10
git checkout v24.10.0-rc1
./scripts/feeds update -a && ./scripts/feeds install -a

建议执行git branch remotes/origin/openwrt-23.05 && git branch remotes/origin/openwrt-24.10要不然会出现各种各样的问题

修改ip地址,pppoe账户和秘密

vim package/base-files/files/bin/config_generate
local ipad
                        case "$1" in
                                lan) ipad=${ipaddr:-"你的ip"} ;;
                                *) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
                        esac
..........................................
uci -q batch <<-EOF
                                set network.$1.proto='pppoe'
                                set network.$1.username='你的账号'
                                set network.$1.password='你的密码‘
                        EO
..........................................
 uci -q batch <<-EOF
                delete system.@system[0]
                add system system
                set system.@system[-1].hostname='OpenWrt'
                set system.@system[-1].timezone='CST-8'#修改时区
                set system.@system[-1].zonename='Asia/Shanghai'#修改时区
                set system.@system[-1].ttylogin='0'
                set system.@system[-1].log_size='128'
                set system.@system[-1].urandom_seed='0'

                delete system.ntp
                set system.ntp='timeserver'
                set system.ntp.enabled='1'
                set system.ntp.enable_server='0'
                add_list system.ntp.server='0.openwrt.pool.ntp.org'
                add_list system.ntp.server='1.openwrt.pool.ntp.org'
                add_list system.ntp.server='2.openwrt.pool.ntp.org'
                add_list system.ntp.server='3.openwrt.pool.ntp.org'
        EOF

修改wan口为pppoe

vim package/base-files/files/lib/functions/uci-defaults.sh
ucidef_set_interface_lan() {
        ucidef_set_interface "lan" device "$1" protocol "${2:-static}"
}

ucidef_set_interface_wan() {
        ucidef_set_interface "wan" device "$1" protocol "${2:-dhcp}"#将dhcp修改成pppoe
}

调换wan口到eth0

vim package/base-files/files/etc/board.d/99-default_network
#
# Copyright (C) 2013-2015 OpenWrt.org
#

. /lib/functions/uci-defaults.sh

board_config_update

json_is_a network object && exit 0

ucidef_set_interface_lan 'eth0'   #这里改成eth1
[ -d /sys/class/net/eth1 ] && ucidef_set_interface_wan 'eth1'   #这里改成eth0

board_config_flush

exit 0

更换用户名及密码

vim package/base-files/files/etc/shadow
root:::0:99999:7:::#将root改成你的用户名
ftp:*:0:0:99999:7:::
network:*:0:0:99999:7:::
nobody:*:0:0:99999:7:::

修改tty自动登陆

vim package/base-files/files/usr/libexec/login.sh
#!/bin/sh

[ -t 0 ] && {
        tty_dev=$(readlink /proc/self/fd/0)
        case "$tty_dev" in
                /dev/console|/dev/tty[0-9]*)
                        export TERM=${TERM:-linux}
                        ;;
                /dev/*)
                        export TERM=vt102
                        ;;
        esac
}

[ "$(uci -q get system.@system[0].ttylogin)" = 1 ] || exec /bin/login -f root #将root替换成你的用户名

exec /bin/login
vim package/system/rpcd/files/rpcd.config
config rpcd
        option socket /var/run/ubus/ubus.sock
        option timeout 30

config login
        option username '你的用户名'
        option password '$p$你的用户名'
        list read '*'
        list write '*'

最后make menuconfig愉快的编译吧!

版权声明

本文为原创文章,作者:[唐小贤],首发于U社区。

转载请注明以下信息:

  • 作者:唐小贤
  • 原文链接:https://haouou.cn/forum-post/215.html?ref=17
  • 联系方式:an7788yy@163.com

说明:未经授权禁止转载,尊重原创内容是对作者最大的支持

请登录后发表评论

    没有回复内容

© 版权声明