我已经使用 NetworkManager/ModemManager 设置了我的 LTE 调制解调器,并且运行正常。我还使用 DHCP 在 NetworkManager 中将 Wifi 设置为接入点。
但是我如何通过 Wifi 共享 LTE 调制解调器互联网访问?我已启用 IP 转发 ( echo 1 > /proc/sys/net/ipv4/ip_forward
),还有什么?
# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:12946 errors:0 dropped:0 overruns:0 frame:0
TX packets:12946 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1297231 (1.2 MiB) TX bytes:1297231 (1.2 MiB)
wlan0 Link encap:Ethernet HWaddr E8:4F:25:DD:BD:51
inet addr:10.42.0.1 Bcast:10.42.0.255 Mask:255.255.255.0
inet6 addr: fe80::ea4f:25ff:fedd:bd51/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:77 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:12101 (11.8 KiB)
wwan0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:100.72.254.176 P-t-P:100.72.254.176 Mask:255.255.255.224
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:1808 errors:0 dropped:0 overruns:0 frame:0
TX packets:2176 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:356293 (347.9 KiB) TX bytes:261384 (255.2 KiB)
# ip route
default via 100.72.254.177 dev wwan0 metric 700
10.42.0.0/24 dev wlan0 scope link src 10.42.0.1 metric 600
100.72.254.160/27 dev wwan0 scope link src 100.72.254.176 metric 700
Wifi 的 DHCP 由 NetworkManager 启动 dnsmasq 使用默认参数完成:
# ps -eF | grep dnsmasq
nobody 1104 606 0 1285 2444 0 09:05 ? 00:00:00 /usr/bin/dnsmasq --conf-file=/dev/null --no-hosts --keep-in-foreground --bind-interfaces --except-interface=lo --clear-on-reload --strict-order --listen-address=10.42.0.1 --dhcp-range=10.42.0.10,10.42.0.254,60m --dhcp-lease-max=50 --dhcp-leasefile=/var/lib/NetworkManager/dnsmasq-wlan0.leases --pid-file=/var/run/nm-dnsmasq-wlan0.pid --conf-dir=/etc/NetworkManager/dnsmasq-shared.d
参考NetworkManager 和 dnsmasq dhcp 地址范围)。
# cat /etc/NetworkManager/system-connections/ap.nmconnection
[connection]
id=ap
uuid=3205b229-8c4d-4766-8d63-bcd949d03321
type=wifi
autoconnect=false
interface-name=wlan0
[wifi]
band=bg
channel=1
mode=ap
ssid=MySSID
[wifi-security]
group=ccmp;
key-mgmt=wpa-psk
pairwise=ccmp;
proto=rsn;
psk=MyPSK
[ipv4]
method=shared
[ipv6]
addr-gen-mode=stable-privacy
method=ignore
[proxy]
一位同事建议使用https://github.com/oblique/create_ap。我尝试了 NAT 和桥接选项,但都失败了。
网络地址转换(NAT):
# create_ap -w 2 wlan0 wwan0 APTest 12345678
WARN: brmfmac driver doesn't work properly with virtual interfaces and
it can cause kernel panic. For this reason we disallow virtual
interfaces for your adapter.
For more info: https://github.com/oblique/create_ap/issues/203
WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt
Config dir: /tmp/create_ap.wlan0.conf.XX59Vdf8
PID: 537195
Network Manager found, set wlan0 as unmanaged device... [46988.754925] ieee80211 phy1: brcmf_set_pmk: failed to change PSK in firmware (len=0)
[46988.784848] ieee80211 phy1: brcmf_vif_set_mgmt_ie: vndr ie set error : -52
[46988.792027] ieee80211 phy1: brcmf_vif_set_mgmt_ie: vndr ie set error : -52
DONE
Sharing Internet using method: nat
iptables v1.8.7 (legacy): unknown option "--to-ports"
Try `iptables -h' or 'iptables --help' for more information.
Doing cleanup.. done
桥:
# create_ap -w 2 -m bridge wlan0 wwan0 APTest 12345678
WARN: brmfmac driver doesn't work properly with virtual interfaces and
it can cause kernel panic. For this reason we disallow virtual
interfaces for your adapter.
For more info: https://github.com/oblique/create_ap/issues/203
WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt
Config dir: /tmp/create_ap.wlan0.conf.XXgGPNON
PID: 540585
Network Manager found, set wlan0 as unmanaged device... DONE
Sharing Internet using method: bridge
Create a bridge interface... ip: RTNETLINK answers: Operation not supported