我正在尝试将我的 LTE 调制解调器连接 (wwan0) 共享到我的 rPi 上的以太网 LAN 端口。
我正在遵循本指南,每个界面均已启动并运行。
@raspberrypi:~ $ ifconfig -a
eth0 Link encap:Ethernet HWaddr b8:27:eb:2a:2a:0f
inet addr:172.24.1.1 Bcast:172.24.1.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:423 errors:0 dropped:0 overruns:0 frame:0
TX packets:76 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:38877 (37.9 KiB) TX bytes:13468 (13.1 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:36 errors:0 dropped:0 overruns:0 frame:0
TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:2813 (2.7 KiB) TX bytes:2813 (2.7 KiB)
wlan0 Link encap:Ethernet HWaddr b8:27:eb:7f:7f:5a
inet addr:192.168.1.50 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:323 errors:0 dropped:2 overruns:0 frame:0
TX packets:485 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:30591 (29.8 KiB) TX bytes:55800 (54.4 KiB)
wwan0 Link encap:Ethernet HWaddr 00:1e:10:1f:00:00
inet addr:100.64.181.186 Bcast:100.64.181.187 Mask:255.255.255.252
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14 errors:0 dropped:0 overruns:0 frame:0
TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1922 (1.8 KiB) TX bytes:8367 (8.1 KiB)
sudo nano /etc/network/interfaces
#iface eth0 inet manual
allow-hotplug eth0
iface eth0 inet static
address 192.168.2.1
netmask 255.255.255.0
sudo nano /etc/dnsmasq.conf
interface=eth0 # Use interface eth0
listen-address=192.168.2.1 # Explicitly specify the address to listen on
bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
bogus-priv # Never forward addresses in the non-routed address spaces.
dhcp-range=192.168.2.1,192.168.2.50,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time
sudo nano /etc/sysctl.conf
net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o wwan0 -j MASQUERADE
pi@raspberrypi:~ $ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default setup.ubnt.com 0.0.0.0 UG 10 0 0 wlan0
default 100.64.35.177 0.0.0.0 UG 1000 0 0 wwan0
100.64.35.176 * 255.255.255.240 U 1000 0 0 wwan0
192.168.1.0 * 255.255.255.0 U 10 0 0 wlan0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
...如果我将客户端 PC 与 rPi 连接,我会通过 DHCP 获取 IP 地址,但没有互联网连接。无法 ping (IP、主机名)。
连接客户端后的路由表:
pi@raspberrypi:~ $ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default setup.ubnt.com 0.0.0.0 UG 10 0 0 wlan0
default 100.64.35.177 0.0.0.0 UG 1000 0 0 wwan0
100.64.35.176 * 255.255.255.240 U 1000 0 0 wwan0
link-local * 255.255.0.0 U 202 0 0 eth0
192.168.1.0 * 255.255.255.0 U 10 0 0 wlan0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
系统日志:
Jul 26 00:35:32 raspberrypi dhcpcd[760]: eth0: carrier acquired
Jul 26 00:35:32 raspberrypi kernel: [ 662.708525] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xC5E1
Jul 26 00:35:32 raspberrypi dhcpcd[760]: eth0: IAID eb:2a:2a:0f
Jul 26 00:35:33 raspberrypi dnsmasq-dhcp[794]: DHCPDISCOVER(eth0) 00:0e:c6:d9:b4:b0
Jul 26 00:35:33 raspberrypi dnsmasq-dhcp[794]: DHCPOFFER(eth0) 192.168.2.40 00:0e:c6:d9:b4:b0
Jul 26 00:35:33 raspberrypi dhcpcd[760]: eth0: soliciting an IPv6 router
Jul 26 00:35:33 raspberrypi dhcpcd[760]: eth0: soliciting a DHCP lease
Jul 26 00:35:34 raspberrypi dnsmasq-dhcp[794]: DHCPREQUEST(eth0) 192.168.2.40 00:0e:c6:d9:b4:b0
Jul 26 00:35:34 raspberrypi dnsmasq-dhcp[794]: DHCPACK(eth0) 192.168.2.40 00:0e:c6:d9:b4:b0 Adrians-MBP
Jul 26 00:35:42 raspberrypi dhcpcd[760]: eth0: using IPv4LL address 169.254.153.193
Jul 26 00:35:42 raspberrypi avahi-daemon[430]: Registering new address record for 169.254.153.193 on eth0.IPv4.
Jul 26 00:35:42 raspberrypi dhcpcd[760]: wwan0: adding default route via 100.64.35.177
Jul 26 00:35:42 raspberrypi dhcpcd[760]: eth0: adding route to 169.254.0.0/16
Jul 26 00:35:43 raspberrypi dhcpcd[760]: wwan0: removing default route via 100.64.35.177
Jul 26 00:35:44 raspberrypi ntpd[784]: Listen normally on 8 eth0 169.254.153.193 UDP 123
Jul 26 00:35:44 raspberrypi ntpd[784]: peers refreshed
Jul 26 00:36:01 raspberrypi CRON[1732]: (root) CMD (/home/pi/script/watchdog.sh >/dev/null 2>&1)
Jul 26 00:37:01 raspberrypi CRON[1751]: (root) CMD (/home/pi/script/watchdog.sh >/dev/null 2>&1)
Jul 26 00:37:53 raspberrypi dhcpcd[760]: eth0: carrier lost
Jul 26 00:37:53 raspberrypi kernel: [ 803.801956] smsc95xx 1-1.1:1.0 eth0: link down
Jul 26 00:37:53 raspberrypi avahi-daemon[430]: Withdrawing address record for 169.254.153.193 on eth0.
Jul 26 00:37:53 raspberrypi dhcpcd[760]: wwan0: adding default route via 100.64.35.177
Jul 26 00:37:53 raspberrypi dhcpcd[760]: eth0: deleting route to 169.254.0.0/16
Jul 26 00:37:54 raspberrypi dhcpcd[760]: wwan0: removing default route via 100.64.35.177
Jul 26 00:37:55 raspberrypi ntpd[784]: Deleting interface #8 eth0, 169.254.153.193#123, interface stats: received=0, sent=0, dropped=0, active_time=131 secs
Jul 26 00:37:55 raspberrypi ntpd[784]: peers refreshed
pi@raspberrypi:~ $ sudo iptables -t nat -v -L -n --line-number
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 1 packets, 240 bytes)
num pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
num pkts bytes target prot opt in out source destination
1 1 240 MASQUERADE all -- * wwan0 0.0.0.0/0 0.0.0.0/0
只有 wwan0 共享不起作用,如果我用 Wifi wlan0 替换它,它立即开始工作。可能是什么问题?
答案1
pi@raspberrypi:~ $ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default setup.ubnt.com 0.0.0.0 UG 10 0 0 wlan0
default 100.64.35.177 0.0.0.0 UG 1000 0 0 wwan0
100.64.35.176 * 255.255.255.240 U 1000 0 0 wwan0
192.168.1.0 * 255.255.255.0 U 10 0 0 wlan0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
您有两个默认网关。删除第一个:
ip route delete default via setup.ubnt.com
或者
使用策略路由通过第二个网关(wwan0)配置路由特定流量。
仍然从主路由表中删除一个网关。它将要造成问题。