Contents
网络配置文件
- 网络接口配置 /etc/config/network
- 网络服务配置 /etc/config/dhcp
- 防火墙配置 /etc/config/firewall
配置查看命令
uci show networkuci show network.lanuci show network.wan
网络配置命令
lan接口配置动态获取
uci set network.lan.proto=dhcp
lan接口配置静态IP
-
设置IP配置方式:
uci set network.lan.proto='static'
-
设置LAN口的IP地址:
uci set network.lan.ipaddr='192.168.10.100'
-
设置LAN口的子网掩码:
uci set network.lan.netmask='255.255.255.0'
-
设置LAN口的网关地址:
uci set network.lan.gateway='192.168.10.1'
-
设置DNS服务器地址:uci set network.lan.dns=‘8.8.8.8’,如果有多个DNS服务器,可以用空格隔开多个IP地址,例如:
uci set network.lan.dns='8.8.8.8 8.8.4.4'
-
保存修改后的配置:
uci commit network
-
最后重启网络服务生效
/etc/init.d/network reload
-
执行完以上步骤后,OpenWrt设备的LAN口将配置为静态IP地址192.168.10.100、子网掩码255.255.255.0、网关192.168.10.1、dns 8.8.8.8
-
完整命令:
uci set network.lan.proto='static'uci set network.lan.ipaddr='192.168.10.100'uci set network.lan.netmask='255.255.255.0'uci set network.lan.gateway='192.168.10.1'uci set network.lan.dns='8.8.8.8'uci commit network/etc/init.d/network reload
- 执行后可以查看uci和配置文件
root@OpenWrt:~# uci set network.lan.proto='static'root@OpenWrt:~# uci set network.lan.ipaddr='192.168.10.100'root@OpenWrt:~# uci set network.lan.netmask='255.255.255.0'root@OpenWrt:~# uci set network.lan.gateway='192.168.10.1'root@OpenWrt:~# uci set network.lan.dns='8.8.8.8'root@OpenWrt:~# uci commit networkroot@OpenWrt:~#root@OpenWrt:~#root@OpenWrt:~# uci show network.lannetwork.lan=interfacenetwork.lan.device='br-lan'network.lan.netmask='255.255.255.0'network.lan.ip6assign='60'network.lan.proto='static'network.lan.ipaddr='192.168.10.100'network.lan.gateway='192.168.10.1'network.lan.dns='8.8.8.8'
lan接口修改后的配置
config interface 'lan' option device 'br-lan' option netmask '255.255.255.0' option ip6assign '60' option proto 'static' option ipaddr '192.168.10.100' option gateway '192.168.10.1' option dns '8.8.8.8'
网络重启命令
修改网络配置后,有多种方式让配置生效
/etc/init.d/network reload/etc/init.d/network restartubus call network reload