5. 在源码里修改lan的默认IP

随笔3个月前发布 和覅胡椒粉
39 0 0

参考网友帖子:OpenWrt编译时修改默认IP地址 – OpenWrt 中文教程 & More (jwtechtips.top)

修改如下文件 openwrt/imx_openwrt/package/base-files/files/binconfig_generate 如下:

    case "$protocol" in
        static)
            local ipad
            case "$1" in
                #lan) ipad=${ipaddr:-"192.168.1.1"} ;;
                #*) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
                lan) ipad=${ipaddr:-"10.168.103.129"} ;;
                *) ipad=${ipaddr:-"10.168.$((addr_offset++)).1"} ;;
            esac

            netm=${netmask:-"255.255.255.0"}

            uci -q batch <<-EOF
                set network.$1.proto='static'
                set network.$1.ipaddr='$ipad'
                set network.$1.netmask='$netm'
            EOF
            [ -e /proc/sys/net/ipv6 ] && uci set network.$1.ip6assign='60'
        ;;

实际效果OK:

root@OpenWrt:/# ifconfig
br-lan    Link encap:Ethernet  HWaddr EA:E3:4C:6E:FB:18
          inet addr:10.168.103.129  Bcast:10.168.103.255  Mask:255.255.255.0
          inet6 addr: fd4d:fa6f:8bd3::1/60 Scope:Global
          inet6 addr: fe80::e8e3:4cff:fe6e:fb18/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:610 errors:0 dropped:0 overruns:0 frame:0
          TX packets:282 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:115426 (112.7 KiB)  TX bytes:188905 (184.4 KiB)

eth0      Link encap:Ethernet  HWaddr EA:E3:4C:6E:FB:18
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:708 errors:0 dropped:15 overruns:0 frame:0
          TX packets:288 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:136804 (133.5 KiB)  TX bytes:189421 (184.9 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0E:C6:8E:98:71
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:262 errors:0 dropped:0 overruns:0 frame:0
          TX packets:262 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:25050 (24.4 KiB)  TX bytes:25050 (24.4 KiB)

root@OpenWrt:/#

 

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...