openwrt中的网络接口介绍

  • 作者:Moilk
  • 最后编辑:2017年09月16日
  • 标签: network

openwrt config

网络配置

有线网配置

openwrt的有线网配置文件在/etc/config/network文件中

config interface 'loopback'					# 虚拟设备,本地回环接口
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'auto'

config interface 'lan'						# 虚拟设备,局域网接口
        option ifname 'eth0.1'
        option force_link '1'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option macaddr '64:09:80:4c:f1:95'

config interface 'wan'						# 外网接口
        option ifname 'eth0.2'
        option proto 'dhcp'
        option macaddr '64:09:80:4c:f1:96'

config interface 'wan6'
        option ifname '@wan'
        option proto 'dhcpv6'

config switch
        option name 'mt762x'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'mt762x'
        option vlan '1'
        option ports '0 1 2 3 5 6t'

config switch_vlan
        option device 'mt762x'
        option vlan '2'
        option ports '4 6t'

无线网络配置

openwrt的无线网络配置在/etc/config/wireless文件中

config wifi-device 'rai0'
        option type 'mt7612'
        option mode '14'
        option channel 'auto'
        option txpower '100'
        option ht '20+40+80'
        option country 'US'
        option disabled '0'

config wifi-iface
        option device 'rai0'
        option network 'lan'
        option mode 'ap'
        option ssid 'PandoraBox_5G_4CF197'
        option encryption 'none'

config wifi-device 'ra0'
        option type 'rt2860v2'
        option mode '9'
        option channel 'auto'
        option txpower '100'
        option ht '40'
        option country 'US'
        option disabled '0'

config wifi-iface
        option device 'ra0'
        option network 'lan'
        option mode 'ap'
        option wps 'pbc'
        option ssid 'PandoraBox_Moilk'
        option encryption 'psk+psk2'
        option key '12345678'

说明

执行ifconfig 指令,得到结果如下:

[root@PandoraBox:/root]#ifconfig
br-lan    Link encap:Ethernet  HWaddr 64:09:80:4C:F1:95  
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::6609:80ff:fe4c:f195/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:60404 errors:0 dropped:0 overruns:0 frame:0
          TX packets:55419 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:9447624 (9.0 MiB)  TX bytes:52951685 (50.4 MiB)

eth0      Link encap:Ethernet  HWaddr 64:09:80:4C:F1:95  
          inet6 addr: fe80::6609:80ff:fe4c:f195/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10411685 errors:0 dropped:0 overruns:0 frame:0
          TX packets:62604 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1221779641 (1.1 GiB)  TX bytes:12907929 (12.3 MiB)
          Interrupt:3 

eth0.1    Link encap:Ethernet  HWaddr 64:09:80:4C:F1:95  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:19367 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:6307815 (6.0 MiB)

eth0.2    Link encap:Ethernet  HWaddr 64:09:80:4C:F1:96  
          inet addr:211.67.16.110  Bcast:211.67.19.255  Mask:255.255.252.0
          inet6 addr: fe80::6609:80ff:fe4c:f196/64 Scope:Link
          inet6 addr: 2001:250:4000:4128:6609:80ff:fe4c:f196/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10411685 errors:0 dropped:1 overruns:0 frame:0
          TX packets:43233 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1034369311 (986.4 MiB)  TX bytes:6599666 (6.2 MiB)

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:255401 errors:0 dropped:0 overruns:0 frame:0
          TX packets:255401 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:17368552 (16.5 MiB)  TX bytes:17368552 (16.5 MiB)

ra0       Link encap:Ethernet  HWaddr 66:09:80:4C:F1:94  
          inet6 addr: fe80::6409:80ff:fe4c:f194/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:66283 errors:1 dropped:0 overruns:0 frame:0
          TX packets:66046 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12370855 (11.7 MiB)  TX bytes:55267038 (52.7 MiB)
          Interrupt:4 

rai0      Link encap:Ethernet  HWaddr 64:09:80:4C:F1:97  
          inet6 addr: fe80::6609:80ff:fe4c:f197/64 Scope:Link
          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)
          Interrupt:13
  1. br-lan: 虚拟设备,用于LAN口设备桥接的,目前路由器普遍将有线LAN口和Wi-Fi无线接口在一起作为统一的LAN
  2. eth0: 网络适配设备,是一块物理网卡,eth0.1和eth0.2都是从此设备上虚拟出来的
    • eth0.1: LAN口
    • eth0.2: WAN口,连接外网
  3. lo: 虚拟设备,local的简称,本地环路
  4. ra0: 2.4G无线网络设备
  5. rai0: 5.8G无线网络设备