首页 > 技术文章 > openwrt上网配置的一些理解(二)

preorder69 2014-05-14 22:34 原文

上一篇里面遇到了只能静态上网的问题,动态不行。所以再接再励,问题总是要解决的,偷懒的下场就是一直停留在菜鸟的水平。

首先分析下问题,要动态上网,首先我要明确不是动态获取不了IP,是获取了,上不了外网。那么问题就不会在lan口的配置上了,肯定是wan口,再来看我们的wan口配置。都一样,ifconfig|more,看了一下,eth1,eth2,eth3居然HWaddr都是00:A0:C9:00:00:00,不知道这样会不会影响上外网,但是肯定不对吧,所以我改了下:

config interface wan
            option ifname    eth1
            option proto      dhcp
            option macaddr  00:A0:C9:00:00:0A
config interface wan
            option ifname    eth1
            option proto      dhcp
            option macaddr  00:A0:C9:00:00:0B
config interface wan
            option ifname    eth1
            option proto      dhcp
            option macaddr  00:A0:C9:00:00:0C

没别的就是各加了个mac地址。

那么再试一下,果然都有自己的IP地址了,虽然我的lan口还是不能上外网。

那么主机ping一下,这里的主机其实就是我们的CPU,之前一直以为是网卡在ping。主机ping通外网了。动态获取了IP了,那么问题肯定在数据流向了。他到了我们主机这里,而且主机可以上外网了,那么肯定就是lan口和wan口数据不通了,一顿百度和谷歌,觉得有可能是firewall的问题,而且我们这里有3个wan口,那么后面的配置肯定还和multiwan有关,那么就去看/etc/config目录下firewall和multiwan这两个文件。

首先我发现之前第一篇的wan配置是不是有点麻烦,每个口都写zone和forwarding,看到网上其他人不用这么麻烦,所以精简成下面这样,试了一下,发现不影响,后来把forward那个reject编程ACCEPT,平板上网了。

config zone
            option name        wan    
            option network     ‘wan wan1 wan2’
            option input         REJECT
            option output       ACCEPT    
            option forward      ACCEPT
            option masq         1
            option mtu_fix      1

不过我还改了multiwan,但是我不认为multiwan是让我可以上网的原因。

那么multiwan是干什么的呢,初步分析认为,他是用来进行多wan口上网时进行流量均衡和wan口切换用的。我的配置了下,发现达到网上某些人说的多wan了,看了下3个wan口还真是都在走流量。在总的status里面MultiWAN-Status,3个wan,wan1,wan2都绿了,但是我试了,我把wan口拔掉,然后上网,不行,得重新启动下网络,防火墙和multiwan,/etc/init.d/network(firewall,multiwan)  restart,然后才又可以上网,这明显不是multiwan的作用。至于怎么配置,继续探索一下。

这里记录下整个multiwan文件:

config 'multiwan' 'config'
    option 'default_route' 'balancer'
    # health_monitor below is defaulted to parallel, and can be set to
    # serial to save system resources.
    # option 'health_monitor' 'serial'
    # option 'debug' '1'

config 'interface' 'wan'
    option 'weight' '1'
    option 'health_interval' '10'
    option 'icmp_hosts' 'gateway'
    # icmp_count is defaulted to 1, and can be increased to reduce
    # false positives.
    # option 'icmp_count' '3'
    option 'timeout' '3'
    option 'health_fail_retries' '3'
    option 'health_recovery_retries' '5'
    option 'failover_to' 'wan1'
    option 'dns' 'auto'

config 'interface' 'wan1'
    option 'weight' '1'
    option 'health_interval' '10'
    option 'icmp_hosts' 'gateway'
    option 'timeout' '3'
    option 'health_fail_retries' '3'
    option 'health_recovery_retries' '5'
    option 'failover_to' 'wan2'
    option 'dns' 'auto'

config 'interface' 'wan2'
    option 'weight' '1'
    option 'health_interval' '10'
    option 'icmp_hosts' 'gateway'
    option 'timeout' '3'
    option 'health_fail_retries' '3'
    option 'health_recovery_retries' '5'
    option 'failover_to' 'wan'
    option 'dns' 'auto'

#config 'mwanfw'
#    option 'src' '192.168.1.0/24'
#    option 'dst' 'ftp.netlab7.com'
#    option 'proto' 'tcp'
#    option 'ports' '21'
#    option 'wanrule' 'lan'

# VoIP traffic goes through wan
# config 'mwanfw'
    # option 'src' '192.168.1.0/24'
    # option 'proto' 'udp'
    # option 'port_type' 'source-ports'
    # option 'ports' '5060,16384:16482'
    # option 'wanrule' 'wan'

config 'mwanfw'
#    option 'src' '192.168.0.3'
#    option 'proto' 'icmp'
    option 'wanrule' 'balancer'

config 'mwanfw'
#    option 'dst' 'www.whatismyip.com'
    option 'wanrule' 'fastbalancer'

 

 

推荐阅读