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。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。