openwrt生成随机mac地址,openwrt自动生成mac地址脚本,随机mac地址生成方法

2019-11-07
0评论
/
2399阅读
爱搜啊

openwrt生成随机mac地址,openwrt自动生成mac地址脚本,随机mac地址生成方法

某些场景下, 需要使用不同的MAC地址与外界通信,查询了部分资料, 现记录如下:

1.生成MAC地址命令如下

dd if=/dev/urandom bs=1 count=32 2>/dev/null | md5sum | cut -b 0-12 | sed 's/\(..\)/\1:/g; s/.$//'

2.OpenWRT通过MACVLAN使用不同的MAC地址与WAN口设备通信

(添加到/etc/rc.local文件中, 以便开机自动运行)

# set up virtual mac addresses as aliases on the main WAN i/f eth0.2

ip link add link eth0.2 eth2 type macvlan

ifconfig eth2 hw ether `<pre name="code" class="plain">dd if=/dev/urandom bs=1 count=32 2>/dev/null | md5sum | cut -b 0-12 | sed 's/\(..\)/\1:/g; s/.$//'

` ip link add link eth0.2 eth3 type macvlanifconfig eth3 hw ether `

dd if=/dev/urandom bs=1 count=32 2>/dev/null | md5sum | cut -b 0-12 | sed 's/\(..\)/\1:/g; s/.$//'

` ip link add link eth0.2 eth4 type macvlanifconfig eth4 hw ether `

dd if=/dev/urandom bs=1 count=32 2>/dev/null | md5sum | cut -b 0-12 | sed 's/\(..\)/\1:/g; s/.$//'

` ip link add link eth0.2 eth5 type macvlanifconfig eth5 hw ether `

dd if=/dev/urandom bs=1 count=32 2>/dev/null | md5sum | cut -b 0-12 | sed 's/\(..\)/\1:/g; s/.$//'

`ifup eth2

ifup eth3

ifup eth4

ifup eth5

# default route

route add default gw 192.168.188.1 dev eth0.2

3.添加openwrt接口规则

 在/etc/config/network中加入我们上面添加的interface:

config 'interface' 'wan2'

    option 'ifname' 'eth2'

    option 'proto' 'dhcp'

    option 'defaultroute' '0'

    option 'peerdns' '0'

    option 'gateway' '0.0.0.0

4.添加openwrt防火墙规则

在/etc/config/firewall中加入上面添加的interface

config zone

    option name             wan1

    option network          'wan1'

    option input            REJECT

    option output           ACCEPT

    option forward          REJECT

    option masq             1

    option mtu_fix          1

# forwards from 1st WAN i/f to SP2010 Web01

config redirect

    option src              wan1

    option src_dport        3389

    option proto            tcp

    option dest_ip          192.168.188.94

5.如需访问路由器前端的modem或者其他设备

添加alias接口,以便openwrt的wan能够直接访问modem, 然后使用iptables规则, 将访问请求改写src ip为alias接口的IP

config 'alias'

    option 'interface' 'wan'

    option 'proto' 'static'

    option 'ipaddr' '192.168.0.2'

    option 'netmask' '255.255.255.0'

iptables -t nat -I postrouting_rule -s 192.168.188.0/24 -d 192.168.1.1 -j SNAT --to 192.168.1.99

iptables -I zone_lan_forward -s 192.168.1.0/24 -d 192.168.1.99 -j ACCEPT

或者

MODEMIP=192.168.0.1                                                                   

MODEM_NET=`echo $MODEMIP | cut -d "." -f 1-3`                                           

ROUTER_WAN_PORT_IP=192.168.0.2                                                    

WAN_PORT=eth0.2

ifconfig $WAN_PORT $ROUTER_WAN_PORT_IP netmask 255.255.255.0 broadcast $MODEM_NET.255   

iptables -A forwarding_rule -d $MODEMIP -j ACCEPT                                       

iptables -t nat -A postrouting_rule -d $MODEMIP -o $WAN_PORT -j MASQUERADE

openwrt无线名称自动加Mac地址

添加到/etc/rc.local文件中, 以便开机自动运行

if[-n "$path"];then

   path="${path##/sys/devices/}"

   dev_id="option path'$path'"

else

   dev_id="option macaddr$(cat /sys/class/ieee80211/${dev}/macaddress)"

fi

if[ x$mode_band == x"a"];then

   ssid_5ghz="-5GHz"

else

全文地址《openwrt无线名称自动加Mac地址

OpenWrt固件实现路由器定时重启方法无限重启

30 05 * * 1,2,3,4,5 sleep 5 && touch /etc/banner && reboot

这段命令的意思是星期1-5的5点30分,自动重启。

第一步 复制到 系统-计划任务-粘贴保存

第二步 系统-启动项-找到 cron  然后重启此启动项

如果直接设置这样的命令

0 5 * * * /sbin/reboot

那么系统在5点重启后就会自动每过一分钟就会重启一次,因为重启后系统时间是不会变的。因为路由器重启后时间还停在重启前的5点。

正确的命令如下

10 2 * * * sleep 70 && touch /etc/banner && reboot   //每天2点10分路由器自动重启

需要注意的是,一定要延迟重启,否则可能无限重启,官方给出的配置中,在 sleep 70 秒之后,使用 touch 写文件,因为路由器如果没有及时联网从NTP服务器上获取到时间,那么路由器的系统时间和重启的系统时间便一样,如果修改过文件,Openwrt 开机后会把最后修改或者访问的文件时间作为默认系统时间。因此延迟1min重启,可以避免这个问题


本站附件分享,如果附件失效,可以去找找看

诚通网盘附件百度网盘附件


于2019-11-07发布
相关文章