OpenWRT总结整理

一、OpenWrt介绍
OpenWrt社区聚集了一大批纯正的Linux各个方向的死忠级专家,从而使OpenWrt具备了如下与传统NorFlash嵌入式Linux截然不同的高级特征:

1、SquashFS与JFFS2文件系统的整合形成的overlayfs机制

对用户而言,OpenWrt的整个文件系统是完全动态可读写的,而其中的固件部分是用SquashFS实施的只读压缩文件系统,而用户所有的对文件系统的增删改都是用类似“差值”的形态存储在JFFS2文件系统中的,二者用overlayfs机制黏合,对用户完全透明。因此我们可以在文件系统中肆意发挥、随便折腾,出现任何问题则可像手机一样恢复出厂设置,并提供fail-safe模式帮助用户修复系统。

而在传统的嵌入式Linux里,固件是静态的,对系统做任何一点与可运行程序相关的变动,比如增加一个模块,删除一个应用程序,都要重新编译全部固件,并重新刷写,就好比你一个Android手机要升级微信就要重新刷机。这种反人类的传统文件系统完全阻挡了非专业爱好者进入嵌入式Linux这一领域。

2、UCI(Unified Configuration Interface)

帮助用户在任何平台的OpenWrt上用同样的方法配置系统、网络和应用。在Boardcom的平台上,在Atheros的平台上,甚至x86的平台上,修改系统配置均为同样的命令。而UCI的机制并不是二进制硬件虚拟层实现的,是由Linux shell脚本实现的。这毫无疑问是一种别致的创新,比Android来的轻巧得多。OpenWrt里的Linux shell脚本用得很帅很高端,那种感觉怎么形容呢?就好像精通十八般武艺的高手有一天特别复古地拿起铅笔刀在硬盘上刻出来了系统,就是这种感觉。

3、Opkg包管理系统与丰富的软件源

是一个与桌面级Linux使用的apt-get、yum等同级别的包管理系统,使用形如:opkg install xxxx-app的命令从互联网软件源中安装大约3000余种各种软件。3000款软件,数量没法跟手机的应用市场比,但是要知道,这里头的任何一个软件都来头不小,是经过Linux社区千锤百炼的东西,一个应用折腾一个月都玩不够。类型覆盖网络、音频、视频、编程开发、Linux系统管理等。当然,如果是专业比较偏的东西OpenWrt的软件源里还是不够完善,比如笔者团队用到的OpenCV的东西,源里就没有,就靠自己交叉编译了。

4、Luci WEB界面系统

除CLI命令行终端界面外,不同于桌面级Linux使用屏幕GUI作为交互界面,OpenWrt使用WEB界面交互。而不同于传统路由器web管理界面的是,luci是用户可订制的,安装了支持luci的软件后,WEB界面系统就中出现了新的模块,而opkg本身也web化了。这个特征让用户感觉很像手机的app store。

 
二、openwrt 的jffs2和squafs两个版本的区别

 官方下载的都分jffs2和squafs两种格式,jffs2文件系统格式是适合于断电的系统,不像FAT那样容易丢文件,因为路由器一般都容易突然断电。官方的jffs2格式刷到路由器后就是一个jffs2分区,ROM本身和以后安装的软件都在这个分区里都可以读写。而squafs格式则是把ROM压缩到了一个文件刷进路由器,然后剩下的空间格式化成jffs2并且优先于ROM文件,有点像WM手机上的情况。ROM只 读分区挂在/rom下,而另一个可读写jffs2分区挂到/overlay,当/overlay下有和/rom同名的文件就优先读这个,相当于覆盖了 ROM文件,实际上并没有覆盖。这种情况的优点是ROM压缩率高,可写分区就更大一点,其次只要备份/overlay就可以把ROM以为的所有文件都备份 下来,以后全部还原就可以不用重新配置了。格式化/overlay分区就相当于恢复openwrt出厂设置了。官方推荐squafs,因为这种格式就算配置乱了还可以恢复刷机后的出厂设置,二是压缩后节省空间。jffs2格式搞乱了就只能重刷了。

 几个不同版本的说明:
sysupgrade版:已经刷了openwrt固件,可用sysupgrade版本在OPENWRT的web页面内升级
tftp版:适用于目前是原厂固件或者ddwrt固件下tftp方式刷入
factory版:此固件适用于直接在官方原厂固件下web方式刷入

 brcm是指CPU方面的通用版本,jffs2是指文件系统可写,但是较大,squashfs是只读文件系统,但是压缩后很小。*.trx和*.bin;一般说来,trx的是通用的版本,bin是为一些设备支持提供的文件,使它符合一些设备的特性。

 分清两个文件factory和sysupgrade的区别,factory固件包含art部分,是从原厂固件升级到op用的,可以在路由器原版固件界面直接软升级,亦或是使用TTL方式刷入路由器,sysupgrade仅包含firmware部分,是已经是op的情况下升级固件用的,除非你对编程器非常了解,否则不推荐使用TTL方式刷入,升级最好的方式就是OpenWRT自带的sysupgrade功能,其次也可以使用mtd命令.当使用原版固件刷固件之后,第一次登录它只有 telnet 被启动,只有设置好root的密码后,我们才可以SSH进行操作

三、刷机方法
0、NVRAM是Non-Volatile RAM,在OpenWrt里面是用了Flash Rom的最后64KB区块,用于存储一些配置参数。
NVRAM操作
显示所有参数:
# nvram show
# nvram show | grep wl0_

设置:
# nvram set <param>=<value>
# nvram set lan_ipaddr=192.168.1.2
# nvram commit
# reboot

删除一些参数:
# nvran unset <param>

提交修改:
# nvram commit

清空nvram
如果变砖头了需要清空nvram, 30/30/30方法:最保险的方式。推荐。mtd方式。
30/30/30方法,首先确保dd-wrt里面开了reset功能,然后:
    接通路由器,按住复位30秒
    不要松开,断开电源,按住30秒
    不要松开,重新接通,按住30秒

1、MTD方式
(1)MTD技术的基本原理
MTD(memory technology device内存技术设备)是用于访问memory设备(ROM、flash)的Linux的子系统。MTD的主要目的是为了使新的memory设备的驱动更加简单,为此它在硬件和上层之间提供了一个抽象的接口,并进行了一个层次划分,层次从上到下大致为:设备文件、MTD设备层、MTD原始设备层、硬件驱动层。MTD的所有源代码在/drivers/mtd子目录下。

(2)Migrate from DD-WRT to OpenWrt
0.准备好对应路由型号的OpenWrt firmware image,下载xxx..xxx_sysupgrade.bin并加入hsf.exe(note:use the sysupgrade image, which is the same as the tftp, just without the header.)

1.30-30-30 factory reset,登录192.168.1.1,Enable SSH on the router ,默认用户名root,密码admin

2.电脑通过网线连接路由器LAN口,并关闭其他无线连接和防火墙

3.将本地IP地址设置为 192.168.1.2,子网掩码为255.255.255.0

4.Login to the router via SSH

5.查看MTD情况
root@DD-WRT:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00010000 "RedBoot"
mtd1: 003a0000 00010000 "linux"
mtd2: 002c8000 00010000 "rootfs"
mtd3: 00020000 00010000 "ddwrt"
mtd4: 00010000 00010000 "nvram"
mtd5: 00010000 00010000 "board_config"
mtd6: 00400000 00010000 "fullflash"
mtd7: 00040000 00010000 "fullboot"
mtd8: 00010000 00010000 "uboot-env"

6. Change directory to /tmp and download OpenWrt firmware image file onto the router
root@DD-WRT:~# cd /tmp
root@DD-WRT:/tmp# wget http://192.168.1.2/openwrt-ar71xx-generic-whr-g301n-squashfs-sysupgrade.bin
Connecting to 192.168.1.2 (192.168.1.2:80)
openwrt-ar71xx-gener 100% |*******************************|  3200k  0:00:00 ETA

7.Overwrite current firmware.Whereas all OpenWRT instructions will tell you to write to the ‘firmware‘ partition, this does not exist on DD-WRT and you have to use the ‘linux‘ partition instead. Note the ‘-r’ argument will reboot the router as soon as the flash is complete.  (As usual, do not power off or disconnect during the flashing!).

root@DD-WRT:/tmp# mtd
Usage: mtd [<options> ...] <command> [<arguments> ...] <device>

The device is in the format of mtdX (eg: mtd4) or its label.
mtd recognizes these commands:
        unlock                  unlock the device
        erase                   erase all data on device
        write <imagefile>|-     write <imagefile> (use - for stdin) to device
Following options are available:
        -q                      quiet mode (once: no [w] on writing,
                                           twice: no status messages)
        -r                      reboot after successful command
        -f                      force write without trx checks
        -e <device>             erase <device> before executing the command

Example: To write linux.trx to mtd4 labeled as linux and reboot afterwards
         mtd -r write linux.trx linux

root@DD-WRT:/tmp# mtd -r write openwrt-ar71xx-generic-whr-g301n-squashfs-sysupgrade.bin linux
                或mtd -e linux -r write openwrt-ar71xx-generic-whr-g301n-squashfs-sysupgrade.bin linux
mtd -e linux -r write openwrt-ar71xx-generic-whr-g301n-squashfs-sysupgrade.bin linux

root@DD-WRT:/tmp# mtd -e linux -r write openwrt-ar71xx-generic-whr-g301n-squashfs-sysupgrade.bin linux
Unlocking linux ...
Erasing linux ...
Writing from openwrt-ar71xx-generic-whr-g301n-squashfs-sysupgrade.bin to linux ...  [w]

Connection closed by foreign host.

8.After flashing, the router should go down for a reboot and return running OpenWrt.
  等待reboot完后,使用telnet登入,添加密码以开启SSH服务(dropbear开始运行),命令依次如下:
telnet 192.168.1.1
passwd admin
passwd admin
即可为root用户添加密码admin。

web登录192.168.1.1 luci
9.Login to the router via SSH

10.查看刷新后的MTD情况
root@OpenWrt:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 0003e000 00010000 "u-boot"
mtd1: 00002000 00010000 "u-boot-env"
mtd2: 003a0000 00010000 "firmware"
mtd3: 0010e49f 00010000 "kernel"
mtd4: 00291b61 00010000 "rootfs"
mtd5: 00080000 00010000 "rootfs_data"
mtd6: 00010000 00010000 "art"

dmesg
uname -a
iptables -V


11.用UCI配置无线和有线网络(https://downloads.openwrt.org/kamikaze/docs/openwrt.html,http://wiki.openwrt.org/doc/uci,http://wiki.openwrt.org/doc/uci/network)
在我们将路由器固件刷成开源的基于Linux内核的openwrt系统后,由于openwrt默认未安装WEB管理界面,所以我们需要先通过SSH或者telnet对路由器进行网络设置,设置完成后可通过openwrt的软件包管理opkg安装web设置界面Luci。
不管你是采用文本编辑器还是通过命令行的方式修改了UCI配置文件,相应的服务或应用程序不会自动更新状态,这时你都必须调用一次/etc/init.d/xxx (re)start才能使刚刚对UCI配置文件的修改生效.
    /etc/config/dhcp
    /etc/config/dropbear
    /etc/config/firewall
    /etc/config/network
    /etc/config/system
    /etc/config/timeserver
    /etc/config/wireless

cat /etc/config/network
root@OpenWrt:~# cat /etc/config/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 'fd7a:cd28:ab3c::/48'

config interface 'lan'
    option ifname 'eth0'
    option force_link '1'
    option type 'bridge'
    option proto 'static'
    option netmask '255.255.255.0'
    option ip6assign '60'
    option ipaddr '192.168.10.1'
    option mtu '1492'

config interface 'wan'
    option ifname 'eth1'
    option _orig_ifname 'eth1'
    option _orig_bridge 'false'
    option proto 'static'
    option ipaddr '192.168.1.66'
    option netmask '255.255.255.0'
    option gateway '192.168.1.1'
    option dns '101.226.4.6 123.125.81.6 192.168.1.1'
    option mtu '1492'

config interface 'wan6'
    option ifname '@wan'
    option proto 'dhcpv6'

config switch
    option name 'switch0'
    option reset '1'
    option enable_vlan '1'

config switch_vlan
    option device 'switch0'
    option vlan '1'
    option ports '0 1 2 3 4'

cat /etc/config/wireless
config wifi-device 'radio0'
    option type 'mac80211'
    option channel '11'
    option path 'pci0000:00/0000:00:00.0'
    option htmode 'HT20'
    option txpower '10'
    option country 'CN'
    option hwmode '11ng'

config wifi-iface
    option device 'radio0'
    option network 'lan'
    option mode 'ap'
    option ssid 'OpenWrt'
    option encryption 'psk2'
    option key 'p.....'
    option hidden '1'
 
 
 root@OpenWrt:~# cat /etc/config/dropbear

config dropbear
    option PasswordAuth 'on'
    option Interface 'lan'
    option Port '30335'


登陆:ssh 192.168.1.1
一、让设备联网
包括三种模式: 一是pppoe模式。一种是二级路由模式、一种是交换机模式

root@OpenWrt:~# uci
Usage: uci [<options>] <command> [<arguments>]

Commands:
    batch
    export     [<config>]
    import     [<config>]
    changes    [<config>]
    commit     [<config>]
    add        <config> <section-type>
    add_list   <config>.<section>.<option>=<string>
    del_list   <config>.<section>.<option>=<string>
    show       [<config>[.<section>[.<option>]]]
    get        <config>.<section>[.<option>]
    set        <config>.<section>[.<option>]=<value>
    delete     <config>[.<section>[[.<option>][=<id>]]]
    rename     <config>.<section>[.<option>]=<name>
    revert     <config>[.<section>[.<option>]]
    reorder    <config>.<section>=<position>

Options:
    -c <path>  set the search path for config files (default: /etc/config)
    -d <str>   set the delimiter for list values in uci show
    -f <file>  use <file> as input instead of stdin
    -m         when importing, merge data into an existing package
    -n         name unnamed sections on export (default)
    -N         don't name unnamed sections
    -p <path>  add a search path for config change files
    -P <path>  add a search path for config change files and use as default
    -q         quiet mode (don't print error messages)
    -s         force strict mode (stop on parser errors, default)
    -S         disable strict mode
    -X         do not use extended syntax on 'show'

1.1 pppoe用户:(通常家庭拨号用户采用这种模式)
#分配网卡
#uci set network.wan.ifname=eth0
#设置wan口类型为pppoe
uci set network.wan.proto=pppoe
#设置pppoe拨号用户名和密码、mtu
uci set network.wan.username=xxxxx
uci set network.wan.password=xxxxxx
uci set network.wan.mtu=1492
#设置lan ip(即访问路由的ip)
uci set network.lan.ipaddr=192.168.1.1


1.2二级路由模式(非DHCP获取):(通常是你在家里的主拨号路由器后面再接一个二级路由)
#设置lan ip(即访问路由的ip,与一级路由不同网段)
uci set network.lan.proto=static
uci set network.lan.ipaddr=192.168.10.1

#设置wan口类型为静态
uci set network.wan.proto=static
#设置wan ip
uci set network.wan.ipaddr=192.168.1.66
uci set network.wan.netmask=255.255.255.0
#网关指向上级路由
uci set network.wan.gateway=192.168.1.1
#dns指向上级路由
uci set network.wan.dns=192.168.1.1
uci add_list network.wan.dns=
uci add_list network.wan.dns=
uci add_list network.wan.dns=

1.3交换机模式(当交换机用,WAN口空置)
#关掉wan
uci set network.wan.proto=none
#设置lan ip(本路由登陆IP)
uci set network.lan.ipaddr=192.168.1.100
#网关指向上级路由
uci set network.lan.gateway=192.168.1.1
#dns指向上级路由
uci set network.lan.dns=192.168.1.1
#关掉lan的dhcp
uci set dhcp.lan.ignore=1


2.配置无线网络
#打开无线
uci set wireless.@wifi-device[0].disabled=0
#设置功率为17dbm
uci set wireless.@wifi-device[0].txpower=17
#设置无线信道为8
uci set wireless.@wifi-device[0].channel=8
#设置无线模式为ap
uci set wireless.@wifi-iface[0].mode=ap
#设置无线SSID
uci set wireless.@wifi-iface[0].ssid=xxxxxx
#无线链接到lan上
uci set wireless.@wifi-iface[0].network=lan
#设置加密为WPA2-PSK
uci set wireless.@wifi-iface[0].encryption=psk2
#设置无线密码
uci set wireless.@wifi-iface[0].key=xxxxx
#1 disables broadcasting of the ssid
uci set wireless.@wifi-iface[0].hidden=1
uci set wireless.@wifi-device[0].hwmode=11ng


3.应用配置:
#应用提交
uci commit

#重新启动网络
/etc/init.d/network restart

二、安装组件
当网络配置完成后,就可以通过网络安装你需要的软件包了。
#查看已安装软件包安装luci管理界面
opkg list-installed
#更新软件包(opkg install *.ipk//在線安裝軟件包 opkg remove //移除軟件包)
opkg update

#安装luci的web配置界面
opkg install luci
#支持中文
opkg install luci-i18n-chinese 

#启动uhttpd服务,并设置其为自启动
#开机自启动
/etc/init.d/uhttpd enable
#立刻启动uhttpd
/etc/init.d/uhttpd start

12.
root@OpenWrt:~# cat /etc/openwrt_release
DISTRIB_ID="OpenWrt"
DISTRIB_RELEASE="14.07"
DISTRIB_REVISION="r42625"
DISTRIB_CODENAME="barrier_breaker"
DISTRIB_TARGET="ar71xx/generic"
DISTRIB_DESCRIPTION="OpenWrt Barrier Breaker 14.07"
DISTRIB_TAINTS=""

官方配置
/etc/opkg.conf

dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
src/gz barrier_breaker_base http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/base
src/gz barrier_breaker_luci http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/luci
src/gz barrier_breaker_management http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/management
src/gz barrier_breaker_oldpackages http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages
src/gz barrier_breaker_packages http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/packages
src/gz barrier_breaker_routing http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/routing
src/gz barrier_breaker_telephony http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages/telephony



openwrt国内镜像站
http://mirror.lzu.edu.cn/openwrt
http://mirrors4.ustc.edu.cn/openwrt
http://mirrors.ustc.edu.cn/openwrt
http://ubuntu.uestc.edu.cn/openwrt/


root@OpenWrt:~# cat /etc/opkg.conf
dest root /
dest ram /tmp
lists_dir ext /var/opkg-lists
option overlay_root /overlay
src/gz barrier_breaker_base http://mirrors.ustc.edu.cn/openwrt/barrier_breaker/14.07/ar71xx/generic/packages/base
src/gz barrier_breaker_luci http://mirrors.ustc.edu.cn/openwrt/barrier_breaker/14.07/ar71xx/generic/packages/luci
src/gz barrier_breaker_packages http://mirrors.ustc.edu.cn/openwrt/barrier_breaker/14.07/ar71xx/generic/packages/packages
src/gz barrier_breaker_routing http://mirrors.ustc.edu.cn/openwrt/barrier_breaker/14.07/ar71xx/generic/packages/routing
src/gz barrier_breaker_telephony http://mirrors.ustc.edu.cn/openwrt/barrier_breaker/14.07/ar71xx/generic/packages/telephony
src/gz barrier_breaker_management http://mirrors.ustc.edu.cn/openwrt/barrier_breaker/14.07/ar71xx/generic/packages/management
src/gz barrier_breaker_oldpackages http://mirrors.ustc.edu.cn/openwrt/barrier_breaker/14.07/ar71xx/generic/packages/oldpackages


(3)update OpenWrt
    sysupgrade xxx.bin #使用sysupgrade更新系统,推荐。
    或mtd -r write xxx.bin firmware


1、千万不能从openwrt强刷ddwrt(web、mtd方式、tftp方式),会变砖
2、openwrt下使用whr-g300nv2-openwrt-to-dd.bin从web ui升级,可刷回dd,再升级最新的dd
3、变砖后TFTP刷机方法(ping不通也可以救回)

准备:tftp版固件,ubuntu系统(windows或indows下虚拟机不可行),ubuntu系统安装好tftp,用户目录下传好固件。
TFTP安装
sudo apt-get update
sudo apt-get install tftp
yum  install  tftp
1、路由器关闭拔掉电源线,路由器的lan口与计算机网口用网线相连接
2、关闭计算机其他网络,设置计算机的IP为192.168.11.2
sudo service network-manager  stop (这步很重要)
sudo ifconfig eth0 192.168.11.2
sudo ifconfig eth0 netmask 255.255.255.0 (此步可以省略)
sudo arp -s 192.168.11.1 00:24:A5:34:0B:AC (路由器背面的SSID)
3、进入固件存放的目录并tftp固件
cd ~
tftp 192.168.11.1 
tftp> verbose
tftp> binary
tftp> trace
tftp> rexmt 1
tftp> timeout 60
tftp> put tftp版固件名 (回车后迅速接通路由器电源,等待数据上传)

如果一切正常,屏幕会有这样的显示。
sent DATA
received ACK
固件上传成功后会自动重启,DIAG灯会频繁闪动一会儿,等待几分钟后DIAG熄灭,其他灯恢复正常,路由器就救活了。再用牙签复位一下,进windows下用192.168.1.1或192.168.11.1进入路由就可以!



OpenWrt的两种模式:桥接模式与路由模式
1、桥接模式(Bridged AP Mode ):通过OpenWrt 设备做桥,连接到OpenWrt的无线设备是由此网段192.168.1.0网段中的路由来分配IP地址的,所以此网段中的所有设备都是互通互连的!http://wiki.openwrt.org/doc/recipes/bridgedap
2、路由模式(Routed AP Mode):OpenWrt 设备做路由时,连接到OpenWrt的无线设备是由OpenWrt路由设备本身来分配IP地址的,所以通过无线连接到OpenWrt网段中的所有设备都与原来的192.168.1.0网段的设备不通(OpenWrt设备本身除外)http://wiki.openwrt.org/doc/recipes/routedap

无线路由器两种模式,一种是桥接Bridge,另一种是中继Repeater
两种模式的主要不同点在于:对于中继模式, 从某一接入点接收的信息包可以通过WDS连接转发到另一个接入点。然而桥接模式,通过WDS连接接收的信息包只能被转发到有线网络或无线主机。换句话说,只有中继模式可以进行WDS到WDS信息包的转发。
连接到Bridge1或Bridge3的主机可以通过WDS链接和连接到桥2的主机通信。但是,连接到Bridge1的主机无法透过Bridge2与Bridge3主机相通。


arptables和ebtables,分别过滤arp协议包和以太网帧。而iptables过滤ip数据报。
用iptables能不能实现arptables的功能呢? 当然不能。 因为当需要发送一个数据包到未知目的MAC地址的时候,数据包完成网络层的封装,封装到数据链路层,因为不知道目的MAC地址,会触发ARP请求,请求目的IP地址的MAC地址。 由此可见ARP协议是当数据包在数据链路层需要往外发送的时候体现它的作用的,而iptables只是工作在网络层的,对这个根本不能控制。

iptables
http://www.netfilter.org/
http://man.cx/iptables
arptables
http://man.cx/arptables
ebtables
http://ebtables.netfilter.org/
http://man.cx/ebtables
nftables
http://www.netfilter.org/


cat /proc/net/arp
#列出规则
arptables -L

#删除所有规则
arptables -F

#设置默认策略,默认拒绝所有主机的arp查询
  arptables -P INPUT DROP

#查看网关的MAC地址:
 arp -n | grep 192.168.1.1

#添加静态ARP
arp -s  192.168.1.1  MAC地址

1.安装ip-full和 net-tools-arp
2.arp 查看网关的MAC
3. ip neigh show 启动项选项中自定义脚本界面,添加下面两条命令
  ip neigh add 192.168.1.1 lladdr a8:15:4d:ba:c4:b2 dev eth1 nud permanent
  ip neigh change 192.168.1.1 lladdr a8:15:4d:ba:c4:b2 dev eth1 nud permanent
4. flags从2变为0x6(主机在关机状态下,不活动的ARP表flag是0,活动的主机ARP表的flag标签是2,更改成静态的后标签flag是6。)
root@OpenWrt:~# arp 或cat /proc/net/arp
IP address       HW type     Flags       HW address            Mask     Device
192.168.10.135   0x1         0x2         00:21:00:1a:59:fd     *        br-lan
192.168.10.199   0x1         0x2         f8:a4:5f:52:a4:55     *        br-lan
192.168.1.1      0x1         0x6         a8:15:4d:ba:c4:b2     *        eth1



root@OpenWrt:~# arping
Usage: arping [-fqbDUAV] [-c count] [-w timeout] [-I device] [-s source] destination
  -f : quit on first reply
  -q : be quiet
  -b : keep broadcasting, don't go unicast
  -D : duplicate address detection mode
  -U : Unsolicited ARP mode, update your neighbours
  -A : ARP answer mode, update your neighbours
  -V : print version and exit
  -c count : how many packets to send
  -w timeout : how long to wait for a reply
  -I device : which ethernet device to use (eth0)
  -s source : source ip address
  destination : ask for what ip address

1.arping命令可以用来测试局域网各个主机之间的连通性,不能用于测试其是否能与互联网连通
arping -I eth1 192.168.1.1 -w 5
2.arping命令可以用来测试局域网中某个特定的IP地址是否已经被占用
arping -I eth1 -D 192.168.1.1 -w 5
添加一条记录允许网关的arp查询:
 arptables -A INPUT --source-mac 同网段其它服务器MAC地址 -j ACCEPT
 arptables -A INPUT -s 192.168.10.0/24 -j ACCEPT
 arptables -A INPUT -s 192.168.1.1 --source-mac 7A:31:14:42:10:01 -j ACCEPT


在eth0上如果源IP是192.168.1.10,并且源MAC不是00:17:A4:A8:68:11的话,就禁止这个数据桢。
arptables -A INPUT -i eth0 --src-ip 192.168.1.10 --src-mac ! 00:17:A4:A8:68:11 -j DROP

在eth0上如果源MAC不是00:24:51:E9:C7:10(网关的MAC地址),就禁止这个数据桢,这一条针对外网过来的访问。
arptables -A INPUT -i eth0 --src-mac ! 00:24:51:E9:C7:10 -j DROP
注意:添加arp防火墙策略的次序不能错,针对网关MAC地址的语句必须放在最后,否则本网段IP的访问策略不能生效。

/etc/init.d/arptables restart


ebtables -h #查看命令

ebtables -t nat -A PREROUTING -p arp --arp-opcode Request  --arp-ip-src 192.168.10.0/24 -j arpreply --arpreply-mac 00:24:A5:34:0B:AC --arpreply-target ACCEPT
 
ebtables -t nat -A PREROUTING -p arp --arp-opcode Request  --arp-ip-src 192.168.1.1 --arp-mac-src  a8:15:4d:ba:c4:b2
 -j arpreply --arpreply-mac 00:24:A5:34:0B:AC --arpreply-target ACCEPT





 增加路由器用户

 
 #安装包 shadow-useradd
 opkg install shadow-useradd
 #调用命令useradd增加用户
 useradd your_name -s /bin/ash
 
 #然后查看/etc/passwd文件确认和root一样
root@OpenWrt:/# cat /etc/passwd
root:x:0:0:root:/root:/bin/ash
daemon:*:1:1:daemon:/var:/bin/false
ftp:*:55:55:ftp:/home/ftp:/bin/false
network:*:101:101:network:/var:/bin/false
nobody:*:65534:65534:nobody:/var:/bin/false
xujf:x:0:0:root:/home/xujf:/bin/ash
 
#设置password
 passwd your_name
 
#创建home工作目录
 mkdir -p /home/your_name
 chown your_name:your_name /home/your_name
 
为了安全,给该用户赋予sudo权限,并禁止root远程登录
 首先要安装sudo包
 opkg install sudo
 其次增加sudo权限。
 执行:visudo
 找到如下行进行修改:
 ##
 ## User privilege specification
 ##
 root ALL=(ALL) ALL
 your_name ALL=(ALL) ALL

 


猜你喜欢

转载自xjf975999.iteye.com/blog/2173202