openwrt上网配置的一些理解

其实已经有很多帖子讲过openwrt路由器上网配置了,我这里主要是讲我自己的一块硬件路由使用openwrt后的一些上网配置。之所以要研究我自己的配置,是因为硬件,硬件不一样,配置也就不一样,但是总的原则是一样的。这个原理上的东西把握好了,配置起来就简单了。可是很不幸,对liunx网络的博大精深的原理一窍不通,所以我的配置基本是依葫芦画瓢,一步一步尝试得来的。首先还是上我自己的硬件图吧

openwrt上网配置的一些理解

从我画的这个图里面就能大概知道我的/etc/config/network文件的写法了:

config interface lookback
option ifname lo
option proto static
option ipaddr 127.0.0.1
option netmask 255.0.0.0 config interface lan
option ifname eth0
option type bridge
option proto static
option ipaddr 192.168.12.1 #这是我自己选择的一个
option netmask 255.255.255.0 config interface wan
option ifname eth1
option proto dhcp config interface wan1
option ifname eth2
option proto dhcp config interface wan2
option ifname eth3
option proto dhcp config interface 3g
option proto 3g
option apn CMNET
option device /dev/ttyUSB2
option service umts
config interface union
option proto 3g
option apn CMNET
option device /dev/ttyUSB8
option service umts #这里因为我没有联通的卡,没试过,但是移动的卡是可以的。

关键还是要看firewall中的设置了,这里设置完了,就可以识别到这些网卡,luci界面中也可以看到了。

firewall这个东西一直不太搞得懂是干啥的,总之里面的口之间的关系不打通,上网是不行的。

这个文件里面我没有改动原来的,只是增加了一些zone和forwarding

首先按照他原有的wan格式,把wan1,wan2加上,如下:

config zone
option name wan1
option network 'wan1'
option input REJECT
option output ACCEPT
option forward REJECT
option masq
option mtu_fix config zone
option name wan2
option network 'wan2'
option input REJECT
option output ACCEPT
option forward REJECT
option masq
option mtu_fix config zone
option name 3g
option network '3g'
option input REJECT
option output ACCEPT
option forward REJECT
option masq
option mtu_fix config zone
option name union
option network 'union'
option input REJECT
option output ACCEPT
option forward REJECT
option masq
option mtu_fix config forwarding
option src lan
option dst wan1 config forwarding
option src lan
option dst wan2 config forwarding
option src lan
option dst 3g config forwarding
option src lan
option dst union

好了,我就做了这些工作,然后/etc/init.d/network  restart,/etc/init.d/firewall  restart

然后3g卡插上,wan口接上动态获取ip的上一级路由,我的电脑用网线练到lan口上,不管用那种方式都可以上网,不过电脑需要静态配置ip,动态的上不了外网。这也是我比较郁闷的,原理上搞不懂,你就别想动态上外网!

既然能上了,就先用着,我先去补补linux网络的知识先。

上一篇:pycharm的Database连接新的Mysql5.7报错[08001]


下一篇:hdu-5977 Garden of Eden(树分治)