OpenWrt在校园网使用的相关问题解决办法

WAN口无法获取IP

将WAN口插上网线之后,始终无法获取外网IP。排除了常见问题都之后,可以试试配置一下WAN口的工作模式。

# 查看网卡eth1的当前参数
ethtool eth1

部分配置参数如下

Settings for eth1:
...
Speed: 10Mb/s
Duplex: Half
Port: MII
PHYAD: 4
Transceiver: external
Auto-negotiation: on
...

可以发现当前eth1工作在10Mb/s的半双工模式,自协商处于开启状态。尝试更改一下工作模式

ethtool -s eth1 speed 100 duplex full authneg off

然后WAN口就可以获取到IP了。但是路由器重启后,设置会被重置。下面让路由器启动的时候自动进行WAN口配置

# 创建启动脚本
vim /etc/init.d/ethtool

加入一下代码

#!/bin/sh /etc/rc.common
# Copyight (C) 2006 OpenWrt.org
START=41
start() {
    ethtool -s $(uci -P/var/state get network.wan.ifname) speed 100 duplex full autoneg off
}

stop() {
    ethtool -s $(uci -P/var/state get network.wan.ifname) speed 1000 duplex full autoneg off
}

其中$(uci -P/var/state get network.wan.ifname)变量会获取到当前WAN口的网卡。

# 追加运行权限
chmod +x /etc/init.d/ethtool
# 创建软连接,使脚本自动启动
ln -s /etc/init.d/ethtool /etc/rc.d/S95ethtool

OpenWRT启动时会自动运行etc/rc.d/目录下形如S*的脚本,S后的数字表示执行的优先级,从小到大依次执行。

配置IPv6

首先路由器要能自动获取全局的IPv6地址(2001开头),下面使用odhcpd来配置ipv6。首先,在OpenWrt的LuCI界面清空接口选项下的Global ULA-Prefix(IPv6 ULA前缀)

# 修改/etc/config/dhcp文件
vim /etc/config/dhcp

# 修改如下
config dhcp 'lan' 
    option interface 'lan' 
    option start '100' 
    option limit '150' 
    option leasetime '12h' 
    option ra 'hybrid' 
    option dhcpv6 'hybrid' 
    option ndp 'hybrid' 
    option ra_management '1' 

config dhcp 'wan6' 
    option interface 'wan' 
    option dhcpv6 'hybrid' 
    option ra 'hybrid' 
    option ndp 'hybrid' 
    option master '1'
# 加载配置
/etc/init.d/network reload

配置完成之后,LAN就可以获得2001开头的global IP了,客户机会获得自动分配的IP。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值