root@OpenWrt:~# ip a s 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000 link/sit 0.0.0.0 brd 0.0.0.0 3: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN group default qlen 1000 link/tunnel6 :: brd :: permaddr d636:b99c:d56d:: 4: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq master br-lan state DOWN group default qlen 1000 link/ether 0e:02:db:93:b8:20 brd ff:ff:ff:ff:ff:ff 5: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 6: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether f2:09:65:33:97:88 brd ff:ff:ff:ff:ff:ff 7: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 7e:ad:dd:05:72:66 brd ff:ff:ff:ff:ff:ff 8: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-lan state UP group default qlen 1000 link/ether 0e:02:db:93:b8:1f brd ff:ff:ff:ff:ff:ff inet6 fe80::c02:dbff:fe93:b81f/64 scope link valid_lft forever preferred_lft forever 9: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 0e:02:db:93:b8:20 brd ff:ff:ff:ff:ff:ff inet 192.168.1.1/24 brd 192.168.1.255 scope global br-lan valid_lft forever preferred_lft forever inet6 fd4e:8614:5748::1/60 scope global noprefixroute valid_lft forever preferred_lft forever inet6 fe80::c02:dbff:fe93:b820/64 scope link valid_lft forever preferred_lft forever 10: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:14:ab:d8:da brd ff:ff:ff:ff:ff:ff inet 172.31.0.1/24 brd 172.31.0.255 scope global docker0 valid_lft forever preferred_lft forever 11: usb0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 82:e0:7e:db:2c:25 brd ff:ff:ff:ff:ff:ff
使用 udhcpc 发送 dhcp 请求
1 2 3 4 5 6
root@OpenWrt:~# udhcpc -i usb0 udhcpc: started, v1.33.1 udhcpc: sending discover udhcpc: sendto: Network is down udhcpc: read error: Network is down, reopening socket udhcpc: sending discover
查看下 usb,确实有我的 手机,居然要手动 up 它
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
root@OpenWrt:~# lsusb Bus 001 Device 004: ID 2717:ff80 Xiaomi M2007J3SC Bus 002 Device 001: ID 1d6b:0003 Linux 5.13.13-flippy-63+ xhci-hcd xHCI Host Controller Bus 001 Device 001: ID 1d6b:0002 Linux 5.13.13-flippy-63+ xhci-hcd xHCI Host Controller
root@OpenWrt:~# ip link set usb0 up root@OpenWrt:~# ip a s usb0
13: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000 link/ether 0a:01:0f:46:3a:e6 brd ff:ff:ff:ff:ff:ff inet6 fe80::801:fff:fe46:3ae6/64 scope link valid_lft forever preferred_lft forever root@OpenWrt:~# udhcpc -i usb0 udhcpc: started, v1.33.1 udhcpc: sending discover udhcpc: sending select for 192.168.42.128 udhcpc: lease of 192.168.42.128 obtained, lease time 3599 udhcpc: ip addr add 192.168.42.128/255.255.255.0 broadcast 192.168.42.255 dev usb0 udhcpc: setting default routers: 192.168.42.129
请求过程中也把默认路由设置为它了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
root@OpenWrt:~# ip r g 1 1.0.0.0 via 192.168.42.129 dev usb0 src 192.168.42.128 uid 0 cache root@OpenWrt:~# ping baudu.com ^C root@OpenWrt:~# ping 114.114.114.114 PING 114.114.114.114 (114.114.114.114): 56 data bytes 64 bytes from 114.114.114.114: seq=0 ttl=64 time=73.218 ms 64 bytes from 114.114.114.114: seq=1 ttl=70 time=45.460 ms 64 bytes from 114.114.114.114: seq=2 ttl=71 time=43.823 ms 64 bytes from 114.114.114.114: seq=3 ttl=81 time=40.963 ms ^C --- 114.114.114.114 ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max = 40.963/50.866/73.218 ms root@OpenWrt:~#
去 web 上,网络接口,把 wan 的口子(如果没有就添加),dhcp客户端,接口设选 usb0。添加后设置下新添加接口的 防火墙设置 ,将其设置为 wan: ,要注意,上面后的 dns 是 dhcp 获取的,也就是 dnsmasq 使用 解析文件:
1
/tmp/resolv.conf.auto
你使用自己的dns 例如 adg 之类的,可以关闭上面的:
1 2 3 4
uci set dhcp.@dnsmasq[0].server='127.0.0.1#5300' uci set dhcp.@dnsmasq[0].noresolv='1' uci commit dhcp /etc/init.d/dnsmasq reload
uci set wireless.default_radio0.ssid='OpenWrt-5G' uci set wireless.default_radio0.encryption='psk-mixed' uci set wireless.default_radio0.key='password' uci set wireless.radio0.legacy_rates='1'
uci set wireless.default_radio1.ssid='OpenWrt' uci set wireless.default_radio1.encryption='psk-mixed' uci set wireless.default_radio1.key='password' uci set wireless.radio1.legacy_rates='1' uci commit wireless wifi reload