| | 1 | [[PageOutline]] |
| | 2 | |
| | 3 | = OpenWrt Network Configuration = |
| | 4 | OpenWrt completely replaces the conventional Linux distribution methods of network configuration. The various config files are replaced with the Unified Configuration Interface or [http://wiki.openwrt.org/doc/uci UCI]. |
| | 5 | |
| | 6 | OpenWrt manages its own 'virtual' network interface names in /etc/config/network. |
| | 7 | |
| | 8 | See Also: |
| | 9 | * [http://wiki.openwrt.org/doc/uci/wireless OpenWrt Wiki for Wireless] |
| | 10 | * [http://wiki.openwrt.org/doc/uci OpenWrt UCI] |
| | 11 | * [wiki:OpenWrt/wireless OpenWrt Wireless] |
| | 12 | |
| | 13 | == UCI and config files == |
| | 14 | You can use the {{{uci}}} command-line utility to get/set configuration or edit the files directly under /system/config (if you know what your doing). Often we will provide uci command-line examples because these can be easily cut-n-pasted into a shell. |
| | 15 | |
| | 16 | UCI configuration can be edited in the files in /etc/config directly or by using {{{uci}}} commands. Often we will provide uci command-line examples because these can be easily cut-n-pasted into a shell. |
| | 17 | |
| | 18 | Network configuration is contained in /etc/config/network. |
| | 19 | |
| | 20 | Example configuration for a single ENET interface: |
| | 21 | * looking at /etc/config/network |
| | 22 | {{{ |
| | 23 | root@OpenWrt:/# cat /etc/config/network |
| | 24 | config interface 'loopback' |
| | 25 | option ifname 'lo' |
| | 26 | option proto 'static' |
| | 27 | option ipaddr '127.0.0.1' |
| | 28 | option netmask '255.0.0.0' |
| | 29 | |
| | 30 | config interface 'lan' |
| | 31 | option ifname 'eth0' |
| | 32 | option type 'bridge' |
| | 33 | option proto 'static' |
| | 34 | option ipaddr '192.168.1.1' |
| | 35 | option netmask '255.255.255.0' |
| | 36 | option ip6assign '60' |
| | 37 | |
| | 38 | config interface 'wan6' |
| | 39 | option ifname '@wan' |
| | 40 | option proto 'dhcpv6' |
| | 41 | |
| | 42 | config globals 'globals' |
| | 43 | option ula_prefix 'fda7:b97b:37b2::/48' |
| | 44 | |
| | 45 | }}} |
| | 46 | * using UCI: |
| | 47 | {{{ |
| | 48 | root@OpenWrt:/# uci show network |
| | 49 | network.loopback=interface |
| | 50 | network.loopback.ifname=lo |
| | 51 | network.loopback.proto=static |
| | 52 | network.loopback.ipaddr=127.0.0.1 |
| | 53 | network.loopback.netmask=255.0.0.0 |
| | 54 | network.lan=interface |
| | 55 | network.lan.ifname=eth0 |
| | 56 | network.lan.type=bridge |
| | 57 | network.lan.proto=static |
| | 58 | network.lan.ipaddr=192.168.1.1 |
| | 59 | network.lan.netmask=255.255.255.0 |
| | 60 | network.lan.ip6assign=60 |
| | 61 | network.wan6=interface |
| | 62 | network.wan6.ifname=@wan |
| | 63 | network.wan6.proto=dhcpv6 |
| | 64 | network.globals=globals |
| | 65 | network.globals.ula_prefix=fda7:b97b:37b2::/48 |
| | 66 | }}} |
| | 67 | |
| | 68 | |
| | 69 | To change the IP address of the '''lan''' network which is configured as a bridge containing the '''eth0''' interface using UCI: |
| | 70 | {{{ |
| | 71 | uci set network.lan.ipaddr 192.168.1.2 |
| | 72 | uci commit |
| | 73 | }}} |
| | 74 | |
| | 75 | You can restart the networking by typing the following command: |
| | 76 | {{{ |
| | 77 | /etc/init.d/network restart |
| | 78 | }}} |
| | 79 | |
| | 80 | |
| | 81 | [=#stp] |
| | 82 | == Spanning Tree Protocol - STP == |
| | 83 | The Spanning Tree Protocol (STP) is a network protocol that builds a logical loop-free topology for Ethernet networks. The basic function of STP is to prevent bridge loops and the broadcast radiation that results from them. |
| | 84 | |
| | 85 | By default bridges are configured without STP thus if you connected multiple ports in a bridge to a LAN you would create a bridge loop. |
| | 86 | |
| | 87 | You can enable STP to avoid bridge loops if you do want to connect multiple ports in a bridge to a LAN for redundancy purposes. To do so, edit {{{/etc/config/network}}} and add an {{{option stp 1}}} to the interface. |
| | 88 | |
| | 89 | For example: |
| | 90 | {{{ |
| | 91 | config interface 'lan' |
| | 92 | option ifname 'eth0' |
| | 93 | option force_link '1' |
| | 94 | option type 'bridge' |
| | 95 | option proto 'static' |
| | 96 | option ipaddr '192.168.1.1' |
| | 97 | option netmask '255.255.255.0' |
| | 98 | option ip6assign '60' |
| | 99 | option stp 1 |
| | 100 | |
| | 101 | }}} |
| | 102 | |
| | 103 | Verify with the brctl show command: |
| | 104 | {{{ |
| | 105 | root@OpenWrt:/# brctl show |
| | 106 | bridge name bridge id STP enabled interfaces |
| | 107 | br-lan 7fff.00d0127af035 yes eth0 |
| | 108 | }}} |