openwrt configuration. Users guide. Part 1. How to configure network.

Short topic explaining openwrt configuration to get IP address via DHCP. Explained on example of NetSom development board but suitable for all another OpenWrt driven devices.

Initially, fresh built and flashed image won’t get IP address as it configured as DHCP server itself:

# ifconfig eth0
eth0            Link encap:Ethernet      HWaddr 00:11:22:33:44:55

UP BROADCAST RUNNING 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)
# ifconfig eth1
eth1            Link encap:Ethernet      HWaddr 23:58:7F:3D:44:78

UP BROADCAST RUNNING 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)

It is pretty simple to change configuration and get IP address via DHCP.

For that you need to edit /etc/config/network:

root@OpenWrt:/# vi /etc/config/network
and change lan interface:
config interface ‘lan’
# option type ‘bridge’
option ifname ‘eth0’
option proto ‘dhcp’
#                 option ipaddr ‘192.168.1.1’
#                 option netmask ‘255.255.255.0’
#                 option ip6assign ’60’
to enable second ethernet interface add following:
config interface ‘lan2’
option ifname ‘eth1’
option proto ‘dhcp’
then exit (by typing :wq) and restart network configuration:
root@OpenWrt:/# /etc/init.d/network  restart
and check if ip addresses taken:
root@OpenWrt:/# ifconfig eth0 && ifconfig eth1
eth0           Link encap:Ethernet HWaddr 06:AD:5C:86:06:FB
inet addr:192.168.0.122 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::4ad:5cff:fe86:6fb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:605 errors:0 dropped:0 overruns:0 frame:0
TX packets:1228 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:88497 (86.4 KiB) TX bytes:231956 (226.5 KiB)
eth1           Link encap:Ethernet HWaddr 00:11:22:33:44:55
inet addr:192.168.0.118 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::211:22ff:fe33:4455/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:482 errors:0 dropped:0 overruns:0 frame:0
TX packets:133 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:39921 (38.9 KiB) TX bytes:12518 (12.2 KiB)

 

In a case of facing network issue during developing custom SW/HW steps to troubleshoot described here might be useful:

 

Keep following as here at our telegram channel and at CrowdSupply!