This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tp-link-mr12u-v1shua-openwrtmentohustjiao-cha-bian-yi-fu-wen-jian-xia-zai.html
340 lines (269 loc) · 18.7 KB
/
tp-link-mr12u-v1shua-openwrtmentohustjiao-cha-bian-yi-fu-wen-jian-xia-zai.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>TP-Link mr12u-v1刷openwrt+mentohust交叉编译(附文件下载)</title>
<link href="/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="华科美团点评技术俱乐部 Full Atom Feed" />
<link href="/feeds/openwrt.atom.xml" type="application/atom+xml" rel="alternate" title="华科美团点评技术俱乐部 Categories Atom Feed" />
<!-- Bootstrap Core CSS -->
<link href="/theme/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="/theme/css/clean-blog.min.css" rel="stylesheet">
<!-- Code highlight color scheme -->
<link href="/theme/css/code_blocks/darkly.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<meta name="description" content="写在前面 开学学校启用了有线网,由于校园网存在只能单一设备登陆的限制与无线登陆限速,所以想通过路由器刷openwrt再使用mentohust进行校园网的锐捷认证来实现多设备与不限速使用。 在选择路由器时考虑了如下因素:...">
<meta name="author" content="Di Wu">
<meta name="tags" content="openwrt">
<meta property="og:locale" content="zh_CN.UTF-8">
<meta property="og:site_name" content="华科美团点评技术俱乐部">
<meta property="og:type" content="article">
<meta property="article:author" content="/author/di-wu.html">
<meta property="og:url" content="/tp-link-mr12u-v1shua-openwrtmentohustjiao-cha-bian-yi-fu-wen-jian-xia-zai.html">
<meta property="og:title" content="TP-Link mr12u-v1刷openwrt+mentohust交叉编译(附文件下载)">
<meta property="article:published_time" content="2017-09-05 20:06:16+08:00">
<meta property="og:description" content="写在前面 开学学校启用了有线网,由于校园网存在只能单一设备登陆的限制与无线登陆限速,所以想通过路由器刷openwrt再使用mentohust进行校园网的锐捷认证来实现多设备与不限速使用。 在选择路由器时考虑了如下因素:...">
<meta property="og:image" content="//images/bg.jpg">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">华科美团点评技术俱乐部</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="/categories.html">分类</a></li>
<li><a href="/archives.html">归档</a></li>
<li><a href="/authors.html">作者</a></li>
<li><a href="/tags.html">标签</a></li>
<li><a href="/pages/about/index.html">关于</a></li>
<li><a href="/pages/friendlinks/index.html">友链</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Header -->
<header class="intro-header" style="background-image: url('/images/bg.jpg')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-heading">
<h1>TP-Link mr12u-v1刷openwrt+mentohust交叉编译(附文件下载)</h1>
<span class="meta">Posted by
<a href="/author/di-wu.html">Di Wu</a>
on 2017年 9月05日 周二
</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<!-- Post Content -->
<article>
<h2>写在前面</h2>
<p>开学学校启用了有线网,由于校园网存在只能单一设备登陆的限制与无线登陆限速,所以想通过路由器刷<code>openwrt</code>再使用<code>mentohust</code>进行校园网的锐捷认证来实现多设备与不限速使用。</p>
<p>在选择路由器时考虑了如下因素:</p>
<ol>
<li>可刷<code>openwrt</code>:只有特定的处理器支持<code>openwrt</code>,支持的路由器型号在官网有一个<a href="https://wiki.openwrt.org/toh/start">列表</a>,直接参照这个列表选就可以了。</li>
<li>有电源/usb供电:在寝室使用的话因为有段时间断电但不断网,所以需要自带电源或可用移动电源usb供电。</li>
<li>性价比高:因为只用于转发校园网,所以可以买便宜一些的。</li>
</ol>
<p>最终选择了<code>TP-Link mr12u</code>这款路由器,在闲鱼上找了一家同城二手的,45元人民币拿下。</p>
<!--more-->
<p><strong>注意下面需要在<code>linux</code>终端环境下操作</strong></p>
<h2>刷不死Boot</h2>
<p>由于路由器固件的特殊性,一旦刷崩了或者设置错误导致无法正常登陆路由器,那么就无法对路由器进行管理,也就是所谓的变砖。</p>
<p>不死boot的作用就是在这种情况下提供进路由设置重新刷固件的机会。</p>
<h3>刷解锁固件</h3>
<p>由于<code>U-Boot</code>分区默认是锁定的,所以无法刷入新的<code>boot</code>。因此我们要先刷入一个修改过的解锁<code>U-Boot</code>分区的固件,这个修改过的固件可以在<a href="https://pan.baidu.com/s/1slWHygP">百度网盘下载</a>,另外由于我手上的这个是v1版本的,与v2版本的硬件不同,所以需要使用的是<code>mr11u-v2</code>的解锁固件(即<code>openwr-ar71xx-generic-tl-mr11u-v2-squashfs-factory.bin</code>)。下载完以后先长按复位键复位路由器,连接上以后直接进入<code>192.168.1.1</code> <code>TP-Link</code>默认的管理界面,在下图这里选择刚下好的固件刷入即可:</p>
<p><img alt="" src="/images/mr11u-1.png"></p>
<p>(图源网络)</p>
<h3>刷不死boot</h3>
<p>先下载不死<code>boot</code>:</p>
<blockquote>
<p>http://viseator.com/file/breed-ar9331-mr12u.bin</p>
</blockquote>
<p>路由器自动重启以后使用网线连接电脑与路由器,先用浏览器登陆<code>192.168.1.1</code>,用户名为<code>root</code>密码为空,然后设置<code>ssh</code>密码并保存。</p>
<p>现在就可以使用<code>ssh</code>用<code>root</code>与刚刚设置的密码登陆路由器了:</p>
<div class="highlight"><pre><span></span>ssh [email protected]
</pre></div>
<p>登陆以后先查看并记下<code>mac</code>地址,之后要用到:</p>
<div class="highlight"><pre><span></span>ifconfig eth0
</pre></div>
<p><img alt="" src="/images/mr12u-2.png"></p>
<p><a href="http://xzper.com/2015/07/11/TP-MR12U%E5%88%B7openwrt-%E4%B8%8D%E6%AD%BBboot/">图片来源</a></p>
<p>然后<code>exit</code>退出<code>ssh</code>,使用<code>scp</code>命令传送下载好的<code>boot</code>包:</p>
<div class="highlight"><pre><span></span>scp breed-ar9331-mr12u.bin [email protected]:/tmp/
</pre></div>
<p>再次登陆路由器,刷入<code>U-Boot</code>:</p>
<div class="highlight"><pre><span></span><span class="n">ssh</span> <span class="n">root</span><span class="mf">@192.168.1.1</span>
<span class="n">cd</span> <span class="o">/</span><span class="n">tmp</span>
<span class="n">mtd</span> <span class="n">write</span> <span class="n">breed</span><span class="o">-</span><span class="n">ar9331</span><span class="o">-</span><span class="n">mr12u</span><span class="p">.</span><span class="n">bin</span> <span class="n">u</span><span class="o">-</span><span class="n">boot</span>
</pre></div>
<p>等待命令返回后直接将路由器关机。</p>
<p>想要进入不死<code>boot</code>,只需按住<code>reset</code>复位键不放,再开机,等待个十几秒后松开,再有线连接电脑与路由器,浏览器输入<code>192.168.1.1</code>就可以进入管理界面了,以后变砖了只要这样都可以重新刷固件,所以称不死。</p>
<p>进入不死<code>boot</code>以后,先进入下图界面设置之前记录的<code>mac</code>地址:</p>
<p><img alt="" src="/images/mr12u-3.png"></p>
<p><a href="http://xzper.com/2015/07/11/TP-MR12U%E5%88%B7openwrt-%E4%B8%8D%E6%AD%BBboot/">图片来源</a></p>
<h2>刷入最新固件(可选)</h2>
<p>下面就可以直接在不死<code>boot</code>里面选择固件更新刷入最新的固件了,最新固件的下载可以到<a href="https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/">这里</a>找到。</p>
<p>但是<code>mr12u</code>的闪存只有可怜的4m,如果安装最新的<code>openwrt</code>就没有空间放下<code>mentohust</code>了,所以还不如就直接用这个解锁用的固件。</p>
<h2>交叉编译mentohust</h2>
<p>在网上找了一圈愣是没找到<code>ar71xx</code>处理器已经编译好的<code>mentohust</code>,只能选择自己交叉编译了。没有条件自己编译的可以使用我编译好的<strong>只适用于ar71xx</strong>处理器的<code>mentohust</code>: http://www.viseator.com/file/mentohust 。</p>
<h3>依赖包的安装</h3>
<p>可以到https://wiki.openwrt.org/zh-cn/doc/howto/buildroot.exigence 根据自己的发行版安装必要的软件包。</p>
<h3>下载编译工具链</h3>
<p>首先到https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/ 页面下载 <a href="https://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/OpenWrt-SDK-ar71xx-generic_gcc-5.3.0_musl-1.1.16.Linux-x86_64.tar.bz2">OpenWrt-SDK-ar71xx-generic_gcc-5.3.0_musl-1.1.16.Linux-x86_64.tar.bz2</a> 处理器<code>SDK</code>,解压后进入目录下的<code>./staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.16/bin</code>。</p>
<h3>配置环境变量</h3>
<div class="highlight"><pre><span></span><span class="nb">export</span> <span class="nv">PATH</span><span class="o">=</span><span class="nv">$PATH</span>:到上述/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.16/bin 目录的完整路径
<span class="nb">export</span> <span class="nv">CC</span><span class="o">=</span>mipsel-openwrt-linux-gcc
<span class="nb">export</span> <span class="nv">CPP</span><span class="o">=</span>mipsel-openwrt-linux-cpp
<span class="nb">export</span> <span class="nv">GCC</span><span class="o">=</span>mipsel-openwrt-linux-gcc
<span class="nb">export</span> <span class="nv">CXX</span><span class="o">=</span>mipsel-openwrt-linux-g++
<span class="nb">export</span> <span class="nv">RANLIB</span><span class="o">=</span>mipsel-openwrt-linux-uclibc-ranlib
<span class="nb">export</span> <span class="nv">LDFLAGS</span><span class="o">=</span><span class="s2">"-static"</span>
<span class="nb">export</span> <span class="nv">CFLAGS</span><span class="o">=</span><span class="s2">"-Os -s"</span>
</pre></div>
<h3>编译libpcap动态链接库</h3>
<p>到 http://www.tcpdump.org/ 下载<a href="http://www.tcpdump.org/release/libpcap-1.8.1.tar.gz">libpcap-1.8.1.tar.gz</a>,解压以后进入目录,执行:</p>
<div class="highlight"><pre><span></span>./configure --host<span class="o">=</span>mipsel-openwrt-linux --prefix<span class="o">=</span>自已设定路径/ --with-pcap<span class="o">=</span>linux
</pre></div>
<p>然后执行:</p>
<div class="highlight"><pre><span></span>make
</pre></div>
<p>会报错误,但是不影响我们需要的<code>libpcap.a</code>文件,在当前目录下找到这个文件复制出来备用。</p>
<h3>编译mentohust</h3>
<p>克隆<code>mentohust</code>源码:</p>
<div class="highlight"><pre><span></span>git clone https://github.com/hyrathb/mentohust
</pre></div>
<p>进入目录,首先生成<code>configure</code>:</p>
<div class="highlight"><pre><span></span>sh autogen.sh
</pre></div>
<p>然后配置:</p>
<div class="highlight"><pre><span></span>./configure --host<span class="o">=</span>mipsel-openwrt-linux --disable-encodepass --disable-notify --prefix<span class="o">=</span>自设目录 --with-pcap<span class="o">=</span>前面保存的libpcap.a文件路径
</pre></div>
<p>编译:</p>
<div class="highlight"><pre><span></span>make
</pre></div>
<p>成功以后就可以在<code>src</code>目录下找到编译好的<code>mentohust</code>文件了。</p>
<h2>部署</h2>
<p>我们把编译好的文件传送到路由器中:</p>
<div class="highlight"><pre><span></span>scp mentohust [email protected]:/root
</pre></div>
<h3>安装libpcap</h3>
<p>路由器中默认没有我们依赖的<code>libpcap</code>库,我们要手动安装,先下载:</p>
<blockquote>
<p>http://www.viseator.com/file/libpcap_1.0.0-2_ar71xx.ipk</p>
</blockquote>
<p>然后传送到路由器中:</p>
<div class="highlight"><pre><span></span>scp libpcap_1.0.0-2_ar71xx.ipk [email protected]:/tmp
</pre></div>
<p>下面登陆路由器,进入<code>/tmp</code>目录,执行:</p>
<div class="highlight"><pre><span></span>opkg install libpcap_1.0.0-2_ar71xx.ipk
</pre></div>
<h3>新建wifi与桥接配置</h3>
<p>新刷的路由器只有一个默认接入点,我们先到路由器管理界面修改接入点。增加访问密码等等。这一步的配置就不多说了网上都有。</p>
<p>由于这个路由器只有一个接口,我们现在是将它作为<code>lan</code>口在用的,但是实际上我们需要使用它作为<code>wan</code>口来连接校园网认证上网,并且要将<code>lan</code>口与<code>wifi</code>进行桥接使得我们依旧可以通过<code>192.168.1.1</code>这个地址来管理路由器。</p>
<p>这步操作需要直接修改<code>/etc/config/network</code>文件,如果使用图形界面配置可能会导致变砖。</p>
<p>我们登陆路由器以后直接用<code>vim</code>修改上述文件:</p>
<div class="highlight"><pre><span></span>vim /etc/config/network
</pre></div>
<p>下面提供我找到的示例文件供参考:<a href="http://www.right.com.cn/forum/thread-105317-1-1.html">出处</a></p>
<div class="highlight"><pre><span></span>config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'lan'
option type 'bridge'
option proto 'static'
option ipaddr '192.168.1.1'
option netmask '255.255.255.0'
config interface 'wan'
option ifname 'eth0'
option _orig_ifname 'eth0'
option _orig_bridge 'false'
option proto 'dhcp'
option macaddr 'xx:xx:xx:xx:xx:xx'替换为自己的mac
</pre></div>
<p>修改后保存,然后<code>reboot</code>重启。</p>
<p>现在就不能通过有线来管理路由器了,因为管理地址已经桥接到了无线上了。所以我们要使用无线连接,有线接校园网,然后登陆到路由器。</p>
<p>找到我们存放<code>mentohust</code>的<code>/root</code>目录(默认就是),启动<code>mentohust</code>:</p>
<div class="highlight"><pre><span></span>./mentohust -u username -p password -n eth0
</pre></div>
<p>如果要后台运行加个<code>-b1</code>就可以了。</p>
<p>如果一切正常的话现在无线就可以正常上网了。</p>
</article>
<div class="tags">
<p>tags: <a href="/tag/openwrt.html">openwrt</a></p>
</div>
<hr>
</div>
</div>
</div>
<hr>
<!-- Footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<ul class="list-inline text-center">
<li>
<a href="https://github.com/HUSTMeituanClub">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-github fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="mailto:@hustmeituan.club">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
</ul>
<p class="copyright text-muted">
Blog powered by <a href="http://getpelican.com">Pelican</a>,
which takes great advantage of <a href="http://python.org">Python</a>.
</p> </div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="/theme/js/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="/theme/js/bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="/theme/js/clean-blog.min.js"></script>
</body>
</html>