openwrt的双出口配置

家里的newifiD2原装系统,没有刷机,原本用的好好的,加了一些插件用作双出口路由(移动,联通)还行,不过昨天突然出现故障,找不到U盘,也就不能用插件了,双出口插件不能用了,我自己写的路由也就不能启作用了。但没有了U盘发现手机还是能用的,就是一些其它的设备不能上网了。我觉得是DHCP中DNS的下发问题,发现设备得到DNS是192.168.99.1,在笔记本电脑上设成常用DNS就可以上网了,但问题出来了,总得解决。上网查得:系统基本是OPENWRT的开发。OpenWrt的网络配置文件是/etc/config/network.我的配置如下
[root@newifi_3BC5:/etc/config]#cat 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 ‘fdff:7532:4457::/48’

config interface ‘lan’
option ifname ‘eth0.1’
option force_link ‘1’
option type ‘bridge’
option proto ‘static’
option ipaddr ‘192.168.99.1’
option netmask ‘255.255.255.0’
option ip6assign ‘60’
option macaddr ‘20:76:93:41:3b:c5’

config interface ‘wan’
option ifname ‘eth0.2’
option macaddr ‘20:76:93:41:3b:c7’
option guide_type ‘3’
option password ‘******’
option username ‘************’
option mtu ‘1500’
option proto ‘pppoe’

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 7t’

config switch_vlan
option device ‘mt762x’
option vlan ‘2’
option ports ‘4 6t 7t’

config switch_vlan
option device ‘mt762x’
option vlan ‘3’
option ports ‘3 6t 7t’

config interface ‘wan2’
option ifname ‘eth0.3’
option proto ‘static’
option ipaddr ‘192.168.2.2’
option netmask ‘255.255.255.0’
option gateway ‘192.168.2.1’
OpenWrt的网络DHCP配置文件是/etc/config/dhcp
我的配置如下:
[root@newifi_3BC5:/etc/config]#cat dhcp

config dnsmasq
option domainneeded ‘1’
option boguspriv ‘1’
option localise_queries ‘1’
option rebind_protection ‘1’
option rebind_localhost ‘1’
option local ‘/lan/’
option domain ‘lan’
option expandhosts ‘1’
option authoritative ‘1’
option readethers ‘1’
option leasefile ‘/tmp/dhcp.leases’
option noresolv ‘1’
list server ‘127.0.0.1#1053’
list dhcp_option ‘6,211.138.24.66,202.102.224.68’

config dhcp ‘lan’
option interface ‘lan’
option start ‘100’
option leasetime ‘12h’
option dhcpv6 ‘server’
option ra ‘server’
option limit ‘101’

config dhcp ‘wan’
option interface ‘wan’
option ignore ‘1’

config odhcpd ‘odhcpd’
option maindhcp ‘0’
option leasefile ‘/tmp/hosts/odhcpd’
option leasetrigger ‘/usr/sbin/odhcpd-update’
加了一条: list dhcp_option '6,211.138.24.66,202.102.224.68’在段
config dnsmasq中,一开始是加在config dhcp ‘lan’ 段中,发现会出现无5G信号和第二wan口192.168.2.1不能转发的问题。网上资料也不多,对这一块也没搞懂。反正现在能用,先作个标记!改其它的地方也不好使!现在DHCP分配的DNS是我想设置的,这样那些不能手动改DNS的安桌设备也可以快速的上网了。
对了,我自己在开机时加了些路由,如下:作的策略路由
[root@newifi_3BC5:/etc]#cat iproute
route add -net 1.51.64.0 netmask 255.255.192.0 gw 192.168.2.1
route add -net 1.88.0.0 netmask 255.252.0.0 gw 192.168.2.1
route add -net 1.93.128.0 netmask 255.255.128.0 gw 192.168.2.1
route add -net 36.128.0.0 netmask 255.255.192.0 gw 192.168.2.1
route add -net 36.192.0.0 netmask 255.255.224.0 gw 192.168.2.1
route add -net 36.193.40.0 netmask 255.255.248.0 gw 192.168.2.1
route add -net 36.193.48.0 netmask 255.255.240.0 gw 192.168.2.1
route add -net 39.128.0.0 netmask 255.192.0.0 gw 192.168.2.1
route add -net 43.240.244.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 43.20.248.0 netmask 255.255.248.0 gw 192.168.2.1
route add -net 43.241.0.0 netmask 255.255.254.0 gw 192.168.2.1
route add -net 43.241.112.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 43.251.244.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 45.115.21.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 49.5.32.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 61.232.0.0 netmask 255.252.0.0 gw 192.168.2.1
route add -net 61.236.0.0 netmask 255.254.0.0 gw 192.168.2.1
route add -net 101.144.0.0 netmask 255.240.0.0 gw 192.168.2.1
route add -net 101.240.0.0 netmask 255.252.0.0 gw 192.168.2.1
route add -net 103.20.112.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 103.21.176.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 103.37.72.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 103.55.236.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 106.3.32.0 netmask 255.255.248.0 gw 192.168.2.1
route add -net 106.3.4.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 110.96.0.0 netmask 255.224.0.0 gw 192.168.2.1
route add -net 110.192.0.0 netmask 255.224.0.0 gw 192.168.2.1
route add -net 111.0.0.0 netmask 255.192.0.0 gw 192.168.2.1
route add -net 111.132.0.0 netmask 255.255.0.0 gw 192.168.2.1
route add -net 111.148.0.0 netmask 255.252.0.0 gw 192.168.2.1
route add -net 112.0.0.0 netmask 255.192.0.0 gw 192.168.2.1
route add -net 113.18.0.0 netmask 255.255.128.0 gw 192.168.2.1
route add -net 113.18.128.0 netmask 255.255.192.0 gw 192.168.2.1
route add -net 114.213.128.0 netmask 255.255.128.0 gw 192.168.2.1
route add -net 114.214.128.0 netmask 255.255.128.0 gw 192.168.2.1
route add -net 115.106.0.0 netmask 255.254.0.0 gw 192.168.2.1
route add -net 116.204.0.0 netmask 255.255.224.0 gw 192.168.2.1
route add -net 117.128.0.0 netmask 255.192.0.0 gw 192.168.2.1
route add -net 118.146.0.0 netmask 255.254.0.0 gw 192.168.2.1
route add -net 118.245.0.0 netmask 255.255.0.0 gw 192.168.2.1
route add -net 119.19.224.0 netmask 255.255.255.0 gw 192.168.2.1
route add -net 119.57.104.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 119.57.152.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 119.90.8.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 119.90.32.0 netmask 255.255.248.0 gw 192.168.2.1
route add -net 119.90.48.0 netmask 255.255.248.0 gw 192.168.2.1
route add -net 120.90.0.0 netmask 255.254.0.0 gw 192.168.2.1
route add -net 120.192.0.0 netmask 255.192.0.0 gw 192.168.2.1
route add -net 122.64.0.0 netmask 255.224.0.0 gw 192.168.2.1
route add -net 123.64.0.0 netmask 255.224.0.0 gw 192.168.2.1
route add -net 124.201.0.0 netmask 255.255.0.0 gw 192.168.2.1
route add -net 183.192.0.0 netmask 255.192.0.0 gw 192.168.2.1
route add -net 203.80.144.0 netmask 255.255.252.0 gw 192.168.2.1
route add -net 211.98.0.0 netmask 255.255.0.0 gw 192.168.2.1
route add -net 211.103.0.0 netmask 255.255.128.0 gw 192.168.2.1
route add -net 211.136.0.0 netmask 255.248.0.0 gw 192.168.2.1
route add -net 218.200.0.0 netmask 255.248.0.0 gw 192.168.2.1
route add -net 221.130.0.0 netmask 255.254.0.0 gw 192.168.2.1
route add -net 221.172.0.0 netmask 255.252.0.0 gw 192.168.2.1
route add -net 221.176.0.0 netmask 255.248.0.0 gw 192.168.2.1
route add -net 222.32.0.0 netmask 255.224.0.0 gw 192.168.2.1
route add -net 223.64.0.0 netmask 255.192.0.0 gw 192.168.2.1
route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.2.1 metric 1
真实路由表如下:
[root@newifi_3BC5:/etc]#ip route
default via 100.64.0.1 dev pppoe-wan proto static
default via 192.168.2.1 dev eth0.3 metric 1
1.51.64.0/18 via 192.168.2.1 dev eth0.3
1.88.0.0/14 via 192.168.2.1 dev eth0.3
1.93.128.0/17 via 192.168.2.1 dev eth0.3
36.128.0.0/18 via 192.168.2.1 dev eth0.3
36.192.0.0/19 via 192.168.2.1 dev eth0.3
36.193.40.0/21 via 192.168.2.1 dev eth0.3
36.193.48.0/20 via 192.168.2.1 dev eth0.3
39.128.0.0/10 via 192.168.2.1 dev eth0.3
43.20.248.0/21 via 192.168.2.1 dev eth0.3
43.240.244.0/22 via 192.168.2.1 dev eth0.3
43.241.0.0/23 via 192.168.2.1 dev eth0.3
43.241.112.0/22 via 192.168.2.1 dev eth0.3
43.251.244.0/22 via 192.168.2.1 dev eth0.3
49.5.32.0/22 via 192.168.2.1 dev eth0.3
61.232.0.0/14 via 192.168.2.1 dev eth0.3
61.236.0.0/15 via 192.168.2.1 dev eth0.3
100.64.0.1 dev pppoe-wan proto kernel scope link src 100.64.220.66
101.144.0.0/12 via 192.168.2.1 dev eth0.3
101.240.0.0/14 via 192.168.2.1 dev eth0.3
103.20.112.0/22 via 192.168.2.1 dev eth0.3
103.21.176.0/22 via 192.168.2.1 dev eth0.3
103.37.72.0/22 via 192.168.2.1 dev eth0.3
103.55.236.0/22 via 192.168.2.1 dev eth0.3
106.3.4.0/22 via 192.168.2.1 dev eth0.3
106.3.32.0/21 via 192.168.2.1 dev eth0.3
110.96.0.0/11 via 192.168.2.1 dev eth0.3
110.192.0.0/11 via 192.168.2.1 dev eth0.3
111.0.0.0/10 via 192.168.2.1 dev eth0.3
111.132.0.0/16 via 192.168.2.1 dev eth0.3
111.148.0.0/14 via 192.168.2.1 dev eth0.3
112.0.0.0/10 via 192.168.2.1 dev eth0.3
113.18.0.0/17 via 192.168.2.1 dev eth0.3
113.18.128.0/18 via 192.168.2.1 dev eth0.3
114.213.128.0/17 via 192.168.2.1 dev eth0.3
114.214.128.0/17 via 192.168.2.1 dev eth0.3
115.106.0.0/15 via 192.168.2.1 dev eth0.3
116.204.0.0/19 via 192.168.2.1 dev eth0.3
117.128.0.0/10 via 192.168.2.1 dev eth0.3
118.146.0.0/15 via 192.168.2.1 dev eth0.3
118.245.0.0/16 via 192.168.2.1 dev eth0.3
119.19.224.0/24 via 192.168.2.1 dev eth0.3
119.57.104.0/22 via 192.168.2.1 dev eth0.3
119.57.152.0/22 via 192.168.2.1 dev eth0.3
119.90.8.0/22 via 192.168.2.1 dev eth0.3
119.90.32.0/21 via 192.168.2.1 dev eth0.3
119.90.48.0/21 via 192.168.2.1 dev eth0.3
120.90.0.0/15 via 192.168.2.1 dev eth0.3
120.192.0.0/10 via 192.168.2.1 dev eth0.3
122.64.0.0/11 via 192.168.2.1 dev eth0.3
123.64.0.0/11 via 192.168.2.1 dev eth0.3
124.201.0.0/16 via 192.168.2.1 dev eth0.3
183.192.0.0/10 via 192.168.2.1 dev eth0.3
192.168.1.0/24 dev eth0.2 proto kernel scope link src 192.168.1.3
192.168.2.0/24 dev eth0.3 proto kernel scope link src 192.168.2.2
192.168.99.0/24 dev br-lan proto kernel scope link src 192.168.99.1
203.80.144.0/22 via 192.168.2.1 dev eth0.3
211.98.0.0/16 via 192.168.2.1 dev eth0.3
211.103.0.0/17 via 192.168.2.1 dev eth0.3
211.136.0.0/13 via 192.168.2.1 dev eth0.3
218.200.0.0/13 via 192.168.2.1 dev eth0.3
221.130.0.0/15 via 192.168.2.1 dev eth0.3
221.172.0.0/14 via 192.168.2.1 dev eth0.3
221.176.0.0/13 via 192.168.2.1 dev eth0.3
222.32.0.0/11 via 192.168.2.1 dev eth0.3
223.64.0.0/10 via 192.168.2.1 dev eth0.3
关于openwrt的端口
在这里插入图片描述Virtual Network Interfaces

lo, eth0:1, eth0.1, vlan2, br0, pppoe-dsl, gre0, sit0 tun0, imq0, teql0, … are virtual network interfaces that do NOT represent an existent hardware device but are linked to one (otherwise they would be useless). Virtual network interfaces were invented to give the system administrator maximum flexibility when configuring a Linux-based operating system. A virtual network interface is generally associated with a physical network interface (eth6) or another virtual interface (eth6.9) or be stand alone such as the loopback interface lo.
Types of Virtual Network Interfaces

aliases: eth4:5, eth4:6, ..
IP-aliases are an obsolete way to manage multiple IP-addresses/masks per interface. Newer tools such as iproute2 support multiple address/prefixes per interface, but aliases are still supported for backwards compatibility. Documentation/networking/alias.txt
VLANs: eth4.0, eth4.1, eth4.3, vlan0, ..
are created to partition a single layer 2 network into multiple virtual ones. The drivers all participating network cards must support IEEE 802.1Q and be configured accordingly. This standard allows for up to 4096 VLANs (12Bits).
Stacked VLANs: IEEE 802.1ad-support was mainlined in 2013-04-19: net: vlan: add 802.1ad support Configuration is done using ip link:

ip link add link eth0 eth0.1000 type vlan proto 802.1ad id 1000
ip link add link eth0.1000 eth0.1000.1000 type vlan proto 802.1q id 1000

bridges: br0, br-lan
are used to make multiple virtual or physical network interfaces act as if they were just one network interface (quasi the opposite of VLANs). Can also be used for VPN and bridged interfaces. The Linux Ethernet bridge can be used for connecting multiple Ethernet devices together. The connecting is fully transparent: hosts connected to one Ethernet device see hosts connected to the other Ethernet devices directly. understanding how bridge-interfaces work
tunnel interfaces: pppoe-dsl, pppoa-dsl, tun0, vpn1,
used to send packets over a tunneling protocol such as GRE, IPsec PPPoE, etc.
special purpose: imq0, teql3
used to change the order of outgoing network packets, or incoming network packet
wireless operating mode virtual interfaces: wlan0, wlan0_1, ath3, ath_monitor, ..
Linux wireless subsystem: There is always one physical network interface for each WNIC called the master interface. The master interface is invisible. Then, depending on the wireless operating mode the master interface is configured to, ad-hoc (IBSS), managed , AP , WDS, mesh point, monitor, wireless virtual network interfaces with different properties are created. This is done automatically by default. When the WNIC driver is loaded, there always will be the master interface and (at least) one virtual interface!

Example on the asus wl500gp v2 , openwrt 10.03, every physical port

config ‘switch’ ‘eth0’
option ‘enable’ ‘1’

config ‘switch_vlan’ ‘eth0_0’
option ‘device’ ‘eth0’
option ‘vlan’ ‘0’
option ‘ports’ ‘4 5’ #wan

config ‘switch_vlan’ ‘eth0_1’
option ‘device’ ‘eth0’
option ‘vlan’ ‘1’
option ‘ports’ ‘3 5’ #lan 1

config ‘switch_vlan’ ‘eth0_2’
option ‘device’ ‘eth0’
option ‘vlan’ ‘2’
option ‘ports’ ‘2 5’ #lan2

config ‘switch_vlan’ ‘eth0_3’
option ‘device’ ‘eth0’
option ‘vlan’ ‘3’
option ‘ports’ ‘1 5’ #lan3

config ‘switch_vlan’ ‘eth0_4’
option ‘device’ ‘eth0’
option ‘vlan’ ‘4’
option ‘ports’ ‘0 5’ #lan4

#note that to use a particular port in an interface the ifname
#should be ‘devicename.vlan’ . So for example ifname ‘eth0.3’

openWRT命令详见:
https://openwrt.org/docs/guide-developer/networking/network.interfaces

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值