在openwrt路由中加入n2n,并在ubuntu里加入n2n服务,实现开机联网互通互访

1、openwrt的硬件环境:

将自己的WR703N刷入openwrt(这里需要修改FLASH芯片,换个8M的FLASH);

刷机后,安装openwrt,此教程网上一大堆,无需说明了,TELNET进入,并开启SSH后,root登陆。

2、安装n2n到openwrt中:

[email protected]:~# opkg update

[email protected]:~# cat /etc/opkg.conf

[email protected]:~# opkg install n2n

运行上述命令即可安装n2n。

3、修改n2n的配置文件:

[email protected]:~# cat /etc/config/n2n

config edge

option ipaddr '10.10.100.191'

option supernode '106.186.30.16'

option port '9876'

option community 'leekwen'

option key 'leekwen'

option route '1'

4、修改n2n服务的启动脚本:

[email protected]:~# vi /etc/init.d/n2n

#!/bin/sh /etc/rc.common

# Copyright (C) 2008-2012 OpenWrt.org

START=90

start_instance() {

local cfg="$1"

config_get type "$cfg" TYPE

case "$type" in

edge)

config_get ipaddr "$cfg" 'ipaddr'

[ -n "$ipaddr" ] || return 1

config_get supernode "$cfg" 'supernode'

config_get port "$cfg" 'port'

config_get community "$cfg" 'community'

config_get key "$cfg" 'key'

config_get_bool route "$cfg" 'route' '0'

[ "$route" = "1" ] && args='-r'

service_start /usr/sbin/edge -f $args -a $ipaddr -c $community -k $key -l ${supernode}:${port} -M 1300

;;

supernode)

config_get port "$cfg" port

[ -n "$port" ] || return 1

service_start /usr/sbin/supernode -l $port

;;

esac

}

stop_instance() {

local cfg="$1"

config_get type "$cfg" TYPE

case "$type" in

edge)

service_stop /usr/sbin/edge

;;

supernode)

service_stop /usr/sbin/supernode

;;

esac

}

start() {

config_load 'n2n'

config_foreach start_instance 'edge'

config_foreach start_instance 'supernode'

}

stop() {

config_load 'n2n'

config_foreach stop_instance 'edge'

config_foreach stop_instance 'supernode'

}

5、将n2n加入openwrt系统启动项:

[email protected]:~# /etc/init.d/n2n enable

6、启动openwrt中的n2n服务:

[email protected]:~# /etc/init.d/n2n start

[email protected]:~# ifconfig edge0

edge0 Link encap:Ethernet HWaddr 86:CC:1B:E9:1A:DC

inet addr:10.10.100.191 Bcast:10.10.100.255 Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1300 Metric:1

RX packets:1117 errors:0 dropped:22 overruns:0 frame:0

TX packets:698 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:500

RX bytes:104415 (101.9 KiB) TX bytes:98732 (96.4 KiB)

7、互通测试:与我的手机端 n2n互ping下

[email protected]:~# ping 10.10.100.103

PING 10.10.100.103 (10.10.100.103): 56 data bytes

64 bytes from 10.10.100.103: seq=0 ttl=64 time=31.738 ms

64 bytes from 10.10.100.103: seq=1 ttl=64 time=25.347 ms

64 bytes from 10.10.100.103: seq=2 ttl=64 time=22.565 ms

64 bytes from 10.10.100.103: seq=3 ttl=64 time=40.063 ms

64 bytes from 10.10.100.103: seq=4 ttl=64 time=23.577 ms

^C

--- 10.10.100.103 ping statistics ---

6 packets transmitted, 5 packets received, 16% packet loss

round-trip min/avg/max = 22.565/19.838/31.738 ms

在ubuntu系统中增加n2n服务:

[email protected]:~$ svn co https://svn.ntop.org/svn/ntop/trunk/n2n

[email protected]:~$ cd n2n/

[email protected]:~/n2n$ ls

n2n_v1 n2n_v2

[email protected]:~/n2n$ cd n2n_v1/

[email protected]:~/n2n/n2n_v1$ ls

COPYING edge.8 HACKING lzoconf.h Makefile minilzo.h n2n.h openwrt scripts supernode.c tuntap_linux.c twofish.c win32

debian edge.c INSTALL lzodefs.h minilzo.c n2n.c n2n.spec README supernode.1 tuntap_freebsd.c tuntap_osx.c twofish.h

[email protected]:~/n2n/n2n_v1$ make

[email protected]:~/n2n/n2n_v1$ ./edge -h

Welcome to n2n v.1.3.2 for i686

Built on 04/23/15 06:11:56 PM

Copyright 2007-08 - http://www.ntop.org

edge -d -a -c -k -s [-u -g ][-f][-m ]

-l [-p ] [-M ] [-t] [-r] [-v] [-b] [-h]

-d | tun device name

-a | n2n IP address

-c | n2n community name

-k | Encryption key (ASCII) - also N2N_KEY=

-s | Edge interface netmask in dotted decimal notation (255.255.255.0)

-l | Supernode IP:port

-b | Periodically resolve supernode IP

| (when supernodes are running on dynamic IPs)

-p | Local port used for connecting to supernode

-u | User ID (numeric) to use when privileges are dropped

-g | Group ID (numeric) to use when privileges are dropped

-f | Fork and run as a daemon. Use syslog.

-m | Choose a MAC address for the TAP interface

| eg. -m 01:02:03:04:05:06

-M | Specify n2n MTU (default 1400)

-t | Use http tunneling (experimental)

-r | Enable packet forwarding through n2n community

-v | Verbose

Environment variables:

N2N_KEY | Encryption key (ASCII)

[email protected]:~/n2n/n2n_v1$ pwd

/home/Leekwen/n2n/n2n_v1

2、下载并编译完毕后,编写启动服务文件n2n:

[email protected]:~/n2n/n2n_v1$ vi n2n

#!/bin/bash

##Some Variable define here ##

PROG="edge"

n2n_IP="10.10.100.103"

n2n_cname="leekwen"

n2n_pass="leekwen"

SNODE_Host="106.186.30.16"

SNODE_Port="9876"

LOGS="/var/log/$PROG.log"

PROG_PATH="/home/leekwen/n2n/n2n_v1" # edge binary put on here for testing this script, Not Needed if the system binary.

PROG_ARGS="-f -d edge0 -a $n2n_IP -c $n2n_cname -k $n2n_pass -l $SNODE_Host:$SNODE_Port -M 1300"

PID_PATH="/var/run"

RETVAL=0

start() {

pid=`ps ax | grep $PROG | grep -v "grep" | awk '{print $1}'`

if [ ! -z "$pid" ]; then

## Program is running, exit with error.

echo "Error! $PROG is currently running!" 1>&2

exit 1

else

## Change from /dev/null to something like /var/log/$PROG if you want to save output.

$PROG_PATH/$PROG $PROG_ARGS 2>&1 > $LOGS &

echo "$PROG started"

echo $pid > "$PID_PATH/$PROG.pid"

fi

RETVAL=$?

if [ $RETVAL -eq 0 ]; then

echo -e "\\033[60G\c"

echo -e "[ \\033[1;32m\c"

echo -e "OK\c"

echo -e "\\033[0;39m\c"

echo " ]"

else

echo -e "\\033[60G\c"

echo -e "[ \\033[1;31m\c"

echo -e "FAILED\c"

echo -e "\\033[0;39m\c"

echo " ]"

fi

return $RETVAL

}

stop() {

pid=`ps ax | grep $PROG | grep -v "grep"| awk '{print $1}'`

if [ ! -z "$pid" ]; then

## Program is running, so stop it

kill $pid

rm -f "$PID_PATH/$PROG.pid"

echo "$PROG stopped"

else

## Program is not running, exit with error.

echo "Error! $PROG not started!" 1>&2

exit 1

fi

RETVAL=$?

if [ $RETVAL -eq 0 ]; then

echo -e "\\033[60G\c"

echo -e "[ \\033[1;32m\c"

echo -e "OK\c"

echo -e "\\033[0;39m\c"

echo " ]"

else

echo -e "\\033[60G\c"

echo -e "[ \\033[1;31m\c"

echo -e "FAILED\c"

echo -e "\\033[0;39m\c"

echo " ]"

fi

return $RETVAL

}

## Check to see if we are running as root first.

## Found at http://www.cyberciti.biz/tips/shell-root-user-check-script.html

if [ "$(id -u)" != "0" ]; then

echo "This script must be run as root, you can use sudo command to run it." 1>&2

exit 1

fi

case "$1" in

start)

start

exit 0

;;

stop)

stop

exit 0

;;

reload|restart|force-reload)

stop

start

exit 0

;;

**)

echo "Usage: $0 {start|stop|reload}" 1>&2

exit 1

;;

esac

3、增加可执行权限,移动n2n服务到/etc/init.d/,并更新rc.d

[email protected]:~/n2n/n2n_v1$ chmod 755 n2n

[email protected]:~/n2n/n2n_v1$ sudo mv n2n /etc/init.d/

[email protected]:~/n2n/n2n_v1$ sudo update-rc.d n2n defaults

4、对n2n服务进行测试:

[email protected]:~/n2n/n2n_v1$ /etc/init.d/n2n start

[email protected]:~/n2n/n2n_v1$ ifconfig edge0

[email protected]:~/n2n/n2n_v1$ /etc/init.d/n2n stop

[email protected]:~/n2n/n2n_v1$ ifconfig edge0

[email protected]:~/n2n/n2n_v1$ /etc/init.d/n2n restart

[email protected]:~/n2n/n2n_v1$ ifconfig edge0

5、对n2n服务进行Ping连通性测试:

[email protected]:~/n2n/n2n_v1$ ping 10.10.100.103

PING 10.10.100.103 (10.10.100.103): 56 data bytes

64 bytes from 10.10.100.103: seq=0 ttl=64 time=11.738 ms

64 bytes from 10.10.100.103: seq=1 ttl=64 time=15.347 ms

64 bytes from 10.10.100.103: seq=2 ttl=64 time=12.565 ms

64 bytes from 10.10.100.103: seq=3 ttl=64 time=10.063 ms

64 bytes from 10.10.100.103: seq=4 ttl=64 time=13.577 ms

^C

--- 10.10.100.103 ping statistics ---

5 packets transmitted, 5 packets received, 0% packet loss

round-trip min/avg/max = 10.063/12.838/15.347 ms

到此客户端的已经安装成功,在网络连接的情况下,每次重启ubuntu及openwrt路由后,他们都会自动连接上supernode节点,以构建一个p2p的网络。

原文:http://blog.csdn.net/leekwen/article/details/45244551

openwrt运行n2n服务器,在openwrt路由中加入n2n,并在ubuntu里加入n2n服务,实现开机联网互通互访...相关推荐

  1. 产品运行所需的信息检索失败_为服务业注入新活力,华北工控推出服务机器人专用计算机产品方案...

    近年来,随着人口老龄化趋势加快和信息科技革命的持续推进,服务机器人已经被当作社会劳动力的一部分在医疗.教育.餐饮等行业广泛应用,市场潜力巨大. 01.需求带动消费,科技改变服务 服务机器人是国内智能机 ...

  2. 软路由中OpenWRT的dnsmasq配置

    旁路由的好处在于,即使旁路由挂了,也不影响主路由正常上网.设备接入旁路由之后,自动获取IP,可以享受广告过滤以及特殊上网需求. 接入的设备,如果有特殊的需要,比如广告过滤,就需要把当前的接入设备手动设 ...

  3. linux音乐服务器mpd,OpenWRT中使用mpd作为音频Server及其使用

    说明 MPD可以播放音乐与streaming Radio,可以用于娱乐用.其官网的说法为: Music Player Daemon (MPD) is a flexible, powerful, ser ...

  4. HG255d通过U盘搭载php服务器,转:利用block-extroot,让你的openwrt运行在USB设备上。...

    一.我需要这个功能吗? 如果你对跑openwrt的设备的要求仅仅是可以上上网,那下面的可以不用看了. openwrt运行在USB设备上的好处: 可以安装openwrt官方的N多软件了(但官方暂时没有m ...

  5. 基于Sane成功解决路由器改OpenWrt打印扫描服务器的手机移动端(IOS、Android)扫描功能实现问题

    1.前言 家里有一台HP打印扫描一体机HP DJ 2300 series PCL-3,不具备打印和扫描功能.之后买了一个TPlink的wr703n路由器,刷了OpenWrt系统,安装p910nd,通过 ...

  6. 交叉编译openwrt php,交叉编译n2n,以openwrt为例子

    交叉编译n2n,以openwrt为例子 预备知识 1 什么是交叉编译? 1.1 本地编译 简单粗暴的解释一下,在当前架构的pc下,直接由编译工具编译生成的程序或者是库文件,可以直接在当前的环境运行.这 ...

  7. pandora固件运行c语言,PandoraBox(OpenWrt)配置(做为二级交换机方法)

    现在不少国产路由器,如小米.联想.华硕.斐讯等都可以刷潘多拉固件,虽然刷起来简单,但是刷之后面对一堆密密麻麻的陌生参数,离正常使用还有段距离,这篇文章就介绍下如何配置刚刷完PandoraBox或者Op ...

  8. 基于OpenWrt的PPTP服务器

    前言 在智能家居系统中,有一块比较重要的就是室内摄像头. 结合上个月底做的--基于FFmpeg的android摄像头视频流媒体广播,再结合基于OpenWrt系统的智能路由器+PPTP服务器,可以使外部 ...

  9. K2P K2 OpenWrt 搭配光猫单臂路由上网

    K2P K2 OpenWrt 搭配光猫单臂路由上网 K2P OpenWrt 搭配光猫单臂路由上网 Openwrt 21.02后版本(网桥) Openwrt 21.02前版本 K2 OpenWrt 搭配 ...

  10. 路由器刷mysql_路由器刷OpenWrt打造全能服务器(七)安装mysql

    Netgear wndr3700v2 路由器刷OpenWrt打造全能服务器(七)安装mysql 1. SecureCrt连接到路由器. 2.安装mysql opkg update opkg insta ...

最新文章

  1. 【python】点分十进制ip与数字互转
  2. java 的序列化和反序列化的问题
  3. 图片显示时加水印(不改变原图片)
  4. SpringSecurity使用自定义认证页面
  5. mysql upgrade 失败_`mysql_upgrade`失败,没有给出真正的理由
  6. Spyder kernel died 错误
  7. 三、Express 路由
  8. oralce load的时候使用触发器会导致load慢吗_你真的了解性能压测中的SLA吗?
  9. 修改Oracle最大连接数
  10. Python学习之路-基础知识1
  11. 网络GHOST使用方法
  12. 本科计算机技术与应用知识点,《软件工程》经典考试例题题,重点的知识点(含答案)...
  13. 自学数据科学机器学习,19个数学和统计学公开课推荐
  14. Python 网络数据采集
  15. 第四届江西省高校网络安全技能大赛初赛WebMisc—Writeup
  16. 有关arcmap的学习使用心得
  17. ubuntu18.04修改ip地址
  18. 读《深入浅出MySQL数据库开发、优化与管理维护(第2版)》笔记1
  19. 齐二TK6916/20/26/32系列数控落地铣镗床简介2
  20. L1-068 调和平均 (10 分)

热门文章

  1. webpack重复打包同名依赖包
  2. 安全防范知识点 -- CSRF
  3. 缓存和数据库刷新的顺序 及阿里OCS介绍
  4. [蓝桥杯2018决赛]阅兵方阵
  5. 技巧推荐 PDF文件怎么转成word文档
  6. mysql的explain执行计划_MySQL之Explain(执行计划)
  7. 电子计算机的基本概念简述
  8. 清理服务器系统日志,win2008服务器清理系统日志
  9. EasyUI filebox 限制文件上传的类型
  10. Linux 下修改时间和时区